UEFI, Grub2: Story of my nightmare

UEFI, Grub2: Story of my nightmare

Update 2

This article is historical!
Read my articles at the Pentoo WIKI for pretty examples on how to tackle UEFI.


The info below are my scrambled notes taken when I hit the problem.
UEFI is actually really cool, you don’t need GRUB2 or any bootloader!
Just follow the handbook on Gentoo installation and make sure your kernel is EFI-bootable (rtfm).
Forget about boot-loaders, although you should know the kernel options that you would put into grub.cfg (root=, initrd, etc.)
The only tricky part is putting your kernel as new boot option into the UEFI-bios.
If you’re lucky, your UEFI has a nice gui to select the kernel and set boot options – my gui is crap and has a wrong help info too!
Then you have to resort to one-time using the EFI-shell (search below) to boot the kernel, then use efibootmgr (search below) to place the boot-option.

Todo: Rewrite this now that I know how to do this simple.

I’m writing this done because I see myself halfway through it and want to take notes.

Short version

I received a brand new laptop with bleeding edge hardware on Monday. It uses a new descendant of BIOS called UEFI, which requires Grub2, which is beta. At least the Gentoo docu on it is.

I struggled for days … pre-OS boot problems give me nightmares, no logs, output just flows by if there’s even one … playing around with partition schemes …


My Knowledge

Fairly familiar with grub.cfg, able to click-through BIOS. Was able to put everything except /boot into LVM by creating my own initramfs.
But basically I want such things to just work, debugging OS startup or Grub is no fun!

GPT – GUID Partition Table

GPT is a standard for partition layout and part of Intel’s EFI standard.
Mac and Windows require EFI to boot from GPT partitions.
Basically this is nice: It supports more the 4 primary partitions, thus eliminating secondaries, and also enables really large disks.

UEFI – Unified Extensible Firmware Interface

UEFI is meant as a replacement for BIOS. It was originally called EFI, so this abbreviation is also often used in configurations.

The traditional MBR (Master Boot Record, 515 bytes) is replaced by a designated boot-partition. This must have the boot-flag set and must be formatted with fat16 or fat32. All boot-loaders are placed in that partition, auto-loading by the EFI firmware should happen from “\EFI\BOOT\BOOTx64.EFI”.

There is also an EFI Shell, a shell like tool to get into from EFI-BIOS. It can also start/execute .efi-files.


GNU GRUB is my preferred boot loader.
Grub 1 does not support EFI or GPT.
Grub 2 is beta in Gentoo, it’s trickier to use.
Note: While writing this: www.gnu.org/ has Grub 1.99 – why is it 2.00-beta6 in Gentoo?

My System

The EFI boot-partition was already there as sda1. 200MB in size, FAT32, with Windows Bootloader married to the Asus EFI.

The following was in it:
/EFI/Microsoft/Boot/{MS-stuff, for ex.: bootmgfr.efi, bootmgfw.efi, memtest.efi}

There was no EFI-shell, even it could be selected in the “BIOS-GUI”.
And my system’s “BIOS-GUI” does not provide “a convenient way to select possible options” (quote).

What I did so far

I tried and read about everything in the last days.
This is my current setup:

EFI Boot Option

I have not succedded at creating a new working boot option.
The interface gives these options:
“Add boot option”: Obviously the name to display
“Select filesystem”: HD is only option, unless USB-stick is plugged in.
“Path for the boot option”: The help text mentions as example “fs0:\path\filename.efi”. Now while exactly this syntax works well within EFI-shell, it does not create working boot options, no matter what the help says.

EFI shell

Download from here. I used some other source with a 2.x version, but can’t find it anymore. 1.x works as well.
Place at root of the efi-boot partition as “Shellx64.efi”. If /dev/sda1 is mounted at /boot, this means “/boot/Shellx64.efi”. Any other path or name does not work, the EFI-BIOS will not find it.
Start it in “BIOS”: “Save & Exit”/”Launch EFI Shell from filesystem device”

This will open some sort of command prompt, if the Shellx64.efi file is found.

First a device must be selected. It’s “fs0:” for 1st HD whithout USB-stick, strangely with USB-stick the HD is at “fs1:” and USB-stick occupies “fs0:”
Afterwards “ls” and “cd” around, the backslash “\” is the directory separator, example path: “fs0:\EFI\Boot\Bootx64.efi”.
It also seems to be case-insensitive.
EFI-Shell Commands:
help : Shows available commands. Sadly most scroll out of the screen.
mode : Shows/sets available output modes (set example: mode 128 40)

Grub 2

Grub 1 does not support UEFI out-of-the-box, Grub 2 should be used.
Now this is where I really struggled with, went through several tutorials – all were mostly correct and slightly false.
And there’s a chicken-egg problem: You can’t install Grub 2 unless you booted with EFI, which you “can’t”.
At least I couldn’t use any of the “easy” workarounds mentioned.

Long story, short end: Finally a variation of this guide worked:
Grub 2 Guide – dev.gentoo.org: Variant B: Installing GRUB 2 on Hardware That Supports EFI

This is what I did differently (or had to):

  1. Boot Partition: Already had one, so I mounted sda1 on /boot, and created a folder /boot/grub2.
  2. Copying of grub modules: The guide reads:cp /lib/grub2/x86_64-efi/* /boot/grub2/, but the modules were in /usr/lib/grub/x86_64-efi. I also had to copy the entire subfolder or grub would not find its modules. So I issued: cp -R /usr/lib/grub/x86_64-efi /boot/grub2/
  3. Grub 2 image: I need ext4 support, which for grub is module “ext2”. This was my command:
    grub2-mkimage -p /grub2 -o /boot/grub2/grub.efi -O x86_64-efi part_msdos part_gpt fat ext2 normal
  4. Replacing Default Boot Loader: Tried without effect.
  5. efibootmgr: Does not work, probably due to the mentioned chicken-egg problem (not booted USB-stick by UEFI)
  6. Grub 2 environment: Almost forgot to execute grub2-editenv - create, it creates the /boot/grub2/grubenv/-folder.
  7. Grub Config: Created as described int the tutorial, /sys mounted as mentioned.
  8. Grub Video Mode: I had errors similar to “No video mode supported” and then a blank screen. “videotest” in grub-shell also reported no supported video mode.
    This tip from ArchLinux helped, although my error message was not exactly identical. I ignored the “do not edit this” comment in /boot/grub2/grub.cfg and appended:
    insmod efi_gop
    insmod efi_uga
    insmod font

    if loadfont ${prefix}/fonts/unicode.pf2
    insmod gfxterm
    set gfxmode=auto
    set gfxpayload=keep
    terminal_output gfxterm

    Recreate grub config …
    Note: The unicode.pf2 was already present on my system.
    Note2: This will be overwritten by grub2-mkconfig – TODO.

  9. Grub Menu: Appending this to “/etc/grub.d/40_custom” worked for me, Gentoo root being on sda7:
    menuentry "Gentoo Kernel" {
    set root=(hd0,1)
    linux /boot/linux-3.2.12-gentoo root=/dev/sda7
  10. LVM:
    Current installation is in one ext4 partition (sda7), apart from /boot (=sda1). I want LVM, if possible with everything except /boot within as I had with Grub1 and BIOS. Apparently Grub2 supports LVM, haven’t made an attempt yet.

Current Boot Steps

While finally booting into Gentoo is a relief, the boot process “leaves room for improvement”.
Feels more like a new Ferrari and you have to push-start it.

  1. Open “BIOS”: Boot PC and press F2 to open UEFI-BIOs
  2. Open EFI-shell: Navigate to “Save & Exit”/”Launch EFI Shell from filesystem device”
  3. Open Grub: By typing “fs0:\grub2\grub.efi”
  4. Select kernel: Normal Grub, enter to start Linux

Note: Just before Grub opens, 2-3 lines flow by … with an error (TODO).


I no longer use Grub 2, but a more recent version of the kernel since these can be booted directly by EFI if EFI support is built in.
So no more need for Grub 2, instead of typing “fs0:\grub …” I can now type fs0:\linux-3.4.2-gentoo-r1 root=/dev/sda7″ at the efi shell. It has tab completition for the kernel name, but still this is only a minor improvement.

Update 2: efibootmgr

Should have done this long ago – efibootmgr was able to set a new boot option.
Following the instructions at https://wiki.archlinux.org/index.php/UEFI_Bootloaders#Using_efibootmgr_entry, it was rather easy.

My recent usage:

echo "root=/dev/sda7"  | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1 --label "Gentoo 3.5.0"  --loader "\\EFI\\Gentoo\\linux-3.5.0-gentoo" --append-binary-args -

See man efibootmgr, the relevant options are:

  • root=/dev/sda7 : my root partition (gpt allows more then 4 primary partitions)
  • –disk /dev/sda –part 1 : default partition /dev/sda1
  • –label “Gentoo 3.5.0” : well, a label :)
  • –loader “\\EFI\\Gentoo\\linux-3.5.0-gentoo” : path to kernel translated from /boot/EFI/Gentoo/linux-3.5.0-gentoo


  1. Hamilton · · Reply


    I have the same problem you had. Many thanks for your post but, since I am a newbie, I need some help. I have a Asus K45A laptop and somehow I destroyed the uefi boot, maybe while installing Ubuntu in the laptop (original Windows 7 Home).
    Using boot-repair (from a live Ubuntu session) I can now start both Windows and Ubuntu, but only accessing bios setup. I suppose that happened because the boot-repair considers the laptop in Legacy mode, although the bios is set in UEFI mode.
    I tried efibootmgr, but it did not work.
    Could you explain in details your recent usage (above)? It seems that the system boots from /dev/sda7 (your – and mine – root partition). I suppose that is exactly what happens when I access Ubuntu from the bios setup. Is that so?

    1. UEFI should boot of /dev/sda1. There should be a folder /EFI/BOOT with an BOOTX64.EFI.
      That one is started per default by UEFI.

      You can have other efi-images on that partition, but then they need to be registered in UEFI, either by the GUI in UEFI itself (mine sucks) or by efibootmgr (which only works when you booted through UEFI – that’s a ckicken-egg problem).
      So either:
      a) Create such a BOOTX64.efi with GRUB2. This needs a grub-config/-menu, see my articles at Pentoo Wiki -BootX64.efi image by GRUB2.

      b) Pick a Linux distro, where the LiveCD supports UEFI and boot that through UEFI from CD/USB. Then use efibootmgr, also see the Pento-wiki on the crazy syntax that you have to use.

      1. Hamilton · ·

        Many thanks!

  2. We should develop FMSO in place of uefi as a boot system. the last O stands for OVER. My experience with grub2 and ubuntu 12.04.3 really supports this and it was on a NON uefi board. I installed grub2 and 12.04 and it worked great but the new version couldn’t even boot. boot-repair got it going with only 8 device not connected errors. UEFI sucks..Thanks for a great article I could have used it before I started..well it boots sortof now.

  3. Anthony · · Reply

    Thanks for this blog.
    I think one of the greatest obstacles to learning how to manage UEFI is there is little explanation of what it actually is. I mean, before it was simple: BIOS is in a chip on the motherboard that tells the computer what to do at power-on.

    For UEFI, what they do not state, anywhere, is that this is really the same thing, instructions on a chip on the motherboard. That is called “firmware”, a vital word to use when searching for help. This can sometimes be accessed with a fancy graphical mouse-friendly interface, and sometimes it’s that old text on grey screen BIOS-like interface. Why do some have the graphical and others don’t? Is it something you install on the EFI partition, or is it in the firmware chip? Is the graphical interface actually that mysterious “Launch EFI shell” thing?

    Explanation = zero

    This is just one aspect of it all, never-mind the EFI partition and secure-boot.

    Question: Where is my fancy graphical UEFI interface? Can I even have one on my computer?
    Answer: Keep repeating
    1. Click the Start menu and select Settings.
    2. Select Update and Security.
    Blah, blah, blah. I’m not using windows you dork and just answer the freaking question, if you can….

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: