Troubleshoot your Linux instance using GRUB - Amazon Elastic Compute Cloud

Troubleshoot your Linux instance using GRUB

GNU GRUB (short for GNU GRand Unified Bootloader, commonly referred to as GRUB) is the default boot loader for most Linux operating systems. From the GRUB menu, you can select which kernel to boot into, or modify menu entries to change how the kernel will boot. This can be useful when troubleshooting a failing instance.

The GRUB menu is displayed during the boot process. The menu is not accessible via normal SSH, but you can access it via the EC2 Serial Console.

Before you can use GRUB, make sure you have completed the prerequisites, which include granting access to the serial console and configuring GRUB.

Use GRUB

After GRUB is configured, connect to the serial console and reboot the instance with the reboot command. During reboot, you see the GRUB menu. Press any key when the GRUB menu appears to stop the boot process, allowing you to interact with the GRUB menu.

Single user mode

Single user mode will boot the kernel at a lower runlevel. For example, it might mount the filesystem but not activate the network, giving you the opportunity to perform the maintenance necessary to fix the instance.

To boot into single user mode
  1. Connect to the instance's serial console.

  2. Reboot the instance using the following command.

    [ec2-user ~]$ sudo reboot
  3. During reboot, when the GRUB menu appears, press any key to stop the boot process.

  4. In the GRUB menu, use the arrow keys to select the kernel to boot into, and press e on your keyboard.

  5. Use the arrow keys to locate your cursor on the line containing the kernel. The line begins with either linux or linux16 depending on the AMI that was used to launch the instance. For Ubuntu, two lines begin with linux, which must both be modified in the next step.

  6. At the end of the line, add the word single.

    The following is an example for Amazon Linux 2.

    linux /boot/vmlinuz-4.14.193-149.317.amzn2.aarch64 root=UUID=d33f9c9a-\ dadd-4499-938d-ebbf42c3e499 ro console=tty0 console=ttyS0,115200n8 net.ifname\ s=0 biosdevname=0 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.she\ ll=0 single
  7. Press Ctrl+X to boot into single user mode.

  8. At the login prompt, enter the user name of the password-based user that you set up previously, and then press Enter.

  9. At the Password prompt, enter the password, and then press Enter.

Emergency mode

Emergency mode is similar to single user mode except that the kernel runs at the lowest runlevel possible.

To boot into emergency mode, follow the steps in Single user mode in the preceding section, but at step 6 add the word emergency instead of single.