harddisks_by_uuid_in_debian_lenny

Harddisks by UUID in Debian Lenny

or even better Harddisks by Label

in debian Lenny both grub and fstab still use /dev/sda like descriptions for harddrives. this might cause problems as soon as you have more than one harddrive controller in your system (or maybe even with just one controller but several drives?). however, due to some magic voodoo your system might detect your primary boot harddisk as /dev/sda the first time and /dev/sdd the second time you boot your system.. this causes it of course to not mount your root directory and therefore to crash while booting.

the simple way out of this situation is to assign UUID's to the partitions and refer to all partitions by UUID in both grub's menu.lst and in fstab.

so first boot your os and hope it will do so :) if it doesn't keep trying until it eventually does boot :)

check out your /etc/fstab where you can see all partitions that are relevant to the system right now. for all partitions you see a /dev/sda1 or similar name you must now find out the uuid

you can do this by using the tool blkid like this:

# blkid /dev/sda1
/dev/sda1: UUID="a2d94c04-06c3-4d92-9e04-dd9e704c0d31" TYPE="ext3

this shows you the UUID of /dev/sda1

now in your fstab replace a line that looks like this:

/dev/sda1 /               ext3    relatime,errors=remount-ro 0       1

with this:

UUID=a2d94c04-06c3-4d92-9e04-dd9e704c0d31 /               ext3    relatime,errors=remount-ro 0       1

repeat this for all your partitions.

in some distributions, like Debian Lenny, you won't get a UUID for your swap partition. if this is the case disable swap

swapoff -a

then re-create the swap partiton (let's say that was /dev/sda5)

mkswap /dev/sda5

this command should already return the UUID .. if it does not you can try to find it with blkid as described above. if still unlucky you could try to lable the partition (when swap is still disabled). i've read that this might also assing a UUID to the partition.

don't forget to also update your /boot/grub/menu.lst file scroll down to your boot menu entries and edit the line where it says something like:

title        My Linux
root         (hd0,0)
kernel       /boot/vmlinuz-2.6.32-25-generic root=/dev/sda1 ro quiet splash
initrd       /boot/initrd.img-2.6.32-25-generic

with something more like this:

title        My Linux
uuid         a2d94c04-06c3-4d92-9e04-dd9e704c0d31
kernel       /boot/vmlinuz-2.6.32-25-generic root=UUID=a2d94c04-06c3-4d92-9e04-dd9e704c0d31 ro quiet splash
initrd       /boot/initrd.img-2.6.32-25-generic

it might not be necessary to replace “root (hd0,0)” with that uuid line when you only enable one of your controllers in the bios as possible boot devices, but once you're editing that file, do it completely :)

now reboot your system and hope i didn't fool you :)

  • harddisks_by_uuid_in_debian_lenny.txt
  • Last modified: 06.01.2015 19:42
  • by Pascal Suter