Contents |
Linux prefers to use UUID (Universally Unique Identifier), LABEL, or symlinks to identify media storage devices on a system. Using device assignments (like /dev/hd*# or /dev/sd*#) is not preferred since these can change between system boots:
all filesystems should be specified by UUID=<id> or LABEL=<name> for each partition.
all physical devices should be specified by a symlink, like /dev/cdrom for a cd drive and /dev/disk/by-id/... for each physical hard drive.
The files for which UUID is most critical:
/boot/grub/grub.cfg
/etc/fstab
/etc/initramfs-tools/conf.d/resume
This page uses the terminal a lot, so if you are new to this, see UsingTheTerminal.
The Fstab page provides some excellent examples of UUID in action.
Finding UUIDs
UUIDs can be determined using the blkid command. This command lists UUIDs for all attached devices (mounted or not).
Here are examples (your output will be different, but similarly formatted). The command:
sudo blkid
produces an output similar to:
/dev/sda1: TYPE="ntfs" UUID="72C0DE8EC0DE57C5" LABEL="windows" /dev/sda2: UUID="30fcb748-ad1e-4228-af2f-951e8e7b56df" SEC_TYPE="ext2" TYPE="ext3" /dev/sda5: TYPE="swap" UUID="8c4e69f8-5074-42c0-8134-0b2429c4c02c" /dev/sdb1: SEC_TYPE="msdos" UUID="4848-E35A" TYPE="vfat"
Alternatively you can list them from their listing in your root filesystem:
ls -l /dev/disk/by-uuid/
produces an output similar to:
total 0 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 30fcb748-ad1e-4228-af2f- 951e8e7b56df -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-07 16:51 4848-E35A -> ../../sdb1 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 72C0DE8EC0DE57C5 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 8c4e69f8-5074-42c0-8134-0b2429c4c02c -> ../../sda5
Using LABEL
Labels can be very useful for external media, like flash drives and USB hard drives since these are generally automounted by hal (Hardware Abstraction Layer). If a device has a label, it will be mounted at the /media/<label> location and appear with the label on the desktop.
For help with labeling devices, see RenameUSBDrive.
Symlinks
Symlinks (symbolic links) are used to make it easier to identify a device. For example /dev/cdrom can link to /dev/scd0. These are normally created by udev which is the device manager program used in the Linux 2.6 kernel series. We will not cover creating your own symlinks here (may be added later).
Other examples of symlinks include /dev/floppy to /dev/fd0 or /dev/dvd to /dev/scd1 .
You can view the linked device on a symlink with the ls command, like so:
ls -l /dev/cdrom
produces an output similar to:
lrwxrwxrwx 1 root root 4 2008-06-22 17:31 /dev/cdrom -> scd0
This tell us that /dev/cdrom is a symlink to the device /dev/scd0 .
To view the physical device identifiers (like for a hard drive, not to be confused with a disk's partitions), the command:
ls -l /dev/disk/by-id/
produces an output similar to:
total 0 lrwxrwxrwx 1 root root 9 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5 lrwxrwxrwx 1 root root 9 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb lrwxrwxrwx 1 root root 10 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1 lrwxrwxrwx 1 root root 9 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5 lrwxrwxrwx 1 root root 9 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb lrwxrwxrwx 1 root root 10 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1
Note that each partition (called part#) identifies with their parent device - this is because they exist on that physical piece of hardware. You will also notice that the drives and partitions appear twice, the first time as ata and the second time as scsi. I am unclear as to why this is, but I believe it is related to IDE hard drives being identified to the system as SCSI drives (because of ide-scsi emulation?).
Other Resources
Here are some other useful and related pages.
RenameUSBDrive - help with adding LABELs to partitions