OpenWrt x86-64 UEFI boot = true

The lack of UEFI/EFI boot support has bothered me for a while, New Intel SOC with AES support are common cheap and low in power usage.

Well here is my work around:
refind is a EFI bootloader that can even boot legacy (http://www.rodsbooks.com/refind/)

You need two USB-sticks for this how to (easiest way)
One for OpenWRT and one for temporary store of rEFInd
A running linux desktop env as Ubuntu or Debian.

the steps:
1, Download and DD OpenWRT to a USB-stick (https://downloads.openwrt.org/releases/19.07.1/targets/x86/64/openwrt-19.07.1-x86-64-combined-ext4.img.gz) to your target OpenWRT USB-stick.

2, Expand the second ext4 filesystem (root) with GParted and leave more than 16MB left on the volyme (we need that later for rEFInd bootloader).

3, Download DD the refind usb image to the temporary USB-Stick

4, Use fdisk to check the size in sectors of the refind image partition (fdisk ./refind-flashdrive-0.11.4.img)
Device Start End Sectors Size Type
refind-flashdrive-0.11.4.img 1 2048 14430 12383 6M EFI System
The magic sector size is "12383" write it down!

5, "sudo fdisk /dev/sdX" and create a new partition (3) enter as default for all except the size. Type that magic number we typed down earlier but reduce it with one sector "12382". this creates a partition with the same size as the one in the image

6, Use "Disks" to mark and create a partition backup from the temporary USB-stick. Then mark the new created partition on the OpenWRT USB-stick and Restore the just created partition backup to that partition.

7, Now all partitions is done. But we need to configure booth rEFInd and kernel options to boot nice.
Start with rEFInd, mount the partition "/dev/sdX3" edit ./EFI/boot/refind.conf.
Change "timout" to "5" at line 13 (faster booting)
Change "showtools" to only "shutdown,reboot" at line 261
Change "scanfor" to only "external" (faster boot and refind only scans for OpenWRT as it will add other bootable kernels automatic)
Save refind.conf

8, Mount OpenWRT boot partition "/dev/sdX1" as root
create a file named refind_linux.conf in ./boot/ Edit the file and add
"Boot using default options" "root=PARTUUID=d7349897-03 rootfstype=ext4 rootwait console=tty0 console=ttyS0,115200n8 noinitrd"
Save

9, unmount the OpenWRT USB-stick and put in your UEFI boot only firewall, set up "BIOS" common for boot from USB and boot :wink:

// Agge

4 Likes

You can also pick this pull request for actual UEFI support:

Also, expanding the rootfs and extra partitions created will be undone every sysupgrade, with your method

True, I actualy made a HDD/USB image with a diffrent partition layout later for a easyer install but it's out of the scope on this small easy how to.

If the maintaners of the 64 dist OpenWRT just made a diffrent disk image and added support for both emmc and nvme in the kernel. This solution a bit tweaked should enable both MBR legacy boot and UEFI boot on the same image just by increasing the total size to about 6MB, yes 6 Mega Byte!

What I did in my install image is:
The first partition the EFI boot partition,
second ass linux boot
and third as linux root.
Change the root=PARTUUID=xxxxxxx-2 to the third partiton (xxxxxxx-3) and off we go.

The disk image boots from UEFI if that is enabled, loads rEFInd, rEFInd looks for the vmlinux kernel and the refind_linux.conf file with right options to the kernel and there we got OpenWRT running in UEFI

In MBR Legacy the linux boot partition is the only booatble partiton and it runs as it would normaly (not tested yet as my issue was nu legacy boot in my BIOS) You might have to put the linux boot partition first then rEFInd and last linux root. But it worked on my desktop computer.
Will try that later on

1 Like

EFI image for 19.07.2 is available here - https://github.com/openwrt/openwrt/pull/1968#issuecomment-612372932

What is the benefit of booting uefi for running openwrt?

Some computers lack the traditional bios, in that case the benefit is clear. However, I can boot both traditional bios and uefi, why would I boot uefi?

EFI image for 19.07.2 is available here - https://github.com/openwrt/openwrt/pull/1968#issuecomment-612372932

Those shitty EFI Images won't boot with an USB flashdrive or LTE modem inserted.

@ Aggebitter: thanks for that instuctions! atm this is the only way to get openwrt working on UEFI-only machines.--- even with LTE modems and flashdrives attached.

1 Like

Some new machines (especially small embedded types with Atom CPUs) will only boot with UEFI.