June 9, 2024
If you've ever tried to install Linux on an external drive, you may have noticed that it boots fine on the machine you used for the installation but doesn't boot on other machines.
Additionally, even if you install everything, including the bootloader, on the external drive, your main drive with Windows and its bootloader may still be modified. This results in your machine automatically booting into GRUB, where you see two OS options.
This issue arises from a bug found in the installers of most Linux distributions. Common advice is to disconnect all other drives except the USB installer and the drive you want to install Linux on. While this prevents the Windows bootloader from being touched, it won't create a truly portable Linux installation. Here's why:
During Linux installation, you can choose where the ESP partition will be created, typically on the drive where Linux is being installed. However, due to a bug, the installer searches for an existing ESP partition on all connected drives. If it finds one, it installs the bootloader there instead of the selected location, fulfilling the first two criteria for the external drive but not the third.
To ensure all three criteria are met for your external drive, disconnect the drive with Windows during installation. However, you still won't be able to boot from this drive on different machines because the bootloader installed is named
grubx64.efi
grubx64.efi
bootx64.efi
The installer creates an entry in the motherboard's NVRAM, called a boot entry, so the BIOS knows about the bootloader named
grubx64.efi
To avoid modifying the Windows bootloader and BIOS boot entries and to create a portable Linux installation, you can use a virtual machine. Here's how:
This installs Linux on the external drive with the bootloader in it without modifying your boot entries.
You can follow the steps in this YouTube video.
After following the tutorial, you may notice that even your machine can't boot from the drive because the BIOS boot entry isn't there, and the bootloader is named
grubx64.efi
bootx64.efi
To fix this, boot into your virtual machine with the live ISO again,
chroot
--removable
Here is what
--removable
It installs the EFI executable to the "fallback" path (e.g.
) to avoid having to register the executable to the UEFI firmware (NVRAM). The UEFI firmware will list it automatically (as a "disk" entry).EFI/boot/bootx64.efi
Follow these steps (adapted from this page):
Mount all partitions from the external drive:
# mount /dev/sdb2 /mnt/ # mount /dev/sdb1 /mnt/boot/efi
Bind mount various virtual filesystems:
# for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B $i /mnt$i; done
Chroot into the system:
# chroot /mnt
Install GRUB with the --removable
# grub-install /dev/sdb --removable
Generate the GRUB configuration file:
# update-grub
Following these steps will ensure that your Linux installation on the external drive is truly portable and can boot on different machines without modifying the main drive's bootloader.