Universally Unique IDentifier (UUID)
Persistent naming of devices is important for instances such as booting where a particular hardware device needs to get mapped to the same name each time. This isn’t really something you have to mess with when you only have one disk or your configuration doesn’t ever change.
If you’re dealing with shared storage on the other hand, the storage may change as devices fail or the overall configuration changes through upgrades, maintenance, and migrations.
To get the UUID of a block device, use scsi_id.
$ sudo scsi_id -g /dev/sd*
1ATA WDC WD2600YS-72SHB4 WD-WCAP04992109
To get the UUID of a file system for something like grub.conf, try blkid.
$ blkid
/dev/sda1: UUID=”410f586a-3f7a-4ff7-b92a-deadca716984″ TYPE=”ext4″
/dev/sda2: UUID=”1c007689-3ff2-4754-bec0-187690751337″ TYPE=”ext4″
/dev/sda3: UUID=”b947f367-cdab-4f5d-bd7e-13379433c7e5″ TYPE=”swap”
/dev/sda5: UUID=”a861337c-9188-4d74-8cdd-2819e8834988″ TYPE=”ext4″
/dev/sda6: UUID=”1337a86-a128-aa77-8cff-381de8734971″ TYPE=”ext4″
Some operating system like Ubuntu will refer to your file systems this way in grub, others may just use /dev/sda2. For any given grub label using UUID, the kernel line would look something like:
kernel /vmlinuz-2.4.37.11.x86_64 ro root=UUID=1c007689-3ff2-4754-bec0-187690751337
udev – dynamic device management
Setting up persistent naming of your block devices using udev is easy. You need to make a rule utilizes PROGRAM to run scs_id and checks for the matching RESULT.
KERNEL==”sd[a-z], BUS=”scsi”, PROGRAM=”/sbin/scsi_id -g /block/%k”, RESULT=”YOUR-UUID-HERE”, NAME=”fc-san2″
You should make the rule early. Something like 20-persistent-naming or 30-persistent-naming would be fine. If you have other rules that utilize the devices once you’ve renamed them, you definitely want this rule to run first.
Posted by admica @ 18 April 2011