Software & AppsOperating SystemLinux

How To Make an External Hard Drive Bootable with Grub

Ubuntu 2

In this comprehensive guide, we will walk you through the process of making an external hard drive bootable using Grub. This is particularly useful for those looking to run a different operating system without altering their main system setup.

Quick Answer

Yes, it is possible to make an external hard drive bootable with Grub. By partitioning the external drive, installing Ubuntu in UEFI mode, mounting the drive, chrooting into the Linux partition, creating a directory for Grub, mounting the EFI partition, installing Grub, updating Grub, configuring fstab, and rebooting the PC, you can successfully make your external hard drive bootable. This allows you to switch between different operating systems without altering your main system setup.

Preparing the External Hard Drive

Firstly, we need to partition the external hard drive. This can be done using a tool like GParted. Ensure that you create a partition on the external drive with the GPT (GUID Partition Table) format. This partition should be formatted to FAT32 and used as the EFI system partition (ESP). The boot and esp flags should be set on this partition.

Installing Ubuntu in UEFI Mode

When installing Ubuntu on the external drive, make sure to select the UEFI boot mode. This ensures that Grub is installed correctly and can boot from the external drive.

Mounting the External Drive

After installing Ubuntu, boot into an Ubuntu live USB and connect the external hard drive. Open a terminal and list the partitions of all devices using the command lsblk. This command will display all block devices (hard drives, flash drives, etc.) in a tree-like format. Identify the Linux partition and the EFI partition of the external drive.

Mounting the Linux Partition

In the terminal, use the command sudo mount /dev/sdXY1 /mnt to mount the Linux partition of the external drive. Replace XY1 with the appropriate partition name. The sudo command is used to execute the command as a superuser, mount is the command used to mount a filesystem, /dev/sdXY1 is the device and partition you want to mount, and /mnt is the directory where you want to mount the partition.

Mounting Critical Virtual Filesystems

Mount the critical virtual filesystems using the command for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done. This command mounts several directories that are necessary for the system to function properly.

Chroot into the Linux Partition

Use the command sudo chroot /mnt to enter the external drive’s Linux filesystem. The chroot command changes the root directory for the current running process and their children. A running process is started with a single root directory but with chroot it can change to another directory.

Creating Directory for Grub

Use the command mkdir -p /boot/efi to create the directory where Grub will install its files. The mkdir -p command creates a directory and its parent directories as needed.

Mounting the EFI Partition

Use the command mount /dev/sdXY2 /boot/efi to mount the EFI partition of the external drive. Replace XY2 with the appropriate partition name.

Installing Grub

Use the command grub-install /dev/sdX to install Grub on the external drive. Replace sdX with the actual drive identifier. The grub-install command is used to install GRUB on your drive.

Updating Grub

Use the command update-grub to update the Grub configuration. This command will generate a new configuration based on the currently installed kernels and available operating systems.

Finding the UUID of the EFI Partition

Use the command blkid or ls -l /dev/disk/by-uuid to find the UUID of the EFI partition. The UUID is a unique identifier for the partition and is necessary for the next step.

Configuring fstab

Use the command sudo nano /etc/fstab to edit the fstab file. The fstab file is a system configuration file and is used to inform the Linux system of partitions and filesystems that the system should mount upon boot. Add the following line, replacing xxxx-xxxx with the UUID from the previous step:

UUID=xxxx-xxxx /boot/efi vfat umask=0077 0 1

Make sure to comment out the fstab entry for the Windows ESP to avoid conflicts.

Exiting the Chroot Environment

Use the command exit to exit the chroot environment. This will return you to the original terminal session.

Rebooting the PC

Finally, use the command sudo reboot to reboot the PC. After the reboot, your external hard drive should be bootable.

By following these steps, you can now switch between Windows and Linux by simply plugging in the external drive and selecting it from the EFI boot manager. This setup offers a flexible and non-destructive way to experiment with different operating systems. Remember to always back up important data before making significant system changes.

Can I use this method to make any external hard drive bootable with Grub?

Yes, you can use this method to make any external hard drive bootable with Grub as long as it is compatible with the EFI system partition (ESP) and the Linux filesystem.

Do I need to have Ubuntu installed on my main system to make the external hard drive bootable?

No, you do not need to have Ubuntu installed on your main system. You can use an Ubuntu live USB to perform the necessary steps to make the external hard drive bootable.

Can I use a different partition format other than FAT32 for the EFI system partition (ESP)?

No, the EFI system partition (ESP) must be formatted to FAT32. This is the standard format for EFI system partitions.

Do I need to have a separate EFI partition on the external hard drive?

Yes, you need to create a separate EFI partition on the external hard drive. This partition will be used by Grub for booting.

Can I use a different bootloader instead of Grub?

Yes, you can use a different bootloader if you prefer. However, this guide specifically covers the process of making an external hard drive bootable using Grub.

Leave a Comment

Your email address will not be published. Required fields are marked *