UUID business

Use *nix? Use many distributions at a time? Use many distributions on many disks?

Managing distributions installed on multiple disks can be a real pain in the a**, say you have fedora10 installed on one SATA disk, and Debian on other disk. Now, can you confidently tell which is the system drive? It gets really messy.

Have a portable hard drive you want to be mounted at a fixed place when attached? If there is another USB drive already attached, there is no way you can tell whether the new one is sdc or sdd.

UUID comes to rescue. Though not supported nor understood by the kernel, many distributions provide tools in initrd which can work with UUIDs. Every partition has a Universally Unique IDentifier (UUID), which can be used as a globally unique name for a partition.

Finding UUID of a partition


This command needs 'udev' package. It comes pre-installed on many modern Linux distributions. If not, please install it following your distribution's guidelines.

/lib/udev/vol_id --uuid /dev/sdaXX

replacing XX by the partition number.

Using UUIDs

  1. Painless booting
    UUID comes in handy when you have a separate boot and / partitions. In this case, the kernel and initrd resides on the boot partition, while the root, is on / partition. Naturally, the kernel needs to be told which partition to use as root.

    say the root partition is sda8, then

    # /lib/udev/vol_id --uuid /dev/sda8
    b036863a-2846-4f57-a6db-e7716f5d903c


    or use


    # udevadm info --query=all --name=/dev/sda8 | grep UUID | sed q | cut -d'=' -f2
    b036863a-2846-4f57-a6db-e7716f5d903c


    This UUID can be used in the kernel parameter. Open up menu.lst of grub (or lilo.conf if you still use LiLo), and make the kernel entry look something like

    kernel vmlinuz-2.6.27.9-159.fc10.i686 ro root=UUID=b036863a-2846-4f57-a6db-e7716f5d903c


    Now you can safely boot without worrying about which drive has the boot partition.

  2. Pseudo-permanent mountpoint settings

    Continuing from the USB disk example, say the partition on the USB drive has UUID 51e3a299-68f3-466f-86ac-428c60420621, an entry can be added into /etc/fstab which looks like

    UUID=
    ba92ef0d-bb4e-4632-bf22-133d9d3fa1f4 / ext3 defaults 1 1
    UUID=b036863a-2846-4f57-a6db-e7716f5d903c /home ext3 defaults 1 2
    UUID=51e3a299-68f3-466f-86ac-428c60420621 /media/thumbdrive auto defaults 0 0

    Now, the USB thumbdrive will always be mounted at /media/thumbdrive :)
Adios.
--
prashant

No comments:

Post a Comment