grub2 install issues

We have had support for configuring grub2 in EL7 for quite some time now but up until this week we had not tackled the install-time support that we require.

When installing a machine we boot either via PXE or using an ISO image. Either way we mount the root filesystem for the target system at /root. With the legacy grub this has never posed a problem but with the new grub2 this has given us a lot of difficulties. The biggest problem is with the design of the tool which is provided to generate the configuration file (grub2-mkconfig). This script runs all the executable scripts stored within /etc/grub.d and then uses the text sent to stdout to generate the configuration file /boot/grub2/grub.cfg. This script has hardwired paths to files in /etc and /boot which is useless for anyone with their target root mounted elsewhere.

My first thought was to try a slightly hacky approach by using the chroot system call. This resolved the issue with writing to the wrong file locations but broke the grub2-probe script which needs to be able to poke around in /proc. I really did not want to have to mount that partition (and possibly others) inside the chroot location so that approach was dropped.

My second idea was to just hack the grub2-mkconfig script to take additional options. This should be a technically simple solution but this failed due to the slightly crazy packaging of grub2 as an RPM by Redhat. They already apply a lot of patches and these have been done using git. In fact, the SRPM will only build when git is installed. I can find no way to apply one additional simple patch. You are forced to do it the very complicated Redhat way or not at all. So, that option has now been dropped as well.

My third approach, and the most promising so far, is to create my own simple alternative script which provides the functionality in the grub2-mkconfig script which we actually require. All it has to provide is enough capabilities to configure the system so that it is bootable after the install phase has completed. On the next boot we can rerun the full script when the grub2 component is started.

As part of this work I’ve extended the functionality of the lcfg script which generates the menu entries to more closely match those provided by default (e.g. 10_linux). It is now possible to use the locations and types of the root and boot filesystems which are detected by the standard grub2 probe scripts. This means it is now very easy to add an additional menu item, something like this:

!grub2.menuitems     mADD(linux)
!grub2.id_linux      mADD(dice)
!grub2.title_linux   mSET(DICE Linux Kernel)
!grub2.kernel_linux  mSET(/vmlinuz)
!grub2.initrd_linux  mSET(/initrd.img)
!grub2.classes_linux mSET(red gnu-linux gnu os)

!grub2.defaultboot   mSET(dice)

This closely resembles the way we use the legacy grub component in SL6. The filesystem UUID will be automatically added to the kernel command line and the necessary grub2 modules will be loaded.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply