update-grub sets wrong root argument

Bug #508901 reported by Matthew Exon
40
This bug affects 7 people
Affects Status Importance Assigned to Milestone
grub2 (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

Binary package hint: grub2

I've made a backup of my system with dd and then changed the UUID and label of the drive. I would like to be able to boot from either the main system or the backup, ideally regardless of whether the backup is in a USB enclosure or mounted internally.

When I run update-grub, even though it correctly finds the backup and uses its UUID as a parameter for the search command, it still sets the root= argument of the linux command to the main system. This makes the backup unusable.

So in my setup, the original drive is 7f0e857e-6118-4696-bdc6-7c51b31e1002, and the backup is 9de2fc84-1128-41eb-9c1b-a444d070d415. Each one has its fstab set up to mount itself as root. The generated boot options look like this:

### BEGIN /etc/grub.d/10_linux ###
menuentry "Ubuntu, Linux 2.6.31-17-generic" {
        recordfail=1
        if [ -n ${have_grubenv} ]; then save_env recordfail; fi
 set quiet=1
 insmod ext2
 set root=(hd0,1)
 search --no-floppy --fs-uuid --set 7f0e857e-6118-4696-bdc6-7c51b31e1002
 linux /boot/vmlinuz-2.6.31-17-generic root=/dev/sda1 ro quiet splash
 initrd /boot/initrd.img-2.6.31-17-generic
}
...
### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Ubuntu, Linux 2.6.31-17-generic (on /dev/sdb1)" {
 insmod ext2
 set root=(hd1,1)
 search --no-floppy --fs-uuid --set 9de2fc84-1128-41eb-9c1b-a444d070d415
 linux /boot/vmlinuz-2.6.31-17-generic root=UUID=7f0e857e-6118-4696-bdc6-7c51b31e1002 ro quiet splash
 initrd /boot/initrd.img-2.6.31-17-generic
}

I tried uncommenting the GRUB_DISABLE_LINUX_UUID=true" line in /etc/default/grub, but it only affects the output of 10_linux, not 30_os-prober.

ProblemType: Bug
Architecture: i386
Date: Sun Jan 17 21:07:18 2010
DistroRelease: Ubuntu 9.10
Package: grub2 1.97~beta4-1ubuntu4.1
ProcEnviron:
 LANGUAGE=en_GB.UTF-8
 PATH=(custom, user)
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-17.54-generic
SourcePackage: grub2
Uname: Linux 2.6.31-17-generic i686

Revision history for this message
Matthew Exon (ubuntubugs-mexon) wrote :
Revision history for this message
Rolf Leggewie (r0lf) wrote :

I agree, grub2 is a complete mess here and this problem looks closely related to what I reported in bug 510824. I talked to the devs in #grub about it, but unfortunately they don't seem to care about shipping a quality product.

Changed in grub2 (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Jordan (jordanu) wrote :

/etc/grub.d/30_os-prober uses os-prober to determine the parameters to pass to linux. os-prober in turn looks at what is passed to the kernel in that system's /boot/grub/grub.cfg. Since that system is a copy of the main one, its grub.cfg has the main system's UUID for the root= parameter.

That is my guess of what is happening at least. If I'm correct then booting/chrooting into the backup system and running update-grub ( or manually fixing the root= in the backup's grub.cfg ), then booting into the main system and running update-grub there should give you a working entry for the backup system.

Revision history for this message
Rolf Leggewie (r0lf) wrote :

Jordan, thank you for that explanation. I would say, that is way to complicated for an ordinary user (I consider myself proficient with them and would have to reread a couple of times to understand what it is you want the user to do). This needs to be "dumbed down" so that it just works and an ordinary user won't even run into the problem described here.

Revision history for this message
Rolf Leggewie (r0lf) wrote :

proficient with them = proficient with computers

Revision history for this message
der_vegi (m-may) wrote :

Maybe this is related to bug 551790?

Revision history for this message
wild.ideas (wild-ideas) wrote :

Appears to be related to Bugs 392836, 462961, and 551790.

Revision history for this message
Lars W (lavs) wrote :

I had a similar problem after copying all files from the root partition /dev/sda1 to another partition /dev/sdb1 and trying to tell grub to boot from there now.

