Monday, April 4, 2011

From device names to UUID

After installing my station with ArchLinux, I realized that my 2 SATA controllers were recognized in a random order by the kernel. This means my /dev/sda-b and /dev/sdc-d sometimes switched, and my root FS was simply ignored at boot (what makes the environment a bit... unusable). The solution is simply to change grub and Linux configurations to use disk's UUID or LABEL, instead of logical names.

After googling, the solution was here, thanks to some Linux magic:

$ ls -l /dev/disk/by-
by-id/    by-label/ by-path/  by-uuid/  
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Apr  4 21:21 4de015b1-34a9-4c58-93e4-dc2c3e2502db -> ../../sdc1
lrwxrwxrwx 1 root root 10 Apr  4 21:21 5b507ae1-8b9e-4689-aea0-4e54e0790f46 -> ../../sdd2
lrwxrwxrwx 1 root root 10 Apr  4 21:21 921f9d8d-7921-48e7-ab72-9ee701633174 -> ../../sdd1
lrwxrwxrwx 1 root root 10 Apr  4 21:21 f05a3192-f8cf-4a22-836c-b82a6b00db04 -> ../../sdc2
lrwxrwxrwx 1 root root 10 Apr  4 21:21 fc8e3b24-0a5c-4138-bfd0-9a6cc0fb1ef5 -> ../../sdc3

These symlinks are updated at each boot to point to the right disk's logical name. So, I only needed to edit my /boot/grub/menu.lst and /etc/fstab files, referencing full path to disk UUID, e.g. /dev/disk/by-uuid/4de015b1-34a9-4c58-93e4-dc2c3e2502db instead of /dev/sdc1. Whatever logical names my SATA disks have, grub and Linux always get the right one.

TIP 1: always keep a backup entry in your grub with the old way your disk was referenced, just in case...
TIP 2: use the /dev/disk symlinks, instead of the UUID=4de015b1-34a9-4c58-93e4-dc2c3e2502db convention, which seems not to be recognized by the legacy grub (version 1).

No comments:

Post a Comment