Linux Partitions and Using UUID (Unique Unit IDs) Attributes
TODO:
Document using LABELs as with RHEL...
tune2fs -l - list the contents of the fileystem superblock...
--------------------------------------------------------------------------------
Using UUID in /etc/fstab
To get the partition or device's UUID (Unique Unit ID):
vol_id -u /dev/x
dumpe2fs /dev/x | grep UUID
To set a device UUID (tune2fs(8)):
tune2fs -U UUID /dev
The format of the UUID is a series of hex digits separated by hyphens, like this:
"c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter may also be one of the
following:
clear clear the filesystem UUID
random generate a new randomly-generated UUID
time generate a new time-based UUID
If the system does not have a good random number generator such as /dev/random
or/dev/urandom, tune2fs will automatically use a time-based UUID instead of a
randomly-generated UUID.
To generate a random UUID (uuidgen(8)):
uuidgen
To use UUID on Swap Partitions:
mkswap [-L label] [-U UUID] /dev [blocks]
mkswap -U "6ef7959c-0851-4c2c-bc57-bcd4f9b9f85c" /dev/sda2
tune2fs -U "6ef7959c-0851-4c2c-bc57-bcd4f9b9f85c" /dev/sda2
cat /proc/swaps
View UUID Partitions the Kernel Currently knows of:
ls /dev/disk/by-uuid/
--------------------------------------------------------------------------------
Using UUID in /etc/fstab
/etc/fstab:
proc /proc proc defaults 0 0
UUID=U-U-I-D / ext3 defaults 0 0
UUID=U-U-I-D none swap sw 0 0
--------------------------------------------------------------------------------
UUID and Kernel Arguments
Kernel Arguments using UUID:
vmlinuz root=UUID=3afd8469-dbf1-442d-9c4a-ef493e9d1a28
/boot/grub/menu.lst
root (hd0,0)
kernel /boot/vmlinuz-2.6.x root=UUID=U-U-I-D ro quite splash
initrd /boot/initrd.img-2.6.x
--------------------------------------------------------------------------------
UUID Notes:
UUID Mount points are very good for "portable devices"...
UUID is a great feature. As a system administrator I frequently have to deal with volumes that are moved around, especially in large enterprise systems where the volumes might be on a SAN, or an external DAS chassis. When storage is shuffled around, all of the /dev/sd... names get shuffled too, and the entire fstab breaks. With UUID, the kernel just automatically finds the volumes in their new physical locations on the bus, and mounts them at their proper mount points.
I agree, UUID makes sense. It makes even MORE sense to when you have understood the UUID concept and have already been using it with RAID/mdadm.
When your raid array is only looking for UUID's rather than device names, you can shut down, juggle the drives into any order, reboot and bingo the array is still ok. Compare that to the old way of "ok... now I better label that this drive goes in this slot..." - when you got two drives switched around you'd have to manually reassemble the array. UUID makes it painless.
IIRC, the big push for UUID in Ubuntu was to deal with external media, such as USB drives on a laptop, ESata, etc. Those were the use cases cited at the time.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
MISC, Put Somewhere Else...
To mount all the partitions listed in /etc/fstab:
mount -a
To re-read block devices after fstab change?:
partprobe
man blockdev
blockdev --rereadpt /dev/sda
Columns in /etc/fstab:
--------------------------------------------------------------------------------
Using Linux Partition / Volume LABELs
A volume label should NOT exceed 16 characters!
To see a volume label (name):
dumpe2fs /dev/hda1
dumpe2fs /dev/hda1 | grep name
-> Filesystem volume name:
To label a partition (label = /data):
e2label /dev/sda5 /data
tune2fs -L LABEL_NAME /dev
tune2fs -L "LABEL_NAME" /dev
To use UUID on Swap Partitions:
mkswap -L label /dev
Using LABELs in /etc/fstab:
LABEL=/ / ext3 defaults 1 1
LABEL=/data /data ext3 defaults 1 1
LABEL=SWAP-sda3 swap swap defaults 0 0
When using LABELs to mount a filesystem, you must use all uppercase as this
method is case sensative.
--------------------------------------------------------------------------------
#/etc/fstab (linux):
LABEL=/ / ext3 defaults 1 1
LABEL=/data /data ext3 defaults 1 1
LABEL=SWAP-sda3 swap swap defaults 0 0
#/etc/fstab (redhat):
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
--------------------------------------------------------------------------------