bash error in the grub-install script

Bug #503604 reported by Cristian on 2010-01-05
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grub (Ubuntu)

Bug Description

Binary package hint: grub-installer

1) LiveCD Ubuntu 9.04 desktop x64 booted on my system.
2) I used the grub-install script with the version from the above live cd.

My goal was to correct the grub boot-loader installed on the MBR of my HDD on which I have a partition with Ubuntu 8.04 LTS, after that partition got another number because I modified some partitions.
Since I wanted the version of grub from Ubuntu 9.04 instead of that from Ubuntu 8.04, I run the grub-install script without chroot-ing first, and such that to use the old config files from directory /boot/grub from the Ubuntu8.04 partition (which became /dev/sda2), namely I run the command:

ubuntu> sudo grub-install --recheck --root-directory=/media/Wdc2_Ubuntu-8.04 --debug /dev/sda

and here is the lines of errors during the execution of this command:
+ sync

+ grub-probe -t fs /media/Wdc2_Ubuntu-8.04/boot/grub
grub-probe: error: Cannot open `/boot/grub/'
+ [ = xfs ]
[: 1: =: unexpected operator

+ count=5

which are cause by the if instruction from lines 489-494 from the script:
    489 # On XFS, sync() is not enough.
    490 if [ `grub-probe -t fs ${grubdir}` = "xfs" ] ; then
    491 xfs_freeze -f ${grubdir} && xfs_freeze -u ${grubdir}
    492 # We don't have set -e. If xfs_freeze failed, it's worth trying anyway,
    493 # maybe we're lucky.
    494 fi

The second error is specific to test command and binary operator = when the operands happen to be null string, and can be easily corrected by the usual trick of adding some character on both sides of the test:
replace [ `grub-probe -t fs ${grubdir}` = "xfs" ] by [ x`grub-probe -t fs ${grubdir}` = x"xfs" ]
This error manifested because of the first error given by the execution of grub-probe, in this case:
grub-probe -t fs ${grubdir}
give the error: Cannot open `/boot/grub/' and as such produces a null string in the if test.

This last error occured because it tried to access the file /boot/grub/ from the live CD, instead that from the /media/Wdc2_Ubuntu-8/boot/grub/, i.e. that from the partition where I wanted to install grub config files without chroot-ing first into it. So I think that maybe the script should use the from under the directory specified as --root-directory= to the call of grub-install script.
This can be achieved by using the option -m or -device-map=FILE for the command grub-probe, namely I think that the line 490 from the grub-install script should be replace by:

   if [ X`grub-probe -t fs --device-map=$device_map ${grubdir}` = X"xfs" ] ; then

So, as to conclude, I think that the call to grub-probe from the grub-install script should take into consideration the file specified by the variable $device_map and not the default /boot/grub/, as is doing through the other grub commands in the script.

If it is not corrected, it will affect the outcome of the script in the case that the partition to which is installed is of type XFS (in which case the xfs_freeze from line 491 would not be called as it was desired to be), otherwise (i.e. other types of partitions) the outcome of the script will be the one desired, besides the `cryptic` error messages which could be confusing for a beginner user.

Please bear with my possible mistakes, this is my first bug report, I hope I was clear enough in describing the problem and a possible solution to it.

Probably this bug should be checked also in the grub-install script from the other Ubuntu/Debian distributions which uses this kind of script for Grub legacy install.

Cristian (vtcris) on 2010-01-06
description: updated
Colin Watson (cjwatson) on 2010-02-04
affects: grub-installer (Ubuntu) → grub (Ubuntu)
Changed in grub (Ubuntu):
importance: Undecided → Medium
status: New → Triaged
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers