GRUB2 upgrade trigger

Jacek Konieczny jajcus at jajcus.net
Sun Oct 28 22:03:52 CET 2012


There is this piece of code in grub2.spec:

> %triggerpostun -- %{name} < %{version}-0
> if [ $1 -le 1 ]; then
>         exit 0
> fi
> echo "Grub was upgraded, trying to setup it to boot sector"
> /sbin/grub-install '(hd0)' || :

And I don't like it.

Having grub installed does not mean one wants it installed to the MBR of
the first HDD. Some cases when it is not what one wants:

– system booted from a different drive than the first HDD
- EFI-booted system. MBR is not used then. And GRUB may have no place to
  write its MBR bootloader. grub-install invocation is different in this
  case
– grub2 installed on a partition not on a disk (e.g. (hd0,1) instead of (hd0))
– grub installed for booting remote systems via PXE
– grub installed for building system images, not to boot the host
etc.

In most of this cases writing grub to disk is JUST WRONG and may destroy other
data (some other specialized bootloader may be needed for this machine).

Any idea what to use instead?
Maybe an option in /etc/sysconfig/grub?

Would this be ok:

in /etc/sysconfig/grub:
GRUB_INSTALL=/sbin/grub-install '(hd0)'

in grub.spec:
%triggerpostun -- %{name} < %{version}-0
if [ $1 -le 1 ]; then
        exit 0
fi
GRUB_INSTALL=""
if [ -f /etc/sysconfig/grub ] ; then
        . /etc/sysconfig/grub || :
fi
if [ -n "$GRUB_INSTALL" ] ; then
        echo "Grub was upgraded, trying to setup it to boot sector"
        echo "running: $GRUB_INSTALL"
        $GRUB_INSTALL || :
else
        echo "Grub was upgraded, GRUB_INSTALL not set in /etc/sysconfig/grub,"
        echo "not the updating boot-loader."
fi

Greets,
        Jacek


More information about the pld-devel-en mailing list