UEFI

= Overview = The Extensible Firmware Interface (EFI), or its second-generation variant, Unified EFI (UEFI), is a replacement for the legacy BIOS in Itanium, x86, and x86_64 PCs. It is available on most motherboards introduced since early-to-mid 2011, although implementations vary:


 * The most primitive implementations, exemplified by Gigabyte's "Hybrid EFI," employ a standard old-style BIOS with a complete UEFI run as a module atop that. Marketing for such models typically downplays EFI features except for the ability to boot from an over-2TiB disk. Nonetheless, these boards do provide complete UEFI implementations; it's just that the basic hardware initialization is handled by BIOS code
 * Another step up involves an EFI implementation that's built from the ground up as such, using non-BIOS code to initialize the hardware but a text-mode user interface. Such computers often lack any mention of EFI or UEFI in their marketing, although their manuals usually include references to a small number of EFI features. This type of implementation can be difficult to distinguish from the previous type based on marketing information and manuals. The principal advantage over the previous type is that boot times can be shorter, since the BIOS-based hardware initialization of the previous type is inefficient.
 * The most sophisticated EFI implementations are built using non-BIOS hardware initialization code, UEFI features, and a flashy GUI for adjusting firmware settings. Examples include Asus' "UEFI BIOS" and MSI's "Click BIOS." Although these have "BIOS" in their names, they are not technically BIOSes, but retain that term so as to avoid confusion to the average user. From a performance perspective, these implementations don't differ from the previous type, but manufacturers want to advertize their products' GUIs and have adopted "UEFI" terminology to emphasize this new feature. Note that the GUI is not a requirement of EFI or UEFI.

Any of these variants, when booted in EFI mode, look identical to boot loaders and OSes, give or take any version number differences and bugs they may contain. (Bugs are a serious problem with the current crop of EFIs. The EFI code base is comparable in size to the Linux kernel without its drivers, and is much less well tested.)

All Macintoshes that use Intel CPUs are based on EFI 1.1, although Apple has been incorporating UEFI 2.x features into its firmware, so later models use a hybrid of EFI 1.1 and UEFI 2.x.

Most or all (U)EFI-based x86 and x86-64 computers include a Compatibility Support Module (CSM), which provides BIOS compatibility to enable older BIOS-based OSes to boot, even if the firmware is not based on a BIOS. If you use the firmware's CSM features, you can treat the computer just like a BIOS-based computer from the perspective of your boot loader and OS configuration. This wiki entry describes tools and techniques required to use the computer in its native EFI mode.

= Kernel Options = The frame buffer support is optional but if you don't select it consoles won't work

= File system support = EFI boots an operating system by reading an EFI program off the EFI System Partition (ESP) on the disk and running that program. Unfortunately most EFI implementations only support FAT, so your ESP will need to be FAT. The specification states that the ESP should be FAT32, and the Windows installer often misbehaves if the ESP uses FAT16, so using FAT32 is advisable for the ESP. Another thing you will want to do is prepare your disk using the new GUID partition table (GPT) system. GPT offers many advantages over the old Master Boot Record (MBR; aka DOS or BIOS) partition table including support for more than 4 partitions and +2TiB disk support. The old fdisk doesn't support GUID partitions but parted and gdisk do.

The optimum size of the ESP varies depending on the number of OSes you're installing and the Linux boot loader you choose to use. In particular, ELILO and the Linux kernel's built-in EFI stub loader both require that the Linux kernel and associated RAM disk be stored on the ESP, so you should size the ESP much as you'd size a separate Linux /boot partition (or larger) -- a minimum of 200 MiB, with 500 MiB being a more desirable size. If you use GRUB as your boot loader, the kernel can reside on a Linux partition, and the boot loader's needs are more modest, so 100-200 MiB may be a reasonable size. Making your ESP larger than necessary can increase your flexibility for future choices.

= Boot Managers and Boot Loaders =

BIOS boot loaders don't work on EFI systems (except in BIOS compatibility mode); however, some BIOS boot loaders are available in EFI variants. More so than on BIOS, it's important in EFI to distinguish between two related classes of programs:


 * Boot managers -- These programs enable users to select between two or more OSes or kernels, but they don't actually load the kernel. Many EFI implementations include a built-in boot manager, but this boot manager is sometimes primitive to the point of being useless. (Details vary from one EFI to another, though.)


 * Boot loaders -- These programs load a kernel and related files into memory and hand off control of the computer to the kernel.

The boot loaders with which Linux users are most familiar in the BIOS world (LILO, GRUB Legacy, and GRUB 2) all perform both of these tasks. Under EFI, though, the firmware often includes a primitive boot manager, and the design can make it desirable to separate the two functions, or at least to clearly distinguish between them.

