I use Ubuntu and used the following steps to make an UEFI pendrive with OpenWRT (USB was /dev/sdd):
-
Download the x86 image
-
Extract the image
gunzip openwrt-18.06.6-x86-64-combined-ext4.img.gz
-
Write the image to the USB drive
dd if=openwrt-18.06.6-x86-64-combined-ext4.img of=/dev/sdd
-
Resize the second partition but leave 512M at the end of the disk using gparted. This extra space will be used to add EFI system partition in the next step.
-
Use gdisk to add an EFI partition and covert to GPT. Please note the "EF00" code used to create the new partition.
gdisk /dev/sdd
Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
1 - MBR
2 - GPT
3 - Create blank GPT
Your answer: 1
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-15126494, default = 14077952) or {+-}size{KMGTP}:
Last sector (14077952-15126494, default = 15126494) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to 'EFI System'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdd.
The operation has completed successfully.
-
Verify the GPT table and the partitions and format the 3rd partition to FAT32 using gparted.
-
As the UUID of the OpenWRT image partitions are duplicated and EFI GRUB cannot use PARTUUD to find the root FS you have to add label to the first partition of the disk using gparted (umount the partition if the option is grayed out). I used the label "boot". You can use different label but in step 9 use the same label instead of the "boot" word in the first line.
-
Copy the /boot/efi content of your Ubuntu system to the EFI partition (3rd partition of your disk). If you do it right then you will have an "EFI" directory in the 3rd partition of your disk.
-
Update the EFI/ubuntu/grub.cfg in the third EFI partition of your disk to use label instead of UUID (use the same label as specified in step 7):
search.fs_label boot root
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
- Fix the grub config in the first partition of the disk (boot) to use the first GPT partition (gpt1) for the kernel and use the GPT PARTUUID (not the old MBR one) of the second (root) partition of the disk (use the command blkid to reveal this information and use your specific PARTUUID):
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 --rtscts=off
terminal_input console serial; terminal_output console serial
set default="0"
set timeout="5"
set root='(hd0,gpt1)'
menuentry "OpenWrt" {
linux /boot/vmlinuz root=PARTUUID=91ed1df5-473e-43ab-b8cd-593e7be7e3ef rootfstype=ext4 rootwait console=tty0 console=ttyS0,115200n8 noinitrd
}
menuentry "OpenWrt (failsafe)" {
linux /boot/vmlinuz failsafe=true root=PARTUUID=91ed1df5-473e-43ab-b8cd-593e7be7e3ef rootfstype=ext4 rootwait console=tty0 console=ttyS0,115200n8 noinitrd
}