I am currently considering using squashfs to store information on flash drives. However, whenever the flash drive is inserted, Fedora 34 assigns it a device id (/dev/sd?) which may change from one boot to another, making it difficult to write scripts involving that drive. Is there any way to assign a label, to the drive or to the partition, which would assist in identifying the drive?
1 Answers
No, the squashfs filesystem format supports neither labels nor UUIDs.
(It seems squashfs is mostly meant to be used for "loop" mounts, where the /dev/loop# name is already known from the start. You'd store the actual squashfs image inside another "normal" filesystem, not directly on raw disk.)
As an alternative, the GPT partition table format allows you to define partition labels and UUIDs (accessible through the /dev/disk/by-partlabel and by-partuuid symlinks) which exist independently of the filesystem within. You can set a custom partlabel through fdisk or gdisk, with the "change partition name" command.
(Linux will also attempt to generate pseudo-PARTUUID symlinks for partitions on MBR disks as well – only if the MBR has a non-zero "NT disk signature".)
The flash drive may also provide a "physical" serial number and/or a WWN that is available through /dev/disk/by-id.
The -EROFS filesystem is an alternative to squashfs; it still doesn't support custom labels, but does support filesystem-level UUIDs.
- 426,297
- 64
- 894
- 966
-
To add to this awesome answer, keep in mind that if these drives are NAND flash, SquashFS is a bad idea. – Señor CMasMas Oct 12 '21 at 14:58
-
The problem with NAND flash, as far as I can tell, is the lack of bad block support in SquashFS. Does this mean that I would be better off formatting the flash device with ext4, for example, and storing the SquashFS as a file on that system? – ghborrmann Oct 12 '21 at 16:05
-
Thanks for your comprehensive answer. I had not even been aware of EROFS. Although I'm not sure it's stable enough at this point, I will be looking into this more fully in the future. – ghborrmann Oct 12 '21 at 16:09