Gentoo Linux Installed on VirtualBox with UEFI firmware

I haven’t written many blogs since life has taken it’s course, and I figured I’d at least share one thing I know will help maybe one or two people out there.  After fighting with documentation and information, I recently successfully installed Gentoo Linux with UEFI (EFI) firmware on VirtualBox.  Not that documentation isn’t out there, it’s just that the main documentation is so outdated and didn’t handle UEFI properly as well.  So, without time wasted, I will share my line-by-line notes/self-documentation which I did because I suck at remembering things that I don’t do regularly 😉

Prerequisites: Make sure you have a VM setup for Linux, and I’d say above 2G ram and disk space above 10G.  Also, for the sake of the install, set the network adapter to “Bridged Adapter” connected to your internet-connected adapter on the host.  Make sure your VirtualBox VM is configured for EFI.  Even though VirtualBox has cautions about it being for “special OS’es”, it’s not so much the case in todays world any longer.  You can do it through the GUI in “Settings -> System -> Motherboard” at the bottom selecting a button underneath “Extended Features” named “Enable EFI (Special OSes only)”.
You can also do it through the commandline with ‘VBoxManage modifyvm “VM-Name” —firmware efi64’ (Changing VM-Name to the VM’s name in VirtualBox)
  • Boot the cd, choose advanced options, then pick console, then let it boot
  • To ssh in for a comfy install, do “/etc/init.d/sshd start && passwd root” and set roots password (temporarily), run ifconfig to find the IP then ssh into that IP as root.
  • Create the partitions:
    • gdisk /dev/sda
      • Creates GPT partition table:
      • Command: o
        • Proceed?: y
      • Creates partition 1 (/boot)
      • Command: n
        • Partition Number: 1
          • First Sector: <return>
          • Last sector: +128M
          • Hex Code: <return>
      • Creates partition 2 (UEFI ESP)
      • Command: n
        • Partition Number: 2
          • First sector:<return>
          • Last Sector: +32M
          • Hex Code: EF00
      • Creates partition 3 (swap)
        • Command: n
          • Partition Number: 3
          • First sector:<return>
          • Last sector: +1024M
          • Hex code: 8200
      • Creates partition 4 (/)
        • Command: n
          • Partition number: 4
          • First sector:<return>
          • Last sector: <return>
          • Hex code: <return>
      • Write partition table to disk
        • Command: w
        • Proceed?: y
  • mkdir -p /mnt/gentoo
  • mount /dev/sda4 /mnt/gentoo
  • mkdir /mnt/gentoo/boot
  • mount /dev/sda1 /mnt/gentoo/boot
  • mkdir /mnt/gentoo/boot/efi
  • mount /dev/sda2 /mnt/gentoo/boot/efi
  • cd /mnt/gentoo
  • Grab the latest stage3-amd64-* tarball
  • tar xpf stage3-amd64*
  • mount -t proc none proc
  • mount —rbind /sys sys
  • mount —make-rslave sys
  • Mount —rbind /dev dev
  • mount —make-rslave dev
  • cp /etc/resolv.conf etc
  • chroot . /bin/bash
  • source /etc/profile
  • emerge-webrsync
  • passwd
  • useradd -g users -G wheel,portage,audio,video,usb,cdrom -m <userid you’d like>
  • passwd <userid you picked above>
  • emerge -vp vim
  • Create /etc/fstab with the following
      • /dev/sda1 /boot ext4 no auto,noatime 1 2
      • /dev/sda2 /boot/efi vfat defaults 0 0
      • /dev/sda3 none swap sw 0 0
      • /dev/sda4 / ext4 noatime 0 1
      • /dev/cdrom /mnt/cdrom auto noauto,ro 0 0
  • Edit /etc/portage/make.conf
    • Add in the line: USE=“-X”
  • Edit /etc/locale.gen
    • Uncomment “en_US” along with “en_US.UTF-8
  • Edit /etc/conf.d/hostname
    • Change “localhost” to your hostname: hostname=“localhost”
  • Edit /etc/conf.d/net
    • Add in the following, changing “domain.com” to your domain name 
      • dns_domain_lo=“domain.com”
  • ln -sf /usr/share/zoneinfo/US/Arizona /etc/localtime
  • emerge -av sys-kernel/gentoo-sources
  • cd /usr/src/linux
  • make menuconfig
    Below are kernel configuration options to enable within menuconfig.
    The lines with “Activate blah blah blah” are for people who want the variable names to find in the configuration files instead of manually choosing.

    • Activate CONFIG_DEVTMPFS and CONFIG_DEVTMPFS_MOUNT
      • Enabling devtmpfs support
        • Device drivers —>
          • Generic Driver Options —>
            • [*] Maintain a devtmpfs filesystem to mount at /dev
            • [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs
    • Activate CONFIG_BLK_DEV_SD
      • Enabling SCSI disk support
        • Device Drivers —>
          • SCSI device support —>
            • <*> SCSI disk support
    • Activate CONFIG_EXT2_FSCONFIG_EXT3_FSCONFIG_EXT4_FSCONFIG_MSDOS_FSCONFIG_VFAT_FSCONFIG_PROC_FS, and CONFIG_TMPFS
      • File systems —>
        • <*> Second extended fs support
        • <*> The Extended 3 (ext3) filesystem
        • <*> The Extended 4 (ext4) filesystem
        • <*> Reiserfs support
        • <*> JFS filesystem support
        • <*> XFS filesystem support
        • <*> Btrfs filesystem support
        • DOS/FAT/NT Filesystems —>
          • <*> MSDOS fs support
          • <*> VFAT (Windows-95) fs support
      • Pseudo Filesystems —>
        • [*] /proc file system support
        • [*] Tmpfs virtual memory file system support ( former shm fs )
    • Activate CONFIG_SMP
      • Activating SMP support
        • Processor type and features —>
          • [*] Symmetric multi-processing support
    • Activate CONFIG_HID_GENERIC and CONFIG_USB_HIDCONFIG_USB_SUPPORTCONFIG_USB_XHCI_HCDCONFIG_USB_EHCI_HCDCONFIG_USB_OHCI_HCD
      • Activating USB support for input device
        • Device Drivers —>
          • HID support —>
            • -*- HID bus support
              • <*> Generic HID driver
              • [*] Battery level reporting for HID devices
                • USB HID support —>
                  • <*> USB HID transport layer
          • [*] USB support —>
            • <*> xHCI HCD (USB 3.0) support
            • <*> EHCI HCD (USB 2.0) support
            • <*> OHCI HCD (USB 1.1) support
    • Activating CONFIG_PARTITION_ADVANCED and CONFIG_EFI_PARTITION
      • Enable support for GPT
        • -*- Enable the block layer —>
          • Partition Types —>
            • [*] Advanced partition selection
            • [*] EFI GUID Partition support
    • Activating CONFIG_EFICONFIG_EFI_STUBCONFIG_EFI_MIXED, and CONFIG_EFI_VARS
      • Enable support for UEFI
        • Processor type and features —>
          • [*] EFI runtime service support
          • [*] EFI stub support
          • [*] EFI mixed-mode support
        • Firmware Drivers —>
          • EFI (Extensible Firmware Interface) Support —>
            • <*> EFI Variable Support via sysfs
  • make -j3 && make -j3 modules_install
  • make install
  • emerge —ask sys-boot/grub
  • grub-install –target=x86_64-efi –efi-directory=/boot/efi
  • grub-mkconfig -o /boot/grub/grub.cfg
  • emerge –ask sys-apps/iproute2 net-misc/dhcpcd
  • unmount all partitions and shutdown with “shutdown -h now
  • Start the VM again and once booted and hitting the UEFI shell, do the following
    • Type: “fs0:
    • Type: “edit startup.nsh” (this will be an interactive editor)
      • Add in: “\EFI\gentoo\grubx64.efi
      • Hit “ctrl-s<return><return>” to save
      • Hit: “ctrl-q<return>” to quit the editor
    • Type: “reset” to reboot.
  • Now, the UEFI 5-second delay will be there before booting Gentoo.  You’re done.

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.