How to boot system from USB using GRUB
Almost every modern computer has a dedicated menu to choose from which device the system should boot. If not, there is an option in BIOS/UEFI to change that. But what if both options failed for some reason?
One of my old computers runs Linux with GRUB as a bootloader. I use it from time to time, but one day the filesystem crashed, and even fsck
couldn’t repair it. I prepared a USB stick with the new system, but I couldn’t boot from it – BIOS was restoring the booting order on every reboot. Moreover, ever since I installed GRUB, the shortcut to summon booting device selection stopped working.
I had an opportunity to learn how to boot from USB using GRUB.
How to boot from USB using GRUB
I assume that you already have a bootable USB drive with your favorite Linux distro. If not, you can use a tool called Unetbootin to create a bootable USB drive. In this case, I use a Ubuntu distro.
If you have your bootable USB drive, insert it into the computer.
Boot from proper device
When the GRUB screen appear, press C or ESC to go to the GRUB console. You should see the grub>
prompt.
First, check if GRUB detects your USB drive. Type command ls
to see available devices.
grub> ls
(lvm/ubuntu-vg-swap_1) (lvm/ubuntu--vg-root) (hd0) (hd0,msdos1) (hd1) (hd1,gpt2) (hd1,gpt1) (cd0)
GRUB recognizes my USB stick as (hd0,msdos1)
. I know it because I recently formatted it and created MS-DOS (FAT) partition.
Now, change the root to this device.
grub> set root=(hd0,msdos1)
You can check if you’re using a proper device. By using the command find
and pressing TAB key, you can preview the list of files on it.
Next step is to locate the bootloader on USB stick to chain-load. In my case, the path to the bootloader is /efi/boot/grubx64.efi
. You can use TAB to invoke auto-completion and type the path faster.
grub> chainloader /efi/boot/grubx64.efi
To invoke the new bootloader, run the command boot
.
grub> boot
Summary
This process doesn’t look so complicated. However, it took me almost two hours before I finally figured it out. I tried different ways to fix the filesystem first, but starting from scratch was the easiest one. Fortunately, I hadn’t had essential data there, but it showed that it’s worth having a backup of your most important files. You have it, right?