Install GRUB Bootloader on a Pen Drive or an External Harddisk

Shivam Saxena
3 min readAug 9, 2020

--

Hi readers, In this article, I will guide you to install a GRUB bootloader on a USB storage device such as Pen Drive or External Harddisk. But before that let’s first become a little familiar with term GRUB.

As per the official documentation, GNU GRUB is a Multiboot boot loader. It was derived from GRUB, the GRand Unified Bootloader, which was originally designed and implemented by Erich Stefan Boleyn.

Briefly, a boot loader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software Linux. The kernel, in turn, initializes the rest of the operating system (e.g. GNU).

So in short, this is something that will kick off your OS boot process. If something goes wrong with the Bootloader then you can not boot into your OS.

So without wasting time let’s go straight to the purpose of reading this document.

To install the Bootloader into any USB storage device. We need to run the following commands. (Here I am using Ubuntu 20.04)

Step-1: Install the grub utility using the following commands.

sudo apt updpate
sudo apt install grub-common

Step-2: Find out the external device name. In most cases, it is sdb. But you can use Gparted or any other tool to discover your USB device. Let’s assume it is sdb. So there should be partition something like sdb1.

Step-3: To support UEFI and EFI boot options we have to create a new EFI partition (if it does not exist). Any disk utility such as Gparted can be used for this purpose. We will use FAT-32 as the type of partition.

Before going further please ensure that there should be at least 2 partitions.

  1. /dev/sdb1 : The main partition where any Linux OS can be installed. We will use this for UEFI boot option.
  2. /dev/sdb2 : The EFI partition which we just created. We will use this for EFI (Legacy) boot option.

Step-4: Mount those two partitions.

sudo mount /dev/sdb1 /mnt
sudo mount /dev/sdb2 /mnt/boot/efi

Step-5: Mount other required locations. These are required to make the GRUB work and detect the devices.

sudo mount --rbind /proc /mnt/proc
sudo mount --rbind /dev /mnt/dev
sudo mount --rbind /sys /mnt/sys

Step-6: Change the root to the mounted path.

sudo chroot /mnt

Step-7: Install GRUB on the external device.

sudo grub-install /dev/sdb

If you have an OS installed on an external device and you want to add it to the grub list. Then use the following command.

sudo update-grub

Step-8: Exit from the root shell. Use Ctrl+D to exit.

Step-9: Unmount the previous mounted locations.

sudo umount /mnt/proc
sudo umount /mnt/dev
sudo umount /mnt/sys

Step-10: Turn off your device and try to boot from the external device. You should see the grub terminal.

Hope you find it useful. Thanks for your time.

--

--

Shivam Saxena

Software Engineer at Accolite | Python | Linux | Big Data