Booting EFI Stub Fedora 25

Recently I realized that Fedora 25 doesn’t use the EFI Stub to boot directly to the kernel if you’re using UEFI on your computer. It boots the grub bootloader and from there you can pick which kernel to boot (or other OS’s if you have them). It probably makes sense if you need to boot into a recovery mode or an older kernel for a rollback but it just doesn’t look as cool and takes longer to get booted into your OS. Here is how to boot into Fedora 25 (or any linux distrobution really) directly without using grub.

First off, run efibootmgr to make sure that you have access to all the efivars (and to ensure that you’re currently booted using UEFI)

[root@blade ~]# efibootmgr
BootCurrent: 0003
Timeout: 1 seconds
BootOrder: 0000,0001
Boot0000* Windows Boot Manager
Boot0001* fedora

Next, go ahead and create a new folder in your EFI partition and name it whatever you want and copy over the kernel and initramfs.

[root@blade ~]# EFIPATH=/boot/efi/EFI/efistub
[root@blade ~]# mkdir $EFIPATH
[root@blade ~]# cp /boot/vmlinuz-4.10.11-200.fc25.x86_64 $EFIPATH/bootx64.efi
[root@blade ~]# cp /boot/initramfs-4.10.11-200.fc25.x86_64.img  $EFIPATH/initramfs.img

Now that we have the kernel and initramfs in the EFI, we need to create an entry for it. In order to do that, we need to get the paramters that we are already booting with.

[root@blade ~]# cat /proc/cmdline

Now that you have those values, you can plug them into efibootmgr. Here’s what my command ended up looking like:

efibootmgr -c -d /dev/nvme0n1 -p 2 --label "Linux" --loader '\efi\efistub\bootx64.efi' -u "root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root rd.luks.uuid=luks-3521a6ac-f4f1-4814-8fb2-7243be8778b8 rd.lvm.lv=fedora/swap rhgb quiet LANG=en_US.UTF-8 initrd=\\EFI\\efistub\\initramfs.img"

Of course, you can change the order of what is booted with efibootmgr as well. This is my boot order:

[root@blade ~]# efibootmgr
BootCurrent: 0003
Timeout: 1 seconds
BootOrder: 0003,0000,0001
Boot0000* Windows Boot Manager
Boot0001* fedora
Boot0003* Linux

If you have any issues with efibootmgr at all, the error messages kind of suck. You can always run strace on the command to get a little more info… As I had to do when I remembered this laptop has an NVMe drive instead of regular sata…. (maybe I’m just dense)

[root@blade ~]# strace efibootmgr -c -d /dev/sda -p 2 --label "Linux" --loader '\efi\efistub\bootx64.efi' 2>&1 | tail -n 7
)                       = 1
open("/dev/sda", O_RDONLY)              = -1 ENOENT (No such file or directory)
write(2, "Could not prepare Boot variable", 31Could not prepare Boot variable) = 31
write(2, ": No such file or directory\n", 28: No such file or directory
) = 28
exit_group(5)                           = ?
+++ exited with 5 +++

Of course, I recommend keeping the grub bootloader in tact just in case you need recovery or a kernel rollback 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *