UEFI Gentoo Quick Install Guide

From Gentoo Wiki
Jump to: navigation, search

Gentoo doesn't officially support UEFI, but it is not hard to install gentoo onto an UEFI system. To do this you will need to basically follow the installation handbook of your architecture. The first place you will diverge from the guide is the partition setup.

UEFI doesn't use MBR (Master Boot Record), so you'll need to create a GPT partition table. UEFI works by reading an .efi file in a FAT32 partition, that you will need to create and upon which you will mount /boot.

Here is how I created my partitions.

root # parted /dev/sda
(parted) mkpart ESI fat32 0% 500m
(parted)
mkpart primary ext4 500m 100%
(parted)
set 1 boot on
(parted)
quit
Note
The mkpart commands shown here ensure proper alignment on SSD drives; change them at your own risk. You may use the 'align-check' parted command to verify partition alignment.
Note
The boot flag parted sets for a GPT partition is NOT the same thing as the bootable flag in a master boot record (MBR). It is confusing that parted choose to use a similar name, but the flags are different. Setting the boot flag by parted in an MBR partition marks that partition bootable, while in a GPT partition the boot flag indicates the EFI System Partition (ESI). Also note that ESI is not a typo.
root # mkfs.vfat -F 32 /dev/sda1
root #
mkfs.ext4 /dev/sda2

Now continue along with the install guide.

For the kernel configuration, make sure you specify the kernel options mentioned here: EFI stub kernel

Here are my steps:

root # cd /usr/src/linux
root #
make menuconfig
root #
make modules_install
root #
mkdir /boot
root #
mount /dev/sda1 /boot
root #
mkdir -p /boot/efi/boot
root #
cp /usr/src/linux/arch/x86/boot/bzImage /boot/efi/boot/bootx64.efi
root #
emerge efibootmgr
Note
You can also copy bzImage from arch/x86_64/boot/bzImage.

Now the tricky part. You need to tell the UEFI Firmware about your new bootx64.efi, to do this you will use a tool called efibootmgr, but also you need to have booted the system WITH UEFI.

So you can grab any linux distribution that support boot in UEFI mode, and do the work. Another option that does work, is if you stick your new bootx64.efi file on a USB flash stick, the laptop will automatically find that and boot it.

So insert a USB stick, we'll pretend it comes up as /dev/sdd in the following code:

root # parted /dev/sdd
(parted) mklabel gpt
(parted)
mkpart esi fat32 0% 500m
(parted)
set 1 boot on
(parted)
quit
root # mkfs.vfat -F 32 /dev/sdd1
root #
mkdir /mnt/tmp && mount /dev/sdd1 /mnt/tmp
root #
mkdir -p /mnt/tmp/efi/boot
root #
cp arch/x86/boot/bzImage /mnt/tmp/efi/boot/bootx64.efi
root #
umount /mnt/tmp

Now reboot the box and hit F2 (or whatever) to enter the UEFI Firmware Boot Menu on boot.

In the UEFI list, choose to boot the new USB flash stick that should be showing up.

The kernel should load up and boot your sytem.

Make sure efivars kernel module is loaded:

root # modprobe efivars

Now you can tell the UEFI Firmware about your bootx64.efi that is on the hard drive:

root # efibootmgr -c -d /dev/sda -p 1 -L Gentoo -l "\efi\boot\bootx64.efi"
root #
reboot

Now enter the UEFI Firmware Boot Menu again and you should see "Gentoo" in the list!

Congrats, it should now boot!