This can happen when you install Ubuntu onto a device with multiple ESPs in its disk or disks. Seems to be a fairly old bug of Ubuntu, when you have multiple ESPs set up, the installation program only use the first one it found. Here's some detailed info
Reason to change:
When you are setting up more then one EFI system partition, it's most likely because you want a multi-booting with each OS installed on separated physical disks. In that case, your Ubuntu disk pretty much would be an external storage device, thus once you set Ubuntu as the first entry in your UEFI boot list, your computer automatically boots into Ubuntu when you plug your external disk in, and boots into another OS when external disk is removed. And that's where the default installation behavior cause trouble. As you remove the external device, the Ubuntu boot files are still in the ESP of your internal disk, so bootloader loads them first at computer start up, but then it can't find the actual Ubuntu OS, and you ends up stuck in the grub command line.
Solution:
In my case it's fairly easy, I had to get into my Ubuntu system and copy every thing from the old ESP to the ESP I want Ubuntu to boot from, then configure it using efibootmgr
.
Show disk info:
$ lsblk -e 7 -o name,fstype,mountpoint,uuid,partuuid
NAME FSTYPE MOUNTPOINT UUID PARTUUID
sda
├─sda1 vfat /boot/efi 0C47-F306 60c76b70-01
├─sda2 60c76b70-02
└─sda5 ext4 / 8357ad81-13cf-48a9-b74e-a528df7e79d6 60c76b70-05
nvme0n1
├─nvme0n1p1 vfat /media/my_user/SYSTEM_DRV C6B4-C00B aaeb7117-8371-4ab0-9d3f-c3913a79d819
└─...
Inspect current boot entries:
$ efibootmgr -v
BootCurrent: 0002
Timeout: 0 seconds
BootOrder: 0002,0000
Boot0000* Windows Boot Manager HD(1,GPT,aaeb7117-8371-4ab0-9d3f-c3913a79d819,0x800,0x82000....
Boot0002* ubuntu HD(1,MBR,0x60c76b70,0x800,0x100000)/File(\EFI\ubuntu\shimx64.efi)
(note that I had an MBR partition type for my current ESP because I parted it on an old computer, I don't have problem with it but you may want to make sure using GPT, modern UEFI may not recognize MBR disks)
Say I want to change active ESP from sda1
to nvme0n1
. Once copied all files, this partition should have an EFI/ubuntu
directory (with absolute path MOUNTPOINT/EFI/ubuntu
), where Ubuntu boot files are located. Now create a boot entry for the new ESP:
$ sudo efibootmgr -c -d /dev/nvme0n1p1 -l \\EFI\\ubuntu\\shimx64.efi
Run efibootmgr -v
again, check if the PARTUUID
of the new ESP shows up in the new entry. Then edit /etc/fstab
, replace the UUID of old ESP with new one to auto mount new ESP to /boot/efi
at next boot.
That's all for me. You may also want to adjust boot order using efibootmgr -o
, or delete old Ubuntu entry using efibootmgr -b 0002 -B
. If you don't feel safe to reboot, you can still find more detailed answers like this one. It's also great to prepare a live USB for recovery, in case something really went wrong