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?