I have a linux installation (full installation not live) in a USB stick. When I set it up it uses BIOS to boot but now I need to change it to UEFI because some newer machines only boot in UEFI. I have read thru many articles like this and this and followed the instructions but still it did not work. This is how my usb looks like using fdisk -l
Disk /dev/sdb: 238.5 GiB, 256087425024 bytes, 500170752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x281a9f52
Device Boot Start End Sectors Size Id Type
/dev/sdb1 411648 143362047 142950400 68.2G 83 Linux
/dev/sdb2 143362048 159897599 16535552 7.9G 5 Extended
/dev/sdb3 159897600 500170751 340273152 162.3G 7 HPFS/NTFS/exFAT
/dev/sdb4 * 2048 411647 409600 200M ef EFI (FAT-12/16/32)
/dev/sdb5 143364096 159897599 16533504 7.9G 82 Linux swap / Solaris
where sdb1 is the linux installation, sdb2 & sdb5 is the swap, sdb3 is storage, sdb4 is the EFI partition I created.
I booted from my desktop, inserted my USB stick, then did the following:
$ sudo mount /dev/sdb1 /mnt
$ sudo mkdir -p /mnt/boot/efi
$ sudo mount /dev/sdb4 /mnt/boot/efi
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /proc /mnt/proc
$ sudo mount --bind /sys /mnt/sys
$ sudo mount --bind /run /mnt/run
$ modprobe efivars
$ sudo chroot /mnt
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu-usb --recheck --no-floppy --debug
Grub seems to installed successfully and I got the following output:
BootCurrent: 0001
Timeout: 2 seconds
BootOrder: 0002,0001,001B,001A,0000,0019,0017,0018,001C,0021
Boot0000* Windows Boot Manager
Boot0001* UBUNTU
Boot0010 Setup
Boot0011 Boot Menu
Boot0012 Diagnostic Splash Screen
Boot0013 Lenovo Diagnostics
Boot0014 Startup Interrupt Menu
Boot0015 Rescue and Recovery
Boot0016 MEBx Hot Key
Boot0017* USB CD
Boot0018* USB FDD
Boot0019* ATAPI CD0
Boot001A* ATA HDD0
Boot001B* USB HDD
Boot001C* PCI LAN
Boot001D* IDER BOOT CDROM
Boot001E* IDER BOOT Floppy
Boot001F* ATA HDD
Boot0020* ATAPI CD
Boot0021* PCI LAN
Boot0002* ubuntu-usb
Installation finished. No error reported.
I then unmounted the filesystems and /mnt and reboot with the USB but it did not boot with UEFI. It can still boot on motherboard that supports BIOS but not in those only support UEFI.