EFI adventures

If you are like me, you probably have heard of EFI, but don’t know what it means in practice, how to eat it, or what to mix it with. But I recently bought a new PC, and it happened to come with EFI, so I decided to enable it and then I learned many things about it.

Whole new world

First of all, EFI is not something just can just “enable”. Even if your kernel has support for EFI, that won’t make a difference unless you boot it through EFI, and you can’t seamlessly boot through EFI unless you create a boot entry, which is done with efibootmgr, which only works once you are in EFI mode. So it’s a bit of a chicken-and-egg problem.

So how do you enter this world in the first place? First of all, you would need a shell. Some BIOSes come with one, but otherwise you would need to install one, and you can find public links on this wiki page.

But where to put this “shell”? Well, the EFI system partition–yes, you need a dedicated partition (more info here). This partition should be formatted using FAT32, and marked in a special way, so the EFI BIOS would be able to identify it, and use it’s contents.

You copy the shell to this partition on /shellx64.efi (I tried UEFI Shell 2.0 (Beta), but it didn’t work for me, so I used the old one).

Your BIOS should now be able to boot this shell… Somehow. It took me a long time to figure out that in my BIOS, that’s a hidden option on the exit menu, where you can “exit” into a shell.

Congratulations, now you are in EFI mode, and probably type some commands, like in the old DOS days, but not be able to do anything really (unless you have some EFI version of Prince of Persia).

The bootloader

There are a few EFI bootloaders out there, like ELILO, and efilinux, but I decided to go with the safest and familiar choice: GRUB2 (well GRUB was familiar, GRUB2 not so much). Arch Linux’s wiki describes in great detail how to setup GRUB2 for EFI, so I’ll just mention that you need to use a different command (‘grub_efi_x86_64-install’ in the case of Arch Linux), and the files need to be installed in the aforementioned EFI system partition.

You would end up with a file /efi/arch/grubx64.efi, and this is an EFI binary that you can use in the shell. Theoretically you should be able to enter the command “\efi\arch\grubx64.efi”, but for some reason that didn’t work for me, so I had to “cd \efi\arch”, and then “grubx64.efi”. Of course, you first need to choose the right partition, but the shell makes it easier by having aliases to the EFI system partitions, so you first type “fs0:” (or something like that), like I said; very similar to DOS.

Directly, please

But going into the shell and typing those commands every time you boot is cumbersome, which is why you would want to add a boot entry. So, once you have been able to boot Linux through EFI, you should be able to load the ‘efivars’ module, and thus access ‘/sys/firmware/efi/vars/’, which is what ‘efibootmgr’ needs.

Then you can do something like:

efibootmgr --create --gpt --disk /dev/sdX --part Y --write-signature --label "Arch Linux (GRUB2)" --loader '\efi\arch\grubx64.efi'

WARNING: You shouldn’t use this on Mac’s, there’s a different process for those.

In your BIOS you should see the option of booting into “Arch Linux (GRUB2)”, like you have the option of booting into a CD-ROM, and then you can choose that as the first one in the boot order 🙂


But wait a second, that starts to look like two bootloaders: the BIOS has a boot entry, and so does GRUB. Why not boot directly into Linux?

A couple of patches from Matt Fleming enable just that. They should be in version 3.3. Enable CONFIG_EFI_STUB, and copy bzImage to /efi/linux/linux.efi.

So now you can boot directly from the BIOS into Linux (or Windows) with no bootloader at all 🙂

Update: echo "initrd=\efi\arch\initramfs.img root=/dev/sda3 ro quiet" | iconv -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1 --label "Arch Linux" --loader '\efi\arch\vmlinuz.efi' --append-binary-args -


While you are on that, why not enable this new partitioning scheme? It’s more EFI friendly, and you can’t actually install a version of Windows that works with EFI without it. For Windows 7 it’s either EFI and GPT, or non-EFI and MBR; you can’t mix them (don’t ask me why).

Fortunately it’s very easy to switch from MBR to GPT; just run gdisk (from a rescue disk, of course). It’s also easy to switch back, as long ad you haven’t used more than four partitions.


13 thoughts on “EFI adventures

  1. The final EFI boot stub patch is at http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=291f36325f9f252bd76ef5f603995f37e453fc60;hp=55839d515495e766605d7aaabd9c2758370a8d27 .

    However Matt Fleming mentioned that CONFIG_EFI_STUB should not be enabled by default as it increases the kernel image size. However enabling it and booting the kernel via grub2-uefi is makes no difference, and this option will not affect BIOS boot. I don’t think this will be enabled in Arch’s kernel.

    Anyway which UEFI Spec version your firmware uses (Shell “ver” command). Shell 2.0 will work only with UEFI 2.3+ systems (http://sourceforge.net/mailarchive/message.php?msg_id=28690732). But Shell 2.0 is recommended over 1.0, if it works in the system.

    Also next Archboot will include UEFI shell binaries http://projects.archlinux.org/archboot.git/commit/?id=b436f45abc036fbf53338b2670b808bdd46a7101 in the iso itself.

  2. The final EFI boot stub patch is at

    Yes, as I said, the patch series will be on v3.3.

    I don’t think this will be enabled in Arch’s kernel.

    That’s a shame, but I’m not using Arch’s kernel anyway. BTW. There are many config options that are not right IMO. I guess I should contact the Arch Linux mailing list.

    Anyway which UEFI Spec version your firmware uses (Shell “ver” command).


    Also next Archboot will include UEFI shell binaries

    Cool 🙂

  3. [quote]
    That’s a shame, but I’m not using Arch’s kernel anyway. BTW. There are many config options that are not right IMO. I guess I should contact the Arch Linux mailing list.

    You have to open a ticket in the bug tracker for that. ML or forums won’t get the attention of the devs. Anyway what are the config options which you feel are wrong. Are they UEFI related options? I think all the UEFI related options are properly set in the kernel.

    If you want to try out the EFI boot stub, you can try https://aur.archlinux.org/packages.php?ID=50893 once its updated.

    Regarding grub_efi_x86_64-install

    from grub2 split PKGBUILD

    install -D -m0755 “${pkgdir}/usr/sbin/grub-install” “${pkgdir}/usr/sbin/grub_bios-install”
    install -D -m0755 “${pkgdir}/usr/sbin/grub-install” “${pkgdir}/usr/sbin/grub_efi_x86_64-install”
    install -D -m0755 “${pkgdir}/usr/sbin/grub-install” “${pkgdir}/usr/sbin/grub_efi_i386-install”

    sed “s|^\(target_cpu\)=.*|\1=i386|; \
    s|^\(platform\)=.*|\1=pc|; \
    s|/boot/grub|/boot/grub|g” \
    -i “${pkgdir}/usr/sbin/grub_bios-install”

    sed “s|^\(target_cpu\)=.*|\1=x86_64|; \
    s|^\(platform\)=.*|\1=efi|; \
    s|/boot/grub|/boot/efi/efi/grub|g” \
    -i “${pkgdir}/usr/sbin/grub_efi_x86_64-install”

    sed “s|^\(target_cpu\)=.*|\1=i386|; \
    s|^\(platform\)=.*|\1=efi|; \
    s|/boot/grub|/boot/efi/efi/grub|g” \
    -i “${pkgdir}/usr/sbin/grub_efi_i386-install”

  4. Pingback: ‘Adventures’ with EFI « 0ddn1x: tricks with *nix

  5. hi, in the linked list and in your article there is a mention of the bios stub… i looked throug hthe kernel config but I couldn’t find a bios_stub definition (efi_stub is there, alright; kernel 3.3).

    do you know how and where is the bios_stub configuration parameter defined (not the efi_stub)?


  6. I’m wondering what how this boot process actually works. It looks like you have to enter bios so tthat would mean – you push the power button on the box, you hit the key to enter bios (for me that would be Del), then you are able to find some entry in the bios with which you can boot the kernel image directly? Is that right?

    If that is correct then it means it would take a very long time to boot because you have the time (and inconvenience) of entering the bios setup menu every time you wanted to boot.

    Am I missing something here?

    Please, I’d really like to know. I’m planning a Gentoo build right now (actually I’ve been planning it). I’m at the point I’m ready to sit down at the keyboard and begin building (planning is basically over). I would like very much to use this efi_stub and boot this way but I need to understand what to expect.

    Hell, this thing is so cool – I’ll write my own interface if I have to. Just tell me what it’s currently like so I know what I’d have to do.


  7. +Jake As I said, imagine the ‘Arch Linux’ boot entry is like the typical ‘CD-ROM’. Do you have to enter the BIOS every time you want to boot from CD-ROM? No, you can configure the boot order so ‘CD-ROM’ is booted first. Same with ‘Arch Linux’.

    I chose to manually select it this time to show the menu, and to show the speed right after I click it, but normally when I click the power button it boots Arch Linux directly.

  8. Wow. That’s amazing FelipeC. I’m going to be building a gentoo system. If I go this route do I need an initramfs? I thought I read somewhere that efi_stub has all the capabilities of initramfs in it (like for raid and lvm – cause I’ll have those). Also, do you know of a good reference and/ or instruction manual for this?


  9. Pingback: EFI Adventures

  10. “WARNING: You shouldn’t use this on Mac’s, there’s a different process for those.”

    Can you explain process or even better give example on how to boot Windows with True UEFi and not Bootcamp Emulation.

    Rod Smith just release new tool, which is basically refit update. It has ability to tweak boot.conf.


  11. [quote=FelipeC]I guess I should contact the Arch Linux mailing list.[quote]
    Please whatever you do, do not contact the mailing list. Please stay under your bridge and keep quiet.

    BTW it is enabled by defualt, as you probably already know.

  12. +Curtis

    BTW it is enabled by defualt, as you probably already know.

    No, it’s not. You don’t know which configuration options I’m talking about.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s