I digged into problem a little bit...
When i run `update-grub` it runs each of the files in `/etc/grub.d/`, my linux copy (Ubuntu in this case) gets detected by `30_os-prober`. This will run `/usr/bin/os-prober`. This works fine. In the `for OS in ${OSPROBED} ` loop it goes into the linux) branch, but somehow sets the $LPARAMS variable wrong. This is due to the sometimes-wrong output of `/usr/bin/linux-boot-prober`. In that script, there is a loop `for test in /usr/lib/linux-boot-probes/mounted/*`, which runs the file `40grub2` from there in my case. (I know that from the debug output flooding syslog.) This script calls its `parse_grub_menu` function with some parameters, and parses "$mpoint/boot/grub/grub.cfg", where $mpoint is the mount point of /dev/sdb1. However, the grub.cfg in there contains the old UUID of /dev/sda1, because it is just a binary copy and does not come from a fresh install.

My plan A was to fix this, take the correct UUID from the device (here: /dev/sdb1), corresponding to the mapping from /dev/disk/by-uuid/ and post a patch. But the inner works of grub seem to complicated for me. I lost motivation to do that.

Now that I know what the problem is, I took plan B, and chrooted into /dev/sdb1, ran update-grub in there, and reboot. You only need to do that once, afterwards the files are okay.
(...btw, for similar setups: you might want to have two different /etc/fstab on each of the partitions.)
This is somewhat a workaround. But here it goes:

mount /dev/sdb1 /mnt/disk
mount -o bind /dev /mnt/disk/dev
mount -o bind /sys /mnt/disk/sys
mount -t proc /proc /mnt/disk/proc
cp /proc/mounts /mnt/disk/etc/mtab

chroot /mnt/disk /bin/bash
grub-install /dev/sdb
update-grub
exit

(Plan C would have been to update the grub.cfg with the correct UUID manually.)

Revision history for this message
Peter Passchier (peter-passchier) wrote :
Rolf Leggewie (r0lf)
tags: added: patch
Revision history for this message
Rolf Leggewie (r0lf) wrote :

Peter, have you tried to get this into upstream or at least into Debian?

Revision history for this message
Peter Passchier (peter-passchier) wrote :

The problem with this solution is, it is discarding most of the information of os-prober, and instead is just enumerating the kernels & initrds that are listed in /lib/modules. Now I haven't checked with many distributions, but I know Ubuntu, Debian, OpenSUSE and RedHat is using this same location. But you could build boot entries for any kernel you can find anywhere. It's just that you couldn't build initrds for those other kernels because update-initramfs will not run (I don't know about dracut).

I have reported a related problem in these forums, but got a Won't Fix. I'm now maintaining my own patches for my own needs, and anybody is welcome to them.

Revision history for this message
james harris (azalea4va) wrote :

HOLY COW!!!! This bug was reported in 2010 AND STILL HAS NOT BEEN FIXED ! Totally unacceptable.

To make sure we have a common understanding. I have linux on partition sda9 and "other" version of linux on partitions sda8, sdb8, and sdb9. The menu entries for ALL the "other" linuxes all specify the sda8 partition is the root partition, which is wrong for the sdb8 and sdb9 partitions. The bug applies if one is specifying the root using UUID or device name.

I have inserted the following line into 30_os-prober as a Bug-Work-Around. The BWA only works because I am specifing root with a device name and not a UUID. A different BWA would be required for those using UUID. Fixing this should not be a major undertaking. I cannot fathom why in some much time it has not been addressed.

LPARAMS=`echo $LPARAMS | sed "s:root=/dev/[A-Za-z0-9]* :root=$LROOT :"`

Revision history for this message
Lars W (lavs) wrote :

I think either linux-boot-prober or update-grub need a fix. As far as I remember, the point was that $mpoint/boot/grub/grub.cfg is not a reliable source of information. However, if you can do `mount $DEVICE $mpoint`, you can trust that $DEVICE correct, because the environment in which update-grub is called is mostly likely the new/current/correct one. At the very least, one could check if the "root" from linux-boot-prober is mountable and if not, fall back to what Peter's patch does.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.