6 Dec 2009

Dealing with UUIDs in fstab

Since there are more and more removable block devices in use (Memmory Sticks, External HDs, etc.) it makes sense to mount them via UUID, since the device name may vary.

Two tools have been very useful for finding out the UUIDs for a partition:

$ blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: UUID="D8A03377A0335B68" LABEL="HP_PAVILION" TYPE="ntfs"
/dev/sda3: UUID="4562-2B6E" TYPE="vfat"
/dev/sda4: LABEL="HP_RECOVERY" UUID="4B6E-6BC0" TYPE="vfat"
/dev/sda5: UUID="2e551b01-6f76-4d8e-85cd-7adc6abc9a2d" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda6: UUID="6cb7b571-be94-4882-a504-fddf8fa1388a" TYPE="swap"
/dev/sda7: UUID="402b3442-1432-4676-ab6f-6cb3c403a4f2" TYPE="ext3"
/dev/sda8: UUID="8501e0d1-55b5-4899-8553-37129213d803" TYPE="ext3"
/dev/sdb1: UUID="7868C17F68C13D1E" LABEL="Volume" TYPE="ntfs"
/dev/sdb2: UUID="e1454921-55a4-42af-9484-e6a82eb33329" SEC_TYPE="ext2" TYPE="ext3"
$ sudo vol_id /dev/sda3
ID_FS_USAGE=filesystem
ID_FS_TYPE=vfat
ID_FS_VERSION=FAT32
ID_FS_UUID=4562-2B6E
ID_FS_UUID_ENC=4562-2B6E
ID_FS_LABEL=
ID_FS_LABEL_ENC=

An easy readable list of device names and UUIDs:
$ blkid -s device -s UUID | sed -e 's|:||; s|UUID="||; s|"||'
/dev/sda1 D8A03377A0335B68
/dev/sda3 4562-2B6E
/dev/sda4 4B6E-6BC0
/dev/sda5 2e551b01-6f76-4d8e-85cd-7adc6abc9a2d
/dev/sda6 6cb7b571-be94-4882-a504-fddf8fa1388a
/dev/sda7 402b3442-1432-4676-ab6f-6cb3c403a4f2
/dev/sda8 8501e0d1-55b5-4899-8553-37129213d803
/dev/sdb1 7868C17F68C13D1E
/dev/sdb2 e1454921-55a4-42af-9484-e6a82eb33329