Install GRUB2 on USB from Ubuntu Linux

How to Install Grub2 on USB from Linux: In the following tutorial, I'll show you one way of easily installing Grub2 Bootloader to a USB Flash Drive from an up and running Linux Operating Environment. I personally used Ubuntu to perform all of the following steps in this guide.

Note: This Grub2 USB Flash Drive Install tutorial assumes you will be running from Ubuntu to create your Grub2 enabled Flash Drive. It may or may not work from several other Linux operating environments as well.

Prerequisites:

  • Running Linux OS (I.E. Ubuntu)
  • Computer that can boot from USB
  • USB Flash Drive
  • No fear of the Terminal

Warning: By following this Guide, it is assumed you are starting with a freshly formatted USB drive. Be aware that you will be overwriting any existing bootloader and grub.cfg.

Grub2 USB Flash Drive Install using Linux

Before proceeding, take note:
Old versions of grub used --root-directory=/mnt/USB
while current versions use --boot-directory=/mnt/USB/boot

Note: If you do use the wrong syntax, you will receive an error stating "Installation is impossible. Aborting".

1. Boot into a Linux desktop (Ubuntu was used here).

2. Once running from your desktop, insert your USB Flash Drive.

3. To gain admin (root) access, open a terminal ctrl+alt+t, then type the following and press Enter.

sudo su

4. Next, you need to find out which dev is your USB. To do this type

fdisk -l

5. Note which device belongs to your USB.
Use fdisk -l to locate usb device
6. Now, let's mount your USB device so that you can install Grub2. Type the following (replacing x with your actual USB device).

mkdir /mnt/USB && mount /dev/sdx1 /mnt/USB

According to the Grub manual, removable installs require the --removable option. When using this, you must also specify --boot-directory and --efi-directory. In addition we'll include the --force option to allow buggy BIOS systems to detect the USB as a Hard Disk.

7. To install Grub2, type one of the following;

a.) If Grub2 64 bit UEFI x86_64-efi is installed on the Linux host, then type

grub-install --force --removable --no-floppy --target=x86_64-efi --boot-directory=/mnt/USB/boot --efi-directory=/mnt/USB

b.) Or if Grub2 32 bit UEFI i386-efi is installed on the Linux host, then type

grub-install --force --removable --no-floppy --target=i386-efi --boot-directory=/mnt/USB/boot --efi-directory=/mnt/USB

c.) Else if Grub2 BIOS i386-pc is installed on the Linux host, type the following
(replacing  x with your device).

grub-install --force --removable --no-floppy --target=i386-pc --boot-directory=/mnt/USB/boot /dev/sdx

Loopback Boot an Ubuntu ISO from your Grub2 USB (Optional)

The next steps are optional, but will compliment your efforts. You'll be adding a simple example configuration file to your USB that will enable you to directly boot from an Ubuntu ISO file using the loopback feature. You'll then download an Ubuntu.iso onto your USB drive. And finally reboot to test functionality.

8. First, type the following to change to the grub directory on your USB.

cd /mnt/USB/boot/grub

9. Next, to download an grub2 loopback configuration file, type

wget pendrivelinux.com/downloads/grub.cfg

10. Then, to navigate back to the root of the USB, type

cd /mnt/USB

11. Now to download the Ubuntu.iso, type

wget "http://releases.ubuntu.com/groovy/ubuntu-20.10-desktop-amd64.iso" -O ubuntu.iso

12. Reboot your PC, setting your BIOS or Boot Menu to boot from the USB device.

If all goes well, you should now be booting into your Grub2 prepared USB Flash Drive.
GRUB2
Optionally with a Grub2 Boot Menu to Loopback Boot from the Ubuntu ISO copied to your USB.
Ubuntu 20.04 Desktop

Install GRUB2 on USB from Ubuntu Linux published under Flash drive installs using Linux, Using and Configuring Linux 

Disclaimer