random failure of grub-installer, working after several retries

Bug #1926528 reported by christopheg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grub-installer
New
Undecided
Unassigned
grub-installer (Ubuntu)
New
Undecided
Unassigned

Bug Description

I prepared an unattended install usb key for focal base on netboot.iso
"http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso"

I'm modifying it to install a preseed to create user account, auto partitioning and such things.

On some machines the unattended install stops when executing the step "Install the GRUB boot loader on a hard disk".

The problem was rather bizarre because if I retried to execute several times the Install Grub step it eventually worked.

As the installation logs were not saying much, I eventually edited grub-installer on the boot key to enable the commented 'set +x' at the beginning of the script.

Is the content the content of syslog relevant to this bug, both for a breaking boot loader installation and a working one.

I was able to dig out and find where the bug is coming from. Actually the origin of the bug is rather funny.

grub-installer script enables break on error with a 'set -e' at beginning of the script.

A few lines below the script do:

   initial_proc_contents="$(ls $ROOT/proc)"

But in the failing cases ls command is returning an exit code of 1 instead of 0 and stops the script.

I checked by doing a direct ls /target/proc ; echo $? from the shell. And I actually get 1 most of the time and eventually 0 when I get lucky (which would lead to grub installing correctly). My understanding of that the underlying cause is that some process terminated while ls was running and thus the pid of that process disappeard from the /proc directory in the middle of the command.

After find that I was also able to check the bug disappears when modifying grub-installer (just did 'set +e' just before the ls and reenabled 'set -e' just after it, but there may be a better way to fix that).

After that change the grub installation step works every time and if I remove that change it starts again to break randomly.

Hopefully this report will help to fix that behavior in grub-installer as I don't know how to prepackage package it in my key.

Revision history for this message
christopheg (christophe-grosjean) wrote :
Revision history for this message
christopheg (christophe-grosjean) wrote :

For those using preseed and having the same problem, a workaround is to fix grub-installer in partman/early_command.

The following line in preseed.cfg will do the trick:

d-i partman/early_command string \
  sed -i "s/initial_proc_contents=\"$(ls $ROOT/proc)\".*/set +e ; & ; set -e/" /usr/bin/grub-installer ;

Revision history for this message
christopheg (christophe-grosjean) wrote :

above command missing some escapes, here is the correct one

d-i partman/early_command string \
  sed -i "s/initial_proc_contents=\"\$(ls \$ROOT\/proc)\".*/set +e ; & ; set -e/" /usr/bin/grub-installer ;

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.