UEFI booting

Last Friday (Black Friday, since I was in the US this year), I ended up buying for myself an early birthday present; I finally got the ZenBook UX31A that I was looking at since September, after seeing the older model being used by J-B of VLC fame. Today it arrived, and I decided to go the easy route: I already prepared a DVD with Sabayon, and after updating the “BIOS” from Windows (since you never know), I wiped it out and installed the new OS on it. Which couldn’t be booted.

Now before you run around screaming “conspiracy”, I ask you to watch Jo’s video (Jo did you really not have anything with a better capture? My old Nikon P50 had a better iris!) and notice that Secure Boot over there works just fine. Other than that, this “ultrabook” is not using SecureBoot because it’s not certified for Windows 8 anyway.

The problem is not that it requires Secure Boot or anything like that but much more simply, it has no legacy boot. Which is what I’m using on the other laptop (the Latitude E6510), since my first attempt at using EFI for booting failed badly. Anyway this simply meant that I had to figure out how to get this to boot.

What I knew from the previous attempt is this:

  • grub2 supports UEFI both 32- and 64-bit mode, which is good — both my systems run 64-bit EFI anyway;
  • grub2 requires efibootmgr to set up the boot environment;
  • efibootmg requires to have access to the EFI variables, so it requires a kernel with support for EFI variables;
  • but there is no way to access those variables when using legacy boot.

This chicken-and-egg problem is what blown it for me last time — I did try before the kernel added EFI Stub support anyway. So what did I do this time? Well, since Sabayon did not work out of the box I decided to scratch it and I went with good old fashioned Gentoo. And as usual to install it, I started from SysRescueCD — which to this day, as far as I can tell, still does not support booting as EFI either. It’s a good thing then that Asus actually supports legacy boot… from USB drives as well as CDs.

So I boot from SysRescueCD and partition the SSD in three parts: a 200MB, vfat EFI partition; a root-and-everything partition; and a /home partition. Note that I don’t split either /boot or /usr so I’m usually quite easy to please, in the boot process. The EFI partition I mount as /mnt/gentoo/boot/efi and inside it I create a EFI directory (it’s actually case-insensitive but I prefer keeping it uppercase anyway).

Now it’s time to configure and build the kernel — make sure to enable the EFI Stub support. Pre-configure the boot parameters in the kernel, make sure to not use any module for stuff you need during boot. This way you don’t have to care about an initrd at all. Build and install the kernel. Then copy /boot/vmlinuz-* as /boot/efi/EFI/kernel.efi — make sure to give it a .efi suffix otherwise it won’t work — the name you use now is not really important as you’ll only be using it once.

Now you need an EFI shell. The Zenbook requires the shell available somewhere, but I know that at least the device we use at work has some basic support for an internal shell in its firmware. The other Gentoo wiki has a link on where to download the file; just put it in the root of the SysRescueCD USB stick. Then you can select to boot it from the “BIOS” configuration screen, which is what you’ll get after a reboot.

At this point, you just need to execute the kernel stub: FS1:EFIkernel.efi will be enough for it to start. After the boot completed, you’re now in an EFI-capable kernel, booted in EFI mode. And the only thing that you’re left to do is grub-install --efi-directory=/boot/grub/efi. And .. you’re done!

When you reboot, grub2 will start in EFI mode, boot your kernel, and be done with it. Pretty painless, isn’t it?