Any EFI-enabled OS must include a boot loader, but boot manager functionality can be left to the firmware or to programs that aren't associated with any one OS.

The following boot manager and Linux boot loader programs are available, either in the Gentoo repository or elsewhere:


 * ELILO -- This boot loader is available as . It's similar to the BIOS LILO boot loader. ELILO can boot only Linux kernels; it cannot chainload to another boot loader. That is, it's a boot manager only for Linux installations.


 * GRUB Legacy -- Although GRUB Legacy doesn't officially support EFI, Fedora ships with a heavily modified version that includes EFI support. This version functions as both a boot manager and a boot loader.


 * GRUB 2 -- This program is both a boot manager and a boot loader, and is available in portage as.


 * The Linux kernel -- Since version 3.3.0 (and RC versions leading up to it), the Linux kernel has included code to enable it to function as an EFI application, effectively turning it into its own boot loader. You must enable the CONFIG_EFI_STUB option for this to work. As a practical matter, you need a separate boot manager to use this feature. If your EFI has a good enough boot manager, it may suffice; otherwise, you'll need to use another program for this purpose.


 * rEFIt -- You can obtain this boot manager from its Web site; however, the binary packages available there work only on Macs, not on UEFI-based PCs. rEFIt is impractical for booting a Linux kernel directly, even one with EFI stub loader support, because of limitations on the options it can pass to arbitrary EFI applications. It can be a useful tool for multi-booting on a Mac, though, and it can launch ELILO or GRUB.


 * rEFInd -- This boot manager, available from its Web site, is a fork of rEFIt with the goal of making it more useful on modern UEFI PCs and in multi-booting Linux. rEFInd can boot a Linux kernel with EFI stub support, or it can chainload another EFI boot loader.

= ELILO =

This boot loader is available as in portage; however, it's masked for x86 and x86-64 systems. (It's unmasked only for ia64.) Thus, you should unmask it by adding it to your file: {{Root| sys-boot/elilo }

Once you emerge ELILO, you must copy the elilo.efi binary file from /usr/lib/elilo to the ESP. You should place it in its own subdirectory of the EFI directory on the ESP. If your ESP is mounted at /boot/efi, this directory might be /boot/efi/EFI/elilo or /boot/efi/EFI/gentoo.

ELILO requires that the kernels and initial RAM disks that it boots be stored on a filesystem that the EFI can read, which in practice means they must be stored on the ESP. This has implications for the size of the ESP, as noted earlier.

ELILO's configuration file is elilo.conf, and is stored in the same directory on the ESP as the elilo.efi executable. Its format is similar to that of the older LILO file. An example looks like this:

elilo.conf

= GRUB =

Emerging
Legacy 1.0 does not support EFI, however  2.0 does. To do this you must unmask 2.0 by adding it to your  file:

You also want to build with EFI support. This can be simply done by adding to your file:

Installation
To install GRUB2 you can simply run command Grub 2 installtion GRUB2 no longer uses its old configuration file and will instead autogenerate the grub.cfg file for you by scanning your system(in /boot) for bootable kernels. You should also run this command whenever you build a new kernel to update your grub.cfg. Generate grub.conf

=efibootmgr= efibootmgr is a tool used to tell the EFI firmware the boot order and where on the disk to look for the boot loader.

Installation
Simply emerge efibootmgr Emerge efibootmgr

Setup
Make sure you're booted into a kernel which is using EFI and has the efivars modules built and loaded. If not take a look at the section. To use grub as our boot device use the command below Setting EFI to boot from GRUB This tells the EFI firmware that we have an EFI program for it to run on /dev/sda1 in grub2/grub.efi.

View the current boot order

Change the boot order

= EFI Shell = The EFI shell allows you to play around in the EFI without loading a specific program. I found it useful when I wanted to install Gentoo using EFI and couldn't find a bootable disk which had EFI support.

Installation
Download the latest EFI Shell x86_64(what you probably want) or x86. Place a copy of it on your EFI bootable partition which for most people should be and name it  if you are using the 64 bit version or  if you are using the 32 bit version.

Startup
To start the EFI shell go into your EFI firmware configuration(same way you would open your BIOS configuration). There should be an option in there to start the EFI Shell. For me its when I goto exit the EFI firmware configuration.

If you place the EFI shell in the EFI/tools directory on the ESP, using the filename shell.efi, rEFIt and rEFInd will auto-detect it and provide a menu option to launch it.

Use
You can use the EFI shell like any other shell although it seems to be much more DOS based then UNIX based.

Show all built-in shell commands

Switch to an EFI readable filesystem(replace X with the fs number)

List the contents of the current directory

Change directory