Skip to content

EC2 Amazon Linux Stuck in Grub boot loader after reboot

0

I have Amazon Linux instance stuck in Grub boot loader mode after a reboot: The details of the instance are:

uname -a
Linux ip-10-0-66-235 4.14.268-139.500.amzn1.x86_64 #1 SMP Wed Mar 2 18:48:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

this is what I did so far to attempt to fix the issue:

  1. Took a snapshot of the EBS Volume and mounted it to my Linux Rescue VM ( Amazon Linux 2023 )
  2. The mounted EBS volume in my Linux Rescue VM looks like this:
Disk /dev/nvme1n1: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: Amazon Elastic Block Store
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 88339FF9-D8A7-4123-8717-059C494C2499

Device           Start        End    Sectors Size Type
/dev/nvme1n1p1    4096 4294967262 4294963167   2T Linux filesystem
/dev/nvme1n1p128  2048       4095       2048   1M BIOS boot
  1. I then did the following steps to mount the volume and be able to access it as chroot
  2. mount /dev/nvme1n1p1 /mnt
  3. for m in dev proc run sys; do mount -o bind {,/mnt}/$m; done
  4. chroot /mnt
  5. After step 6 I attempt to reinstall grub but getting this error message:
grub-install /dev/nvme1n1p1
/dev/nvme1n1p1 does not have any corresponding BIOS drive.

I am not sure what is causing the error above? /dev/nvme1n1p1 does not have any corresponding BIOS drive. Any help with this would be much appreciated.

asked a year ago2.4K views

3 Answers
1

The issue you're experiencing with your Amazon Linux instance being stuck in the GRUB boot loader after a reboot is a common problem that can occur due to various reasons, including updates or configuration changes. Your approach to troubleshooting is on the right track, but there are a few adjustments we can make to resolve the issue.

First, it's important to note that when reinstalling GRUB, you should target the entire disk device, not just a partition. In your case, you're trying to install GRUB on /dev/nvme1n1p1, which is a partition, not the entire disk. This is likely why you're seeing the error message about not having a corresponding BIOS drive.

To fix this, you should run the grub-install command on the entire disk device. In your case, that would be /dev/nvme1n1. Here's what you should do:

  1. While still in the chroot environment, run: grub-install /dev/nvme1n1

  2. After successfully installing GRUB, update the GRUB configuration: update-grub

  3. Exit the chroot environment: exit

  4. Unmount all the bound directories and the main partition: for m in sys proc dev run; do umount /mnt/$m; done umount /mnt

  5. Detach the volume from your rescue instance and reattach it to your original instance.

  6. Start your original instance.

If the issue persists, you might need to check the GRUB configuration file (/boot/grub/grub.cfg or /boot/grub/menu.lst) to ensure it's correctly configured. Look for any recent changes or updates that might have affected the GRUB configuration.

Additionally, make sure that your instance's boot volume is correctly attached and that you're using the appropriate GRUB image for your system (first disk or first partition on the first disk).

If you continue to face issues, you might consider creating a new AMI with a properly configured GRUB at the standard location (/boot/grub/menu.lst) and launching a new instance from this AMI.

Remember to always take snapshots of your volumes before making significant changes to ensure you can recover your data if needed.
Sources
EC2 Instance not booting, stuck on grub rescue screen | AWS re:Post
Troubleshoot your Amazon EC2 instance using the EC2 Serial Console - Amazon Elastic Compute Cloud
Troubleshoot Amazon EC2 Linux instances with failed status checks - Amazon Elastic Compute Cloud

answered a year ago

EXPERT

reviewed a year ago

0

It does not seem to be working with only nvme1n1

mount /dev/nvme1n1 /mnt
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/nvme1n1, missing codepage or helper program, or other error.

It does work fine with mount /dev/nvme1n1p1

so no progress yet...

answered a year ago

0

Let me provide a detailed solution based on AWS documentation and best practices:

  1. First, your approach to mounting the volume is correct.

Here's the correct sequence of commands based on AWS documentation:

# Mount the partition
mount /dev/nvme1n1p1 /mnt

# Mount necessary system directories
for i in /dev /proc /sys /run; do mount --bind $i /mnt$i; done

# Enter chroot environment
chroot /mnt
  1. For GRUB installation, since you're using Amazon Linux with GPT partitioning, you need to ensure both the BIOS boot partition and the main partition are properly handled. Kindly try these steps:
# Install grub2 to the device (not partition)
grub2-install --target=i386-pc --recheck /dev/nvme1n1

# Generate grub configuration
grub2-mkconfig -o /boot/grub2/grub.cfg
  1. If you're still experiencing issues, verify the BIOS boot partition (nvme1n1p128) is properly flagged. You can check this using:
parted /dev/nvme1n1 print

The BIOS boot partition should have the "bios_grub" flag set.

  1. Additional verification steps from AWS documentation:
# Verify boot configuration
ls -l /boot/grub2
ls -l /boot/vmlinuz*
ls -l /boot/initramfs*
  1. Before detaching the volume:
# Exit chroot
exit

# Unmount everything
for i in /dev /proc /sys /run; do umount /mnt$i; done
umount /mnt

Sources:

If these steps don't resolve the issue, you might want to consider:

  1. Checking system logs in /var/log/ for any boot-related errors
  2. Verifying that the kernel and initramfs files referenced in the GRUB configuration actually exist
  3. Creating an AMI from the volume after repairs for backup purposes
AWS
EXPERT

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.