How to Manually Boot an OS in GRUB

If you change kernels often or otherwise touch GNU GRUB's configuration, or if you use Ubuntu, at some point you may see this screen after booting:

GNU GRUB  version 2.12-1ubuntu7

Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists possible
device or file completions. To enable less(1)-like paging, "set
pager=1".

grub> ▁

It usually means that GRUB configuration is malformed, and that starting from now on - you are on your own to boot the system. To feel more comfortable with this, press TAB as advised by the initial message. Then, to read description of each command use, for example, help search.

When everything is fine, GRUB runs some generic commands to load modules and to prepare a menu. After that, it runs commands specific to a selected menu entry. Among other things, these entries contain path to the kernel image. Finally, it executes boot command. Manual flow is similar: load everything needed to run an OS, find kernel and any other necessary things (if any), and boot.

  1. Let's start by making sure that appropriate loader module is ready:
    grub> insmod linux
    

    bsd for BSD distributions; see GRUB sources or installation for other modules (as of time of writing, Modules chapter is incomplete), and refer to other loaders for specific commands.

  2. Next, find kernel and, for Linux, an initramfs image. Let's see if search will work:
    grub> search --file /vmlinuz
    grub> echo $root
    hd0,gpt2
    

    By default, search will write its result to root variable, but this behaviour can be changed with --set option if needed.

    If you got a result, you can proceed to step 3. If you instead ended up with an error or an empty variable:

    grub> search --file /vmlinuz
    error: no such device: vmlinuz
    grub> echo $root
    
    grub>
    

    You can retry with a different file paths, for example:

    grub> search --file /boot/vmlinuz-linux
    

    This one is used by my Arch Linux installation. For Linux, if everything from [/boot]/vmlinuz[-linux][.old] fails, switch to manual search. Find available disks with ls:

    grub> ls
    (proc) (lvm/root) (lvm/swap) (hd0) (hd0,gpt2) (hd0,gpt1)
    

    Now, for each listed device, execute ls (disk)/. Note the trailing slash. You are looking for any kernel-like and boot-like entries, check subdirectories if needed. When found, set root=:

    grub> ls (lvm/root)/
    bin boot/ dev/ efi/ etc/ home/ lib lib64 lost+found/ media/ mnt/ opt/
    proc/ root/ run/ sbin srv/ sys/ tmp/ usr/ var/
    grub> ls (lvm/root)/boot
    amd-ucode.img grub/ initramfs-linux-fallback.img initramfs-linux.img
    vmlinuz-linux
    grub> set root=(lvm/root)
    
  3. Next step is to run appropriate loader commands. For Linux, use linux and initrd, in this order. For BSD, see one of k{free,net,open}bsd together with accompanying commands.

    First, use linux to select kernel image; path is relative to root. Provide command-line parameters, too. The simplest version is:

    grub> linux root=/dev/mapper/root ro
    

    This time root= is for the kernel. If you don't know this path, you can proceed without providing anything. In this case, startup will fail and drop to a shell. Here, you can proceed with the boot manually or find the path to the root disk under /dev tree, write it down, reboot, and provide it to the kernel.

    Second, use initrd to select initramfs image. You don't need to provide any special arguments this time. Path that is relative to GRUB's root is enough:

    grub> initrd /boot/initramfs-linux.img
    

    Let me repeat, these two commands must be run in this order. Executing linux will reset initrd state.

  4. Finally, kick it off with:
    grub> boot
    

After the system boots, regenerate GRUB's configuration file with distribution-appropriate command, for example, update-grub(8) for Debian.

grub

See also