# Ubuntu – Problem booting Ubuntu on external hard drive

I have this very weird problem with my Ubuntu installation. I installed Ubuntu on an external hard drive (Seagate 2 Terabytes usb3) and everything seems normal.
But when I unplug the external hard drive and plug it again and then start the computer, I cannot boot from this external hard drive.
Do you know how can I resolve this issue?
Thanks!

Note: I know I can repair the boot by launching bootrepair utility, but that's not something I want to do everytime I unplug my external hard drive.
Note2: Changing the harddrive isn't something I want to do. I had CentOS on it before and it worked just great.

If the computer is booting in EFI mode, as your "UEFI" tag and the symptoms imply, then you should first be aware of the cause of the problem: External media normally boot using the default/fallback boot filename, which is EFI/BOOT/bootx64.efi on the EFI System Partition (ESP) on x86-64/AMD64 systems. Most OS installations are to internal disks, which boot using customized entries stored in NVRAM. External media can also boot with such entries; but some EFIs delete entries that they can't see when you boot, so customized entries for external media can disappear if the external medium is unplugged while the system boots another OS.
• The most straightforward solution is to move/rename your boot loader. Ubuntu installs its boot loader as EFI/ubuntu/shimx64.efi and EFI/ubuntu/grubx64.efi on the ESP, which is normally mounted at /boot/efi in Ubuntu. Rename EFI/ubuntu on the ESP to EFI/BOOT on the ESP. You must then rename shimx64.efi to bootx64.efi. (If your system does not use Secure Boot, you may optionally rename grubx64.efi to bootx64.efi instead of renaming shimx64.efi.) This solution has the advantage that your external disk should be bootable on most EFI-based computers of the same architecture as the original computer.
• Install my rEFInd boot manager to your internal disk's ESP and set it as the default boot program. You could do this in Ubuntu by unmounting the external ESP from /boot/efi, mounting the internal ESP to /boot/efi, and installing the Debian package (but not the PPA version). Do not edit /etc/fstab. Once set up in this way, rEFInd should launch on every boot, even when your external disk is unplugged; but because rEFInd builds its boot list on every boot, ignoring NVRAM entries, Ubuntu entries will appear only when the external disk is plugged in. This solution has the advantage of per-boot adaptability. You can even set rEFInd's defaults so that Ubuntu is the default boot option when the external disk is plugged in but Windows takes top spot when the disk is removed. One caveat: If you're using Secure Boot, you'll have to jump through some extra hoops to get it working. Copying the EFI/ubuntu directory tree from the external ESP to the internal one before installing rEFInd, then deleting EFI/ubuntu from the internal ESP, should do the job.
• You can re-install GRUB to an ESP on an internal hard disk. To do this, you'll need to unmount /boot/efi from Ubuntu, mount an internal disk's ESP to /boot/efi, and re-install GRUB. You may want to update your /etc/fstab, too. This approach can be tricky, though; some GRUB configurations rely on a GRUB configuration file in /boot/grub, and if yours does this, /boot will also need to be on the internal disk or else GRUB will stop working when you unplug that disk, which means you won't be able to boot anything except by using the computer's built-in boot manager. I haven't been following the details of where Ubuntu stores its GRUB configuration file, so I'm not sure how likely you are to run into this problem.
Personally, I'd go with one of the first two solutions, since I'm not entirely sure where Ubuntu stores its grub.cfg file these days. That third option might be viable if you know that file gets stored on the same ESP as GRUB, or if you're willing to create a /boot partition on your internal disk.