So, I've used Ubuntu for a month or two in dualboot with Windows 8, it looked and ran fine, however it broke down for some reason and I had to restore the entire PC. Due to this bad experience, I decided to reinstall Ubuntu on an external hard drive separated from my main Windows machine. This option seems to be good for both the operating systems.
However, when installing Ubuntu, for some reason, the bootloader Grub was not installed on the external drive, while at the same time, the "old" Grub bootloader was never erased from the PC internal hard drive. As a result, I am in a weird situation: when I want to run Windows, I just power on the pc and go. When I want to run Linux, I have to plug in the external drive, go in the startup menu, and change bootloader from Windows' to Grub. The external hard drive is not bootable (as a usb stick for example) and this long sequence of operations needs to be repeated each time.
Quick recap:
- PC internal hard drive contains Windows OS, Windows bootloader and Grub from the old linux installation.
- External hard drive contains Ubuntu 15.10, possibly Grub, but is not bootable as a USB stick is.
- Every time I want to switch OS I need to change bootloader manually in the startup menu which is tedious.
- Boot devices are ordered as follows: 1. USB 2. External drive 3. Internal drive
My question: How can I make the external drive bootable so that when I want to switch from Windows to Linux I just power off the pc, plug in the USB, power on the pc and go? (without loosing the data I already stored on it and all the preferences)
PS. For some reason Windows is terribly slow when loaded via the Grub bootloader available in the internal drive. Furthermore, if the external hard drive is not plugged in, Grub bootloader shows the Grub rescue panel only. So using the already installed Grub as the only bootloader is not an option.
This is how I installed grub unto my external hard drive (GPT) which had Ubuntu 17.04 installed. When you do this it allows you to boot your Ubuntu on any PC which supports UEFI by using the grub on the external without relying on the PC grub. It can also serve as backup grub in case the is problem with EFI of Windows.
Installing Grub to an external hard drive that has Ubuntu installed
Boot into an Ubuntu live USB and connect the external hard drive.
List partitions of all devices:
From the results of
lsblk
, identify the linux partition and also the efi partition of the external hard drive, i.e./dev/sdXY1
and/dev/sdXY2
respectively. ReplaceXY1
andXY2
with your own partition names.Special mount the linux partition:
Mount critical virtual filesystems:
chroot
into the Linux partition you mounted:You are now in the external hard drive's linux filesystem.
Create the directory where grub would install its files:
If it already exists, then skip to step 8.
Mount the efi partition from step 3:
Install grub to the external hard drive:
Update grub:
Find the UUID of the efi partition (aka 'vfat') and note it down:
or
Now we need to tell fstab to mount that efi partition on boot:
Add the below two lines to fstab replacing xxxx-xxxx with the UUID from step 11:
Make sure to comment out the fstab entry of the Windows esp so it doesn't conflict.
Exit the chroot:
Reboot the PC:
At this point when you reboot and choose your external device from the EFI boot manager, it will boot to grub.
To make Ubuntu automatically boot when you insert the external and Windows to automatically boot when the external is not inserted you would have to create a custom boot entry for Ubuntu to point to the efi on the external drive:
Creating a custom boot entry for Ubuntu to point to efi on the external HD
From Windows EasyUEFI can add or remove boot entries.
From Linux efibootmgr can add or remove boot entries.
Alternative #1 – using EasyUEFI
In Windows download EasyUEFI, install it and run.
Choose the EFI options manager
Choose create 'new entry' with + sign
Choose Linux or other OS and give it a name in the description box
Select the FAT32 EFI partition on the external drive that contains the grub bootloader
Choose browse
Navigate to /efi/ubuntu/shimx64.efi or /efi/ubuntu/grubx64
Save
Move it to the top of the boot entries list
Restart
Alternative #2 – using
efibootmgr
List boot menu entries:
Create a boot entry:
e.g.:
efibootmgr -c -L myubuntu -d /dev/sdX
This boot entry would automatically be the first entry.
/dev/sdX
is the external hard drive with the grub bootloader.You can now reboot and without your intervention Ubuntu would automatically boot when external hard drive is plugged in. When the external hard drive is not plugged in, the PC would skip our Ubuntu boot entry to the next entry which is probably Windows Boot Manager.
I eventually found the solution to my problem. I'll post it here in case someone may need it. Also, I'm not entirely sure what worked and if all the steps I took were really necessary, however this worked.
to check partitions' UUID just type in the terminal
while to edit the fstab file
Now install Grub. (You can also try to copy grub from the internal drive to the external drive partition but it did not work for me).
sudo grub-install /dev/sdX
replace sdX with the actual drive.