Grub, the Grand Unified Bootloader, is the most common such bootloader on desktop Linux distributions. Its job is to get the machine from the BIOS or UEFI environment to being able to boot into Linux.
The boot process
Grub has three stages:
- Stage 1 is the earliest stage, designed to be small enough to fit in the 512k footprint of the MBR, the reserved space at the beginning of a hard drive for the bootloader. It contains the
- Stage 1.5 is an intermediary stage that's loaded on systems where the hardware requires further work to access the second stage.
- Stage 2 is the final stage of the Grub bootloader which provides the menu system, the
grub>prompt and all of the code necessary to boot a Linux kernel with an initrd.
Entering the boot menu
Esc or hold down
Shift. If you end up at a
grub> prompt, try running
normal to get back to the boot menu. If you can't, the system doesn't have any boot menu entries and you're going to need to follow the rescue steps below.
ls with no arguments will list detected filesystems:
grub> ls (hd0) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)
You can then view filesystem properties:
grub> ls (hd0,msdos1) Partition hd0,msdos1: Filesystem type ext* - Last modification time 2020-02-17 13:10:55 Monday, UUID 00000000-0000-0000-0000-000000000000 - Partition start at 1024KiB - Total size 498688KiB
Or list contents:
grub> ls (hd0,msdos1)/ lost+found config-4.15.0-55-generic initrd.img-4.15.0-55-generic System.map4.15.0-55-generic vmlinuz-4.15.0-55-generic
Rescuing a system
First, tell the bootloader where it was installed to (usually the location of
/boot/grub when the system is running):
grub> set root=hd0,1 grub> set prefix=(hd0,1)/boot/grub/
We can then set the location of the kernel (
linux) and initrd images. Note that must provide the
root= boot option to the kernel to a valid path to the root device according to
udev. Once configured, tell Grub to try and
grub> linux /boot/vmlinuz-5.0.0-1031-azure root=/dev/disk/azure/root-part1 grub> initrd /boot/initrd.img-5.0.0-1031-azure grub> boot