Installing grub2 in efi-mode in usb flash drive

I've two different OS, which one is ubuntu. I'm using a PC, NOT a Mac. I use Chimera bootloader that don't find Ubuntu. So, i'd like to install grub 2 in EFI-mode on flash-drive USB. In this way, i can load Ubuntu only if the usb flash-drive is connected.

I followed this guide https://help.ubuntu.com/community/UEFIBooting replacing "/dev/sda" in

sudo efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"

with the usb-pen directory. Then, i've copied the grub.cfg file that exists in Ubuntu partition.Result? Grub2 loads, but when i select the menu entries, grub2 doesn't find any command, or disks. How can i fix this problem?

P.S. Here, there are the photo of the error(when i select ubuntu entry in grub2), the usb-drive's contents and the grub.cfg file http://paste.ubuntu.com/7283661/


I realize I'm a bit late in answering this, but I wanted to do something similar to your setup and ran into the same problem. I finally found a fix and wanted to share it.

It looks like some sort of bug in grub-install. In your USB drive you have this:

/EFI/thenameIgavetomygrub/grub.cfg

Simply make a copy of the folder thenameIgavetomygrub and all of its content (in your case it looks like you called it "grub") into the same EFI folder on the usb drive, and rename that copy as "ubuntu".

Then it should work. At least it did for me.


maybe something need clarify.

一. boot menu //seems on Motherboard

boot menu

A. the items in red box

was created by efibootmgr (or Or similar tools)

they always here, even if the disk device not exist.
//it's not necessary for boot from device. (just add more entry for boot)

1. parts layout

/dev/sda: PTUUID="79be6d7a-0332-4aae-95c6-5798b97db2d5" PTTYPE="gpt"
/dev/sda1: UUID="D18D-CD5C" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="3545bf37-ae87-4741-8cdf-fc196833e869"
/dev/sda2: LABEL="u20" UUID="88c19248-455c-4446-b077-3f63b3123c5f" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="d481f035-fbe8-496c-b8be-11ff7b3cf4fe"
mount /dev/sda1 /mnt/efi/

/mnt/efi/
└── EFI
    └── BOOT
        ├── BOOTX64.CSV
        ├── BOOTX64.EFI
        ├── grub.cfg
        ├── grubx64.efi  // grub2 启动文件
        └── mmx64.efi    // 好像是 诊断模式

2. install boot item:

efibootmgr -c -w -L 'u20_grubx64' -d /dev/sda -p 1 -l '\EFI\BOOT\grubx64.efi'

will got menu item:

Boot0007* u20_grubx64   HD(1,GPT,3545bf37-ae87-4741-8cdf-fc196833e869,0x8000,0x80000)/File(\EFI\BOOT\grubx64.efi)

B. the items in green box

was auto displayed when real disk connected.
they will disappear if the disk not connected.

//they can boot grub2 from corresponding disk.



二. grub //on disk

A. grub on inner ssd. //ubuntu18 grub on ssd

B. grub on usb disk. //ubuntu20 grub on usb

they were installed by grub-install from grub2-common package.

1. parts layout to create

gparted create gpt partition.

  • create sda1 part, set part flag: esp, set part label EFI system partition, format to fat32.
  • create sda2 part, format ext4(as example), //may be installed by linux os, with /boot dir inside.
sda           8:0    0 465.8G  0 disk 
├─sda1        8:1    0   256M  0 part 
├─sda2        8:2    0    40G  0 part 
blkid /dev/sda*
/dev/sda1: UUID="D18D-CD5C" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="3545bf37-ae87-4741-8cdf-fc196833e869"
/dev/sda2: LABEL="u20" UUID="88c19248-455c-4446-b077-3f63b3123c5f" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="d481f035-fbe8-496c-b8be-11ff7b3cf4fe"

2. install grub2 efi

mount parts, wait for install

sudo mount /dev/sda2 /mnt/p2
sudo mount /dev/sda1 /mnt/p2/boot/efi/

do install

sudo grub-install --target=x86_64-efi --recheck --removable --efi-directory=/mnt/p2/boot/efi/ --boot-directory=/mnt/p2/boot /dev/sda1 
Installing for x86_64-efi platform.
Installation finished. No error reported.

this will install grub2 on usb disk sda.

those files in sda1 /:

/mnt/p2/boot/efi/
└── EFI
    └── BOOT
        ├── BOOTX64.CSV
        ├── BOOTX64.EFI
        ├── grub.cfg
        ├── grubx64.efi  // grub2 启动文件
        └── mmx64.efi    // 好像是 诊断模式

will show as 二.B image,
and can be boot from boot menu item 一.B or 一.A



kernel in sda2 /boot, installed by ubuntu20.

/mnt/p2/boot/
├── config-5.8.0-63-generic
├── efi
├── grub
│   ├── fonts
│   ├── gfxblacklist.txt
│   ├── grub.cfg
│   ├── grubenv
│   ├── locale
│   ├── unicode.pf2
│   └── x86_64-efi
├── initrd.img -> initrd.img-5.8.0-63-generic
├── initrd.img-5.8.0-63-generic
├── memtest86+.bin
├── memtest86+.elf
├── memtest86+_multiboot.bin
├── System.map-5.8.0-63-generic
├── vmlinuz -> vmlinuz-5.8.0-63-generic
├── vmlinuz-5.8.0-63-generic



and total boot flow:

efi boot menu item => grub2 on sda1 => kernel on sda2 => rootfs


see also:

https://wiki.archlinux.org/title/Multiboot_USB_drive
https://wiki.archlinux.org/title/GRUB#Installation_2
https://wiki.archlinux.org/title/EFI_system_partition

https://unix.stackexchange.com/questions/18752/change-the-number-of-the-partition-from-sda1-to-sda2