Gentoo UEFI

From Gentoo Wiki
Jump to: navigation, search
This page has been nominated for deletion.

The given reason is:

Most if not all information in this article is covered in topic specific articles as there are:

Also Gentoo Hanbook cares for UEFI in several sections.

It is tedious to maintain redundant copies of information especially as there are always deviations that have to be compared in detail.

If you disagree with its deletion, do not remove this notice; discuss your objections on the associated discussion page.

Administrators, please remember to check if anything links here and the page history before deleting.

This notice should remain for a minimum of 1 month after it was placed on the page. If discussion is still ongoing it should remain until a consensus is reached, at which time the page may be deleted or this notice may be removed. (However, if the page has only been edited by the user who nominated it for deletion and/or is in the nominator's user space, then a speedy deletion may be called for.)
Article status
This article needs wikification.


The Unified Extensible Firmware Interface (UEFI) is a specification that defines a software Interface between an operating system and platform firmware.[1] Means it is a way to open up the old style BIOS so that more functionality can be added and used in today's computing going forward into the future. It can be simply understood in that the old BIOS used to just boot a MBR based bootable device and would just hand off the BIOS function to a specific address on the disk then execute it. With UEFI the MBR has been scrapped and now you have a extension which can hand itself off to just about anything from a shell to GRUB to multiple boot managers.

You must make sure that your hard disk drives use GPT tables only as using the old MBR will render your system un-bootable in UEFI mode. Compatibility mode (CSM) is also a bit hit and miss when using UEFI as boot managers all default to MBR legacy boot if it is available. Microsoft Windows particularly with it's auto-detection during installation will almost always choose a non UEFI install in BIOS Compatibility mode. This results in a Hybrid MBR/GPT layout which is not desirable if you want to use UEFI boot.

How it works(simply)

The UEFI system unlike the old BIOS which handed off to a specific location(address) in the start of the bootable media now executes files in a dedicated EFI System Partition (ESP) of type 0xEE. The UEFI looks for specific files with extension *.EFI in particular directory structure. Once it finds these files it will display them in your mainboards boot order screen. It does not stop there as you can modify this order within your OS as well as within the mainboards firmware or even the UEFI built in shell.

The most important thing to understand about this new system is that each hard disk drive that will require the firmware to execute a bootloader must have a FAT 0xEE ESP. So if you have Gentoo on one hard disk and another OS on a second hard disk then each disk will need a small FAT partition marked of type 0xEE. If you multi-boot on a single hard disk then only that disk will need one of these dedicated partitions in FAT to store the *.EFI files that can be executed once the mainboards firmware executes the one of your selection.

Common layout in Gentoo

We commonly layout this partition schema in Gentoo so that we have the BIOS /boot partition and then a /boot/efi mount point which is mounted to a small ESP to hold the *.EFI files that your mainboard UEFI can execute.

Device Mount Point Filesystem Description
/dev/sda1 not mounted (bootloader) BIOS boot partition
/dev/sda2 /boot/efi fat32 EFI System Partition (ESP) where the EFI files will be held to boot into the bootloader 0xEE
/dev/sda3 / ext4 root partition for your system

In case of EFI stub kernel, the kernels and initramfs files should be stored in the ESP. For sake of simplicity, the ESP can be used as the /boot partition itself instead of a separate /boot partition, for EFISTUB booting. In other words, after creating and formatting the ESP (...), simply mount it at /boot.[2]

The ESP can be anywhere on the disk start, middle, or end although it is best to put it at the start especially if your disk is a spinning disk type. The UEFI firmware will first search for the partition type(flag) and once found it will read the directory structure to find the *.EFI files. This is what you will see in your mainboard utility screen under the boot section.

File structure

See EFI System Partition


Using EFI stub kernel

See EFI stub kernel


See efibootmgr

See UEFI_Dual_boot_with_Windows_7/8

See rEFInd

You just need to remember if you want to boot an OS on a separate hard disk you must have also placed an ESP on that drive as well so that the GRUB configuration can find it.

As mentioned above multi-boot is not difficult in a UEFI system. All that is required is that the ESP contain the relevant EFI files for that OS to be selected for boot. Microsoft Windows is a problematic OS in that it does not want anything other than it's own EFI files to be populated in this partition and if you want to boot Windows you must install windows before you install another OS as it will detect your other OS and give you false misleading errors in the installation process.

As with the old BIOS MBR Windows never played nice and wanted the installation drive it was to be used on to be the master drive and the primary OS set in the BIOS or it would not install, well it is not any different for UEFI just adds more annoyance and complication as you need install Windows first then Gentoo afterwards. If you have Windows and Gentoo on two different drives and have HotSwap you can just pull your Gentoo Linux installed drive and after you install Windows you can return your Gentoo Linux drive and all is good.

Using GRUB



You need to mount the Windows ESP, assuming you have an installed Gentoo using UEFI and your /etc/fstab is setup correctly.

root #mount /boot
root #mount /boot/efi
root #mkdir /boot/winefi
root #mount /dev/"Partition sd* of windows FAT EFI" /boot/winefi

To add a section in the GRUB loader to boot windows is simple as before by adding this to the /etc/grub.d/40_custom

FILE /etc/grub.d/40_customGRUB 40 custom windows add
if [ "${grub_platform}" == "efi" ]; then
	menuentry "Microsoft Windows UEFI-GPT" {
		insmod part_gpt
		insmod fat
		insmod search_fs_uuid
		insmod chain
		search --fs-uuid --set=root $hints_string $fs_uuid
		chainloader /EFI/Microsoft/Boot/bootmgfw.efi

GRUB does not care what drive this is located on. It just searches for any and all partitions and if found then it will add it to your grub.cfg. The FAT filesystem containing the Microsoft *.EFI file must be mounted for GRUB to detect and add this custom menu selection so make sure to mount /boot and then /boot/efi and /boot/winefi

root #grub-mkconfig -o /boot/grub/grub.cfg

See also

External resources

For more information, please see: