Skip to content Skip to main navigation Skip to footer

Modifying Linux Boot Files Using /dev/disk/by-id When Restoring To a Different System or Physical Drive

Some Linux distributions (most notably OpenSUSE) will set up the fstab (/etc/fstab) and menu.lst (/boot/grub/menu.lst) files using the /dev/disk/by-id method of identifying partitions. While this normally will work OK, problems can be encountered when an image of the Linux installation is created and then restored to a different drive or system. The restored image will fail to boot, typically with an error message related to /dev/disk/by-id.

To overcome this situation, all lines referencing partitions using the "by-id" method in fstab and menu.lst should be changed so that they are using the UUID method of identifying each partition. The UUID of a partition (for both regular and swap partitions) is created when the partition is formatted, and will always remain valid, regardless of what system or drive the partition is located on.

 

An example of changing an fstab file to use UUIDs:

The lines below are from an fstab file originally set up using /dev/disk/by-id. The first line is for the swap partition, and the second line for the root partition:

/dev/disk/by-id/scsi-3600605b000db099011b1713421c457ad-part1 swap swap  defaults           0 0
/dev/disk/by-id/scsi-3600605b000db099011b1713421c457ad-part2 /    ext3      acl,user_xattr  1 1

To convert these lines to use UUIDs, the UUIDs of both partitions must be determined. The command 'blkid' can be used for this purpose. This command will list all UUIDs for all partitions on a system. The 'blkid' command is included with the e2fsprogs set of utilities, and will be available on all distributions. The 'blkid' command is also available on the IFL boot disk.

Once the actual UUIDs are determined for the partitions, the 2 lines above can be changed as shown below:

UUID=b8484bab-ea06-48a9-96ce-ef9b5a7def34   swap    swap      defaults                0 0
UUID=b13e754d-80d8-431d-a24e-54445693efcb  /          ext3       acl,user_xattr        1 1

 

An example of changing a menu.lst file (stanza) to use UUIDs:

Similar changes are required for the menu.lst file. A typical menu.lst file will contain one or more boot stanzas. Each stanza will have to be reviewed for instances of using /dev/disk/by-id, and each instance of "by-id" will need to be changed to use UUIDs instead.

An example of a menu.lst boot stanza using the "by-id"  method is shown below:

title openSUSE 11.1 - 2.6.27.21-0.1
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.27.21-0.1-default
    root=/dev/disk/by-id/scsi-3600605b000db099011b1713421c457ad-part2
    resume=/dev/disk/by-id/scsi-3600605b000db099011b1713421c457ad-part1 splash=silent
    showopts vga=0x31a
    initrd /boot/initrd-2.6.27.21-0.1-default

Note that the "kernel" line above is actually wrapped 3 times to fit on the screen, so the 3 lines following it are all actually part of the kernel line. The stanza above converted to use UUIDs will look as shown below:

title openSUSE 11.1 - 2.6.27.21-0.1
    uuid   b13e754d-80d8-431d-a24e-54445693efcb
    kernel /boot/vmlinuz-2.6.27.21-0.1-default
    root=UUID=b13e754d-80d8-431d-a24e-54445693efcb
    resume=UUID=b8484bab-ea06-48a9-96ce-ef9b5a7def34 splash=silent
    showopts vga=0x31a
    initrd /boot/initrd-2.6.27.21-0.1-default

The "resume=" value is referring to the swap partition, so the UUID for the swap partition must be used for that value. Note that in addition to changing the "by-id" references to UUIDs, the root (hd0,1) line was also changed to uuid <UUID>. This allows Grub to find the Grub root partition based on its UUID, regardless of what it's actual drive/partition location is.

When editing the fstab and menu.lst files, it is suggested that you make backup copies of the original files before making any changes.


Was This Article Helpful?

0