7 thoughts on “UEFI booting

  1. @SysRescueCD not supporting booting as UEFI: I installed last month an Asus based system (E35M1-I DELUXE) using SystemRescueCd on an USB stick. At least in that mode, it supported UEFI booting. I was only required to select the UEFI boot entry manually as by default the board would boot the USB stick in legacy mode (UEFI boot entries were prefixed with the string “UEFI: “). Also I had to fix some paths in the grub menu entries. So as long as SysRescueCD is the same as the SystemRescueCd (http://www.sysresccd.org/), I can confirm that it boots and works in UEFI mode!As far as I remember, the Gentoo Minimal CD didn’t support UEFI (or that support was being lost when putting it on the USB stick), that’s why I tried the SystemRescueCd.On an unrelated note: I make use of the UEFI boot manager and let UEFI boot the kernel directly (http://www.rodsbooks.com/ef…. Works for me (although I only run it in headless mode so no guarantee that e.g. the GPU is working as expected).

    Like

  2. Hi Diego, when you install Grub2 or the kernel STUB method, it’s not required to run the EFI shell.Indeed, you can use the efibootmgr directly to add your entry inside the EFI NVRAM.This FS1:EFIkernel.efi commandcan be replace by this :# efibootmgr –create –gpt –disk /dev/sda –part 1 –write-signature –label “Kernel” –loader “\EFI\KERNEL.EFI”Right now, it seems that we can install a bootmanager with 4 methods :1. With the EFI shell2. With the efibootmgr manually3. Automagically with Grub2 if you are lucky.4. Use the BOOTX64.EFI and don’t bother with all the NVRAM stuff

    Like

  3. Jean-Marc, indeed I had an outdated SysRescueCD that I was under the impression was updated instead. I’ll try again with the new version this weekend as I intend to convert the Latitude to UEFI boot as well.Sylvain, the problem is that you can’t use efibootmgr if you’re not booting as EFI — and in that case you’re in the chicken-and-egg problem I described, which is easy to break if you use the shell and an EFI-stub capable kernel.

    Like

  4. Hi Diego, about your last comment :I know that about the chiken-and-egg problem, but you don’t have to do that(shell + kernel stub before you install your /boot/efi directory for real) , because the latest SystemRescueCD can boot your box in UEFI mode. So, basically you only need to do this :1. Make sure that your UEFI motherboard boots your LiveCD in UEFI mode. On a Intel motherboard, you hit F10 to change your uefi/bios boot method for a specific drive.2. mount your partition as usual 3. mount -o bind /sys /mnt/gentoo/sys4. chrootAfter that, the directory that efibootmgr needs will be there and also valid :/sys/firmware/efiSo, this weekend if you have the time,try that do and give us some feedback :PFinally, I saw on the Gentoo forum that the rEFIt is really simple and can do the job too if you don’t want to use Grub2.

    Like

  5. I’ve given up trying to use UEFI booting and reverted to using MBR. I did once get it working after studying the Arch Linux wiki for hours and banging my head against the wall, but never again. I really hate UEFI. Sure, the GUI BIOS screens are nice, but why did they make it so hard to boot the OS? Why couldn’t they just implement something like GRUB in the BIOS (just specify the partition and kernel file).

    Like

  6. Because this is actually possible, with UEFI. I think you’re conflating a wide number of very different things.Graphical setup screens have existed in the time of BIOS just as well as UEFI — it’s just a bit more complex to do that since you have to maintain your whole stack, but it’s by far not impossible. The point of UEFI is not there, but rather it’s in the ability to actually use a standard interface across a wider range of hardware, for graphical access (you don’t want to keep using VBE, trust me), and other similar things.Now, of the two laptops I wrote about, the Asus has actually a non-graphical setup mode that is more like an old style BIOS than anything else. The Dell instead has a fully graphical interface, with mouse and everything (and it’s actually the older of the two.Both of them though have a way to define the boot variables from the setup itself, it’s just that I didn’t know how to do that before; now after actually getting it to work with Grub, it’s pretty easy to do. So if you write your own kernel install script that uses two fixed paths for “current kernel” and “old kernel”, setting it up without having to use Grub and just going through the stub is dead easy.

    Like

  7. So, the capture. I have a very shaky hand, and no tripod, so I couldn’t use a camera – had to use a webcam. I stole the wife’s, a Logitech G310, and it worked out of the box in both Linux and Windows. However, every capture option on Linux was terribad (couldn’t capture video from the webcam and audio from my headset successfully with any proposed solution), and half the Windows apps were terrible too. In the end resorted to Windows Movie Maker, which I couldn’t work out how to force to capture in HD. And the lighting conditions weren’t great due to the lack of natural light, what with it being 1AM.

    Like

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 )

w

Connecting to %s