3

I am writing this from inside ubuntu 16.04 on a 1TB USB external hard drive. It works fine on this laptop, but when I try to boot from the UEFI boot menu of any other computer, the drive shows up as an external HDD, but when selected, will not boot linux but rather boots back to the Windows OS on the computer. I have enabled USB boot and disabled secure boot to see if that was the issue but it did not correct.

Interesting point: when I boot up my laptop (that will run linux) without the USB attached, having last been running linux, I still get the initial grub menu. Maybe my external drive doesn't have the proper boot/grub info to work on another computer? Maybe that info is stored only here on my laptop?

The external drive is partitioned into the following:

  • ext4 system (no flags) for all linux files
  • linux-swap file system (no flags, shows 0 usage)
  • ntfs file system for me to use for other files, Windows files, etc.

What I want to do is to be able to plug my external HDD into any computer and run the linux distribution. Can anybody help me to make my distribution portable?

Tim
  • 31
  • I like to use labels in fstab for portability just a tip – FreeSoftwareServers Nov 16 '17 at 03:09
  • @FreeSoftwareServers -- UUID is better for portability, since the UUID never changes. Drive labels may change depending on the system, or even on the same system depending on which drive mounts first. – ravery Nov 16 '17 at 03:46
  • @ravery can you support that with a link? I believe a drive label is tied to the partition, the worst i could see is having the same label twice and a race condition. – FreeSoftwareServers Dec 13 '17 at 01:24
  • @FreeSoftwareServers -- the designation given by linux to a drive (sda,sdb, etc) depends on the order it is mounted. thus external drives will often mount as sda when booting from them but not always. and if there is another USB device it could be sdc. – ravery Dec 13 '17 at 07:22
  • Ahh no i meant LABEL=BOOT not /dev/sda – FreeSoftwareServers Dec 13 '17 at 07:23
  • @ravery https://wiki.gentoo.org/wiki/Fstab#UUIDs_and_labels – FreeSoftwareServers Dec 13 '17 at 07:24

1 Answers1

4

Always backup your information before attempting any repairs.

Your assumption is correct. When you installed Ubuntu, it installed grub to the EFI partition of the internal HDD. In order to make the external drive bootable, it needs an EFI System Partition with grub installed in it. Usually this partition is the first partition on the drive. However, moving the root partition can cause boot errors.

If reinstalling is a viable option

Repartition the external hard drive. Delete the linux partition, then make a 500MB partition formated FAT32 and Flagged as ESP (Efi System Partition). Use the remaining space for the linux partition formated Ext4. The result should be:

  • EFI partition 500MB formatted FAT32 and flagged ESP
  • Linux partition formatted Ext4 no flags
  • Swap partition formated swap no flags
  • NTFS partition

Then reinstall Ubuntu. Use the manual partitioning option to select your precreated partitions. Make sure the EFI partition of the internal drive is set to "Do Not Use".

Booting an external drive requires the use of the default media path. Boot the LiveCD, and mount the EFI partition on the external (you may need to teporarily remove the ESP flag to do this). Copy EFI/ubuntu/shimx64.efi to EFI/boot then rename it bootx64.efi. Unmount the EFI partition and set the ESP flag if you had to remove it.

Attempt to repair the current installation

Boot from a LiveCD, and use gparted to shrink the linux partition by 500MB. Create a new partition with the freespace, format it FAT32, and flag it ESP. Record the UUID of the new partition.

Mount your linux partition. Edit etc/fstab. Look for a line similar to:

# /boot/efi was on /dev/sda1 during installation
UUID=BB1E-83B5  /boot/efi       vfat    umask=0077      0       0

Replace the UUID with the one for the new EFI partition.

Next, mount the EFI partitions for both drives (you may need to remove the ESP flag temporarily). Copy /efi/ubuntu/shimx64.efi from the internal drive to /efi/boot/ on the external then rename it to bootx64.efi. Note: you will have to make the folders on the external drives.

After either repair

Finally, mount the EFI partition of the internal drive. Delete the folder /EFI/ubuntu. Reboot and open system settings by pressing the appropriate function key while booting. Change the boot order so USB HDD is before the internal drive.

You should now boot linux when the external is connected, and Windows when the external isn't connected.

ravery
  • 6,874