Gentoo and UEFI


This is a guide to help with the initial setup and install of Gentoo on a fairly recent PC with UEFI. This is not a replacement for the official Gentoo Handbook. With that in mind, I have made a few assumptions:

  1. You know what Gentoo is and what you are getting yourself into,
  2. You have a 64-bit PC (or Mac) with UEFI support and want to boot from UEFI mode into Gentoo, and
  3. You have free space available on one of your hard drives for a small ~100MB partition and said drive is formatted as GPT (not MBR).

It may be possible to use this guide for 32-bit builds by substituting all references to 64 with 32. However, you may want to confirm this through the use of the linux man pages and google searches for the appropriate commands.
Also, this guide may be followed, unaltered, for Macs. Was tested on a MacBook Air (2011) and may work equally as well on others.

Step 1: Booting from UEFI

Gentoo uses syslinux and a non-UEFI compatible Grub2 boot loader. So, before we can begin anything, we need UEFI bootable media and the easiest way of doing this is to download a live Fedora 16 disk image, burn it and boot it, in UEFI mode of course. All the required information on how to do this is on Fedora’s website. Follow their documentation for creating a disk image in your format of choice (i.e. USB, DVD etc) and once booted from UEFI into Gnome 3 (Fedora’s default desktop) continue with Step 2.

I strongly recommend that you use a windows system and the Fedora Live USB Creator program as it preserves and properly creates the EFI info on the USB drive.

Step 2: Creating the Partitions

If you already boot from UEFI (i.e. Windows 7) there will be a FAT32 EFI partition on one of your hard drives and there will be no need to create another.

For example, the output of parted:

Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: Linux Software RAID Array (md)
Disk /dev/md126: 456GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start  End   Size  File system Name                         Flags
1      1049kB 106MB 105MB fat32       EFI System Partition         boot
2      106MB  240MB 134MB             Microsoft reserved partition msftres
3      240MB  456GB 456GB ntfs        Basic data partition

If you need to create the EFI partition (where sdX, START, END, and sdXn are specific to your installation):

parted /dev/sdX
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) gpt
(parted) primary fat32 START END
(parted) set 1 boot on
(parted) q
mkfs.vfat /dev/sdXn

Ensure the EFI partition is the first partition (i.e. partition 1 as displayed in parted).

For the system disk partitions, you can go classic (ext4) or advanced (lvm). Whatever your choice, a sufficiently large boot partition formatted as ext2-4 is required–important, the boot partition should be one of ext2-4, otherwise Grub2 may not find it and will not be able to boot your kernel nor will Grub2 be able to find it’s own modules under the grub directory tree. It is also assumed that parted is being used and the drive(s) in question have been set as GPT (i.e. mktable gpt etc). Gentoo and others have an abundance of documentation for setting up system partitions in almost every conceivable way (google is your friend).

Step 3: Initial Stage 3 and Portage Snapshot

This step does not differ much from the official Gentoo Handbook, with the exception of booting from UEFI using a Fedora 16 live image. Basically, all the steps that would normally be performed from a Gentoo console and Gentoo boot disk, are performed from a Gnome 3 terminal in Fedora.

The advantage here is access to UEFI, multiple terminal windows, Firefox (rather than links) and easy network setup (required for stage3, portage, emerge etc).

So, connect to your network using the Gnome 3 graphical network manager utility. Make the gentoo directory from a console and mount it:

mkdir /mnt/gentoo
mount /dev/sdXn /mnt/gentoo

Download (to /mnt/gentoo/) a stage3 and snapshot tarball following the appropriate mirrors: And essentially, use the official Gentoo Handbook up to the kernel section with one exception:

When linking proc and dev to your gentoo rootfs, just before chroot’ing, be sure to:

mount -t sysfs /sys /mnt/gentoo/sys
mount /dev/sdXn /mnt/gentoo/boot/efi

before you:

chroot /mnt/gentoo /bin/bash

Afterwords, return here and continue with Step 4 for some special options that must be built into the kernel. Also, because we have booted from a non-gentoo install disk mirrorselect will not exist and thus mirrors will need to be entered manually into your make.conf.

You may use the following as a template for your mirrors and rsync:


Step 4: Kernel Configuration

At this point you should be chroot’ed into a full Gentoo rootfs environment by following the Gentoo Handbook.

Setup your kernel as per normal making sure to enable the following:

Processor type and features  --->
    [*] EFI runtime service support
    [*] Build a relocatable kernel
Device Drivers  --->
    Graphics support --->
        <*> Support for frame buffer devices  --->
            [*]   Enable firmware EDID
            [*]   EFI-based Framebuffer Support
    Console display driver support  --->
        <*> Framebuffer Console support
Firmware Drivers  --->
    <*> EFI Variable Support via sysfs
File systems  --->
    Partition Types  --->
        [*] Advanced partition selection
        [*]   EFI GUID Partition support

The EFI-based frame buffer overrides all other frame buffer drivers, so don’t bother including any (VESA fb, UVESA fb etc.). See Step 5 for an example /etc/default/grub. After compiling and installing the kernel and initramfs (for frame buffer support), continue with Step 5.

Step 5: Grub2 x86_64-efi

Before we can emerge grub, there are a few things we need to take care of.

First, make.conf requires GRUB_PLATFORMS=”efi-64″:

echo "GRUB_PLATFORMS=\"efi-64\"" >> /etc/make.conf

Next, unmask grub and enable required keywords:

echo "sys-boot/grub" >> /etc/portage/package.unmask
echo "=sys-boot/efibootmgr-0.5.4 ~amd64" >> /etc/portage/package.accept_keywords
echo "=sys-boot/grub-9999 **" >> /etc/portage/package.accept_keywords

And finally, we are ready to emerge grub:

emerge grub:2

If you plan to use fbcondecor etc. you will want to modify the default /etc/default/grub file. Here is an example of the variables that need changing:

GRUB_CMDLINE_LINUX_DEFAULT="dolvm rootfstype=ext4 ro splash=silent,theme:natural_gentoo console=tty1 quiet"
# The following is only needed if you wish to use the default grub theme

Now, install grub to the efi and boot partitions:

grub2-install --target=x86_64-efi --modules="part_gpt part_msdos linux normal boot all_video chain efi_gop video video_fb gzio ls lvm" --efi-directory=/boot/efi /dev/sdXn
grub2-mkconfig -o /boot/grub2/grub.cfg

The –modules option is not necessary and can in-fact be included in the /etc/default/grub file instead. Although, I would recommend adding at least what I have listed as a failsafe incase grub cannot find your boot partition on startup.

Step 6: Check and Verify

To check and verify your Grub2 installation enter the following:

efibootmgr -v

Which should print out something similar to:

BootCurrent: 0002
Timeout: 1 seconds
BootOrder: 0002,0000,0001,0003
Boot0000* Windows Boot Manager  HD(1,800,32000,4333eaa4-5031-4ed5-9798-9e3acc16db5e)File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.}...a................
Boot0001* Hard Drive    BIOS(2,0,00)AMGOAMNO........_.I.n.t.e.l. .V.o.l.u.m.e.0.........................rN.D+..,.\...........0..Gd-.;.A..MQ..L.I.n.t.e.l. .V.o.l.u.m.e.0......AMBOAMNO........s.H.i.t.a.c.h.i. .H.D.S.5.C.,.\...........D..Gd-.;.A..MQ..L.H.i.t.a.c.h.i. .H.D.S.5.C. .R.a.i.d. .V.D. .0.........................rN.D+..,.\...........8..Gd-.;.A..MQ..L.M.A.R.V.E.L.L. .R.a.i.d. .V.D. .0......AMBO
Boot0002* gentoo        HD(1,800,32000,4333eaa4-5031-4ed5-9798-9e3acc16db5e)File(\EFI\gentoo\grubx64.efi)
Boot0003  CD/DVD Drive  BIOS(3,0,00)AMGOAMNO........o.H.L.-.D.T.-.S.T. .B.D.D.V.D.R.W. .C.H.1.2.L.S.2.8....................A...........................>..Gd-.;.A..MQ..L.9.K.B.2.P. .4. . . . . . . . ......AMBO

Grub2 with UEFI support is now configured, installed and ready to boot your Gentoo install. Once you reboot, after you have followed the rest of the Gentoo Handbook and emerged all required and optional packages you should be greeted by the new Grub2 menu and be able to boot into Gentoo from UEFI.

If grub displays an unusual repetitive character (i.e. ??????), then it has not correctly copied over any fonts into the /boot/grub2/fonts directory. Correct this by copying from /usr/share/grub/*.pf2 to /boot/grub2/fonts:

cp /usr/share/grub/*.pf2 /boot/grub2/fonts/


I find Grub2 extremely stable and reliable as of this writing and have it installed with the default starfield theme and loading Gentoo with fbcondecor for console splash etc.. The location of the EFI FAT32 partition is of little consequence and can be located on any drive, array etc. as long as your motherboard can see it.

The linux boot partition is somewhat limited and is best left as a traditionally formatted ext2-4 partition (otherwise, some effort will be required to determine which grub modules must be loaded to find your boot partition).

The bottom-line is grub installs neatly beside a Microsoft EFI install on the same partition, or as a standalone and is ready for deployment as far as I can tell. Therefore, it should not be long before we start seeing Grub2 with UEFI support automagically installed from all major distros. But until then…

Good luck!

This entry was posted in Gentoo, Linux and tagged , , , , . Bookmark the permalink.

12 Responses to Gentoo and UEFI

  1. lari says:

    95% of your guide worked me !!!

    The 5% ?
    It should be stressed that one must boot up in UEFI mode (F8 on Asus P8P67 MB), I uses Sysresccd 3.0.0.beta. This then gives the usual menu from which you can make your selection.

    Please note:
    grub2-mkconfig -o /boot/grub2/grub.cfg

    Had to do:

    grub2-mkconfig -o /boot/efi/EFI/GRUB2/grub.cfg

    My set up is GPT / 2 x (SSD + HD) in Raid 1/ EF02 part on each SSD.

  2. Hi,
    At this time there’s no need to unmask grub.

    Only things necessary is:
    echo “=sys-boot/efibootmgr-0.5.4 ~amd64” >> /etc/portage/package.accept_keywords
    echo “=sys-boot/grub-2.0.0-r1 ~amd64” >> /etc/portage/package.accept_keywords

    anyway i prefer to do:
    echo “sys-boot/efibootmgr ~amd64” >> /etc/portage/package.accept_keywords
    echo “sys-boot/grub ~amd64” >> /etc/portage/package.accept_keywords

    just to keep rules valid for future versions.

  3. Oscar Medina says:

    Hi all,

    Does anybody understand the part where says:
    # mount /dev/sdXn /mnt/gentoo/boot/efi

    I already have FAT32 EFI partition, it’s /dev/sda1 made by windows 7 64, so, as I udertand I’ll mount the partition this way:

    # mount /dev/sda1 /mnt/gentoo/boot/efi

    but, what happen with the following:

    Reading “4.f. Mounting” from “Gentoo Handbook”, I saw the following:

    What will happen with this?
    Code Listing 6.1: Mounting partitions
    —-> # mkdir /mnt/gentoo/boot
    —-> # mount /dev/sda1 /mnt/gentoo/boot

    My understand is that I need two partitions, one of them I already have it (/dev/sda1), but Do I need another one (e.g. /dev/sda4) to mount it in /mnt/gentoo/boot:

    # mount /dev/sda1 /mnt/gentoo/boot/efi
    # mount /dev/sda1 /mnt/gentoo/boot

    Is this correct?

    I’m a little confused, Could anybody help me with this?


    • Hello Oscar,

      It has been a while since I have fiddled with efi and Gentoo. However, what you suggest sounds correct and makes perfect sense. If memory serves, it is exactly what I had done in the past.

      • Oscar Medina says:

        Thanks a lot Cristopher,

        But I had a mistake 😛 :

        /* My understand is that I need two partitions, one of them I already have it (/dev/sda1), * ** but Do I need another one (e.g. /dev/sda4) to mount it in /mnt/gentoo/boot: **

        # mount /dev/sda1 /mnt/gentoo/boot/efi
        # mount /dev/sda4 /mnt/gentoo/boot

        Do you think that the configuration above are correct?

      • The boot directory does not have to be on a separate partition. Although, the following is typical:

        (#1) /dev/sda1 /mnt/gentoo/boot/efi
        (#2) /dev/sda2 /mnt/gentoo/boot
        (#3) /dev/sda3 /mnt/gentoo

        #2 is optional, whereas #1 and #3 are mandatory (match your partition numbers to your configuration)

        Hope that answers your question.

  4. Kyle says:

    Thank you or writing this guide, I haven’t had a chance to test it out yet, but I have been searching for information about gentoo and UEFI. I’m trying to dual boot with Windows 8 on my laptop and was having trouble finding decent information. Perhaps you should see about getting this guide on gentoo’s website?

  5. Raydude says:

    I wasn’t able to get grub dual booting with windows 8, but this howto worked for me:

  6. Henrique says:

    Is the EFI /boot partition supposed to be FAT32 or EXT2-4? It is not very clear… The example and any other guide says FAT32, yet to remind us that GRUB2 will only work on EXT2-4 partitions…

    • The EFI partition needs to be FAT32, while the boot/root need to be any Linux compatible format (ext3, jfs etc)
      All EFI partitions on all platforms are FAT32 and grub2 has no problem handling it.

      Hope this helps.

  7. AFUMEX says:

    Mmm… I’m a bit confused reading this guide and also the comments regarding mounting partitions… I feel sorry of asking maybe again same things that had been already asked/explained.
    Why should I mount the same partition (/dev/sdXn) in two different paths? I mean, in your useful guide you just say
    “mkdir /mnt/gentoo
    mount /dev/sdXn /mnt/gentoo”
    Here I understand to mount the partition (eg.: /dev/sda4) that will be the root of Gentoo, am I right?

    Then you continue with:
    “mount -t sysfs /sys /mnt/gentoo/sys
    mount /dev/sdXn /mnt/gentoo/boot/efi”
    Again /dev/sdXn… But I already have an ESP FAT32 partition on /dev/sda1: so in this step I’ll use:
    mount /dev/sda1 /mnt/gentoo/boot/efi

    Let me knon if I understood well theese 2 step. Am I right?
    Thanks! 🙂

  8. Perhaps you can help me with my problems. I’ve been unable to get the Gentoo kernel to work at all with EFI. Kernel configurations have changed since this post was made, now that we are on Linux 4.2 today. As far as I’m aware, everything is enabled that is needed. However, even if I copy the Arch Linux kernel configuration, which enables everything a module, I cannot get the Gentoo kernel that is compiled to boot. Upon attempting to boot, I’m simply left with ‘Failed /vmlinuz-gentoo-version Unsupported’.

    Now, if I use GRUB, I actually can get the kernel to boot, but it is unable to mount the EFI partition, remarking that vfat isn’t a recognized filesystem, which is puzzling because VFAT is enabled and built into the kernel, and I’ve made sure it’s configured by checking the .config file produced by menuconfig.


    However, if I copy /lib/modules from my Arch partition and edit the gentoo entry in gummiboot to use Arch Linux’s kernel, everything works perfectly, so there must be some sort of configuration problem, although it’s strange that even the Arch Linux kernel configuration gives the same problem.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s