BIOS boot issues with RockyLinux 9 AWS AMI created using packer

I have a packer build that I have used to create BIOS boot AMIs for RockyLinux 8. I took that same code and updated it to do RockyLinux 9 but I am getting boot issues.

I use amazon-ebssurrogate to take a pre-existing RockyLinux 9 image to create a new one with the LVM setup we wanted. On top of that I have provisioner scripts that builds out the new disk. One of the last steps is to install/setup grub2 on the new disk. I run the following command:

chroot "${ROOTFS}" grub2-install "${DEVICE}"

Then I run:

chroot "${ROOTFS}" grub2-mkconfig -o /etc/grub2.cfg

${DEVICE} is the NVME EBS volume of the new disk.

When I create an instance of the new AMI it does not boot. When I mount the root volume on a working AmazonLiunx volume I see that grub it pointed at the wrong UUID.

Now if I mount all the new volumes on /mnt and the temp filesystems then run chroot /mnt I can access the new volume. If I run grub2-install "${DEVICE} and grub2-mkconfig -o /etc/grub2.cfg again it picks up the Amazon Linux boot volume.

Clearly grub2 does not respect chroot. So how am I supposed to do this correctly? Am I supposed to unmount the Source disk’s /boot mount first then run the grub commands?

I finally figured it out and boy did it kick my ass. Here is what I did:

ROOTFS=/rootfs
DEVICE="/dev/nvme1n1"
efiDEVICE="/boot/efi"
biosDEVICE="/boot"
LVM="/dev/mapper"

umount ${efiDEVICE}
umount ${biosDEVICE}

echo "GRUB_DISABLE_LINUX_UUID=true" >> ${ROOTFS}/etc/default/grub
echo "GRUB_ENABLE_BLSCFG=true" >> ${ROOTFS}/etc/default/grub
echo "GRUB_ENABLE_LINUX_LABEL=true" >> ${ROOTFS}/etc/default/grub

chroot "${ROOTFS}" grub2-install --target i386-pc "${DEVICE}"
chroot "${ROOTFS}" grub2-mkconfig -o /etc/grub2.cfg

chroot "${ROOTFS}" grubby --default-kernel
chroot "${ROOTFS}" grubby --update-kernel=ALL --args=audit=off selinux=0

Now the new EBS volume is bootable.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.