Update-grub does not set kopt correctly in loopinstallations

Bug #175772 reported by Agostino Russo
6
Affects Status Importance Assigned to Milestone
Wubi
Fix Released
Medium
Unassigned
grub (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: grub

Update-grub does not set kopt correctly in loopinstallations, the following patch should improve the situation. This bug blocks https://blueprints.launchpad.net/ubuntu/+spec/installer-for-windows

300,311c300
< loop_file=$(awk '$2=="/" && $4~"loop" {print $1}' /etc/fstab)
< host_device=$(awk '"'${loop_file}'"~"^"$2 && $2!="/" {print $1}' /proc/mounts)
< host_mountpoint=$(awk '$1=="'${host_device}'" && $2!="/boot" {print $2}' /proc/mounts)
< loop_file=${loop_file#$host_mountpoint}
< if [ -n "$host_device" ]; then
< boot_device=
< root_device="$host_device"
< default_kopt="root=$host_device loop=$loop_file ro"
< else
< default_kopt="root=$root_device ro"
< fi
< kopt="$default_kopt"
---
> kopt="root=$(awk '$2 == "/" {print $1}' /etc/fstab) ro"
836c825
< kopt_2_6="$default_kopt"
---
> kopt_2_6="root=$root_device ro"

Tags: wubi

Related branches

Revision history for this message
Agostino Russo (ago) wrote :
Agostino Russo (ago)
description: updated
Revision history for this message
Agostino Russo (ago) wrote :

diff -u

--- /home/src/extern/grub-0.97/debian/update-grub 2007-10-09 21:52:49.000000000 +0100
+++ update-grub 2008-01-02 09:05:01.000000000 +0000
@@ -297,7 +297,18 @@
 crashdump="0"

 # Default kernel options, overidden by the kopt statement in the menufile.
-kopt="root=$(awk '$2 == "/" {print $1}' /etc/fstab) ro"
+loop_file=$(awk '$2=="/" && $4~"loop" {print $1}' /etc/fstab)
+host_device=$(awk '"'${loop_file}'"~"^"$2 && $2!="/" {print $1}' /proc/mounts)
+host_mountpoint=$(awk '$1=="'${host_device}'" && $2!="/boot" {print $2}' /proc/mounts)
+loop_file=${loop_file#$host_mountpoint}
+if [ -n "$host_device" ]; then
+ boot_device=
+ root_device="$host_device"
+ default_kopt="root=$host_device loop=$loop_file ro"
+else
+ default_kopt="root=$root_device ro"
+fi
+kopt="$default_kopt"

 # Title
 title=$(lsb_release --short --description 2>/dev/null) || title="Ubuntu"
@@ -822,7 +833,7 @@
 # Set the kernel 2.6 option only for fresh install (but convert it to
 # mount-by-UUID on upgrade)
 test -z "$kopt_2_6" && test -z "$(GetMenuOpt "kopt" "")" && \
- kopt_2_6="root=$root_device ro"
+ kopt_2_6="$default_kopt"
 test -n "$kopt_2_6" && kopt_2_6=$(convert_kopt_to_uuid "$kopt_2_6")

 # Extract the grub root

Agostino Russo (ago)
Changed in wubi:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Agostino Russo (ago) wrote :

Note that when not on a loopinstallation, I am setting:

default_kopt="root=$root_device ro"

When in the original code it used to be

kopt="root=$(awk '$2 == "/" {print $1}' /etc/fstab) ro"

My understanding is that using $root_device is safer, since it comes from find_root_device which also parses fstab but is more robust than the awk command (+ handles LABEL and UUID).

Strangely enough kopt_2_6, differently from kopt, did already use $root_device as opposed to the awk code.

Revision history for this message
Agostino Russo (ago) wrote :

Safer code

loop_file=$(awk '$2=="/" && $4~"loop" {print $1}' /etc/fstab)
if [ -f "$loop_file" ]; then
    dev_mountpoint=$(awk '"'${loop_file}'"~"^"$2 && $2!="/" {print $1";"$2}' /proc/mounts|tail -n 1)
    host_device="${dev_mountpoint%;*}"
    host_mountpoint="${dev_mountpoint#*;}"
fi
if [ -n "$host_device" ]; then
    boot_device=
    root_device="$host_device"
    default_kopt="root=$host_device loop=${loop_file#$host_mountpoint} ro"
else
    default_kopt="root=$root_device ro"
fi
kopt="$default_kopt"

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package grub - 0.97-29ubuntu6

---------------
grub (0.97-29ubuntu6) hardy; urgency=low

  * Set kopt correctly for loop installations (LP: #175772). Thanks
    Agostino Russo.

 -- Evan Dandrea <email address hidden> Fri, 18 Jan 2008 14:41:27 -0500

Changed in grub:
status: New → Fix Released
Agostino Russo (ago)
Changed in wubi:
status: Fix Committed → Fix Released
Agostino Russo (ago)
Changed in grub:
status: Fix Released → In Progress
Revision history for this message
Agostino Russo (ago) wrote :

It is necessary to remove the check:

if [ -f "$loop_file" ]; then

Since when update-grub is run by grub-installer in a chrooted installation, /host is not accessible and hence the above block will always evaluate to false. The fact that finde_device > readlink fails and defaults to /dev/hda1 is irrelevant since root_device is overidden by the included patch.

Changed in wubi:
status: Fix Released → In Progress
Revision history for this message
Agostino Russo (ago) wrote :

better still:

- if [ -f "$loop_file" ]; then
+ if [ -n "$loop_file" ]; then

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package grub - 0.97-29ubuntu13

---------------
grub (0.97-29ubuntu13) hardy; urgency=low

  * /host is not accessible when update-grub is run by grub-installer so
    the file test will always fail (LP: #175772). Thanks Agostino Russo.

 -- Evan Dandrea <email address hidden> Wed, 30 Jan 2008 09:11:41 -0500

Changed in grub:
status: In Progress → Fix Released
Agostino Russo (ago)
Changed in wubi:
status: In Progress → Fix Released
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.