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.
Update
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 …
Prelude
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.
Grub
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/ASUS/{N76Y.BIN,N76M.BIN}
/EFI/Boot/bootx64.efi
/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)
etc.
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):
- Boot Partition: Already had one, so I mounted sda1 on /boot, and created a folder /boot/grub2.
- 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/ - 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 - Replacing Default Boot Loader: Tried without effect.
- efibootmgr: Does not work, probably due to the mentioned chicken-egg problem (not booted USB-stick by UEFI)
- Grub 2 environment: Almost forgot to execute
grub2-editenv - create , it creates the /boot/grub2/grubenv/-folder. - Grub Config: Created as described int the tutorial, /sys mounted as mentioned.
- 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
then
insmod gfxterm
set gfxmode=auto
set gfxpayload=keep
terminal_output gfxterm
fi
Recreate grub config …
Note: The unicode.pf2 was already present on my system.
Note2: This will be overwritten by grub2-mkconfig – TODO.
- 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
} - 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.
- Open “BIOS”: Boot PC and press F2 to open UEFI-BIOs
- Open EFI-shell: Navigate to “Save & Exit”/”Launch EFI Shell from filesystem device”
- Open Grub: By typing “fs0:\grub2\grub.efi”
- Select kernel: Normal Grub, enter to start Linux
Note: Just before Grub opens, 2-3 lines flow by … with an error (TODO).
Update
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./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
Like this:Like Loading...
http://blechtog./2012/06/09/uefi-grub2-story-of-my-nightmare/
|