diskimage-builder/diskimage_builder/elements/rhel/post-install.d/03-reset-bls-entries
Steve Baker e129fad7f8 Move reset-bls-entries to post-install
03-reset-bls-entries was previously a pre-install script to run after
the machine-id was set, but a new kernel may be installed during the
install phase, which will install another bls entry file with a
filename which differs from the machine-id.

This means this package installed bls file won't be updated when
grub2-mkconfig is called, resulting in incorrect kernel args and boot
device in the entry file that will get booted by default.

By fixing the filenames after the new kernel is installed,
grub2-mkconfig will update the bls file that actually gets used on
boot.

Change-Id: I653bef9638e38ded68458fd40d90e30e5206caad
2022-04-21 10:13:10 +12:00

40 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
if [[ ! '9' =~ ${DIB_RELEASE} ]]; then
exit 0
fi
# This is a workaround for the grub issue reported upstream with
# https://bugzilla.redhat.com/show_bug.cgi?id=2032680
# This renames the BLS entries from the upstream .qcow2 image in
# /boot/loader/entries with the current machine-id. This means that in the
# bootloader setup, grub2-mkconfig will update config options as required.
pushd /boot/loader/entries
machine_id=$(</etc/machine-id)
for entry in *.conf; do
new_entry=$(echo $entry | sed "s/^[a-f0-9]*/$machine_id/")
echo "renaming $entry to $new_entry for new machine-id"
if [[ $entry != $new_entry ]]; then
mv $entry $new_entry
fi
# RHEL-9 is unique in having a separate /boot partition, fix the paths to assume
# /boot will be in the root partition.
sed -i "s| /vmlinuz| /boot/vmlinuz|" $new_entry
sed -i "s| /initramfs| /boot/initramfs|" $new_entry
done
popd
echo "--- Show kernels ---"
grubby --info=ALL