Overview
Gentoo is a Linux distribution built from source that emphasizes versatility, performance, and customizability. Installing Gentoo entails compiling key components like the Linux kernel and optimizing the system for your specific hardware.
In this comprehensive guide, we will walk through installing Gentoo step-by-step in a VirtualBox virtual machine (VM). We will cover:
- Downloading the Gentoo installation media and creating a VM
- Partitioning the virtual disk
- Configuring the network and updating Portage
- Compiling a custom Linux kernel
- Installing a graphical environment
- Configuring system services
By the end, you will have a fully fledged Gentoo Linux installation in VirtualBox ready for further customization and tweaking.
Step 1 – Download Gentoo and Create a Virtual Machine
First, download the Gentoo minimal install ISO from https://www.gentoo.org/downloads/. Select the amd64 architecture ISO as it offers the best compatibility.
Next, create a new VirtualBox virtual machine with the following recommended settings:
- Type: Linux
- Version: Gentoo (64-bit)
- Memory Size: At least 2048 MB
- Virtual Disk: Dynamically expanding storage, 32 GB
With the VM created, go to the Settings > Storage section. Under Controller IDE, select the Gentoo ISO you downloaded as the virtual optical disk drive.
Boot your VM. You should be greeted with the Gentoo Installer boot menu. Select Install Gentoo to launch the graphical installation wizard. This will guide you through installing Gentoo onto your virtual disk.
Step 2 – Partition the Disk
When you reach the partitioning section of the installer, you will need to partition your virtual disk.
The recommended partitioning scheme is:
/dev/sda1– 500 MB boot partition/dev/sda2– 32 GB root partition for OS files/dev/sda3– 4 GB swap partition for virtual memory
To create this layout, select Manual partitioning then use the tool provided to create the partitions above. Format the boot partition as ext2 and the root partition as ext4. For the swap partition, set the type to Linux swap.
With partitioning complete, continue through the installation wizard until Stage 3 extraction begins. This will install the base Gentoo system onto your setup partitions.
Step 3 – Configure Networking
After extraction finishes, you will be dropped to a chroot terminal in the new Gentoo environment. The first task here is networking configuration.
Run nano -w /etc/conf.d/net and set config_enp0s3="dhcp" to enable DHCP on the VM‘s network interface. This will retrieve an IP automatically.
Then edit /etc/resolv.conf and add your nameservers:
nameserver 1.1.1.1
nameserver 8.8.8.8
Check connectivity with ping google.com.
Step 4 – Update Portage Tree
Portage is the Gentoo package manager that compiles apps from source. It relies on the Portage tree which contains software profiles and ebuilds.
To update the tree, run:
emerge --sync
Next, select your system profile with:
eselect profile list
eselect profile set <number>
The default desktop profile is a good starting point.
Step 5 – Compile the Kernel
With the base system installed, it‘s now time to compile a custom Linux kernel optimized for your system.
Begin by emerging the kernel sources:
emerge sys-kernel/gentoo-sources
Then install genkernel to automatically build the kernel:
emerge sys-kernel/genkernel
Now compile the kernel with genkernel all. This will take some time depending on your system specs.
genkernel all
After it finishes, you can find your custom kernel files in /boot.
Step 6 – Install a Graphical Environment
By default, Gentoo boots to a basic CLI. To add a graphical desktop environment, we will install the KDE Plasma DE.
First emerge the meta-package with necessary dependencies:
emerge kde-plasma/plasma-meta
Then install a display server – either Xorg or Wayland:
emerge x11-base/xorg-server
emerge x11-base/xorg-drivers
Or
emerge gui-libs/wayland
Setup the display manager to launch KDE automatically on boot:
rc-update add sddm default
Finally, enable resolution and keyboard layout settings with nano /etc/conf.d/udev:
udev_config="keymap keyboard layout"
udev_config+=" i8042.kbdreset i8042.nomux i8042.nopnp i8042.dumbkbd"
Reboot and you should now have the KDE Plasma desktop environment once logged in!
Step 7 – System Services
Some final setup steps for core services:
Add a local admin user:
useradd -mG wheel,users <username>
passwd <username>
Enable sudo access:
EDITOR=nano visudo
Uncomment %wheel ALL=(ALL) ALL
Install a DHCP client:
emerge dhcpcd
rc-update add dhcpcd default
Sync the clock:
emerge ntp
ntpd -qg
rc-update add ntpd default
Setup logging:
rc-update add syslog-ng default
rc-update add metalog default
Conclusion
After following this guide step-by-step, you now have a fully working Gentoo Linux installation customized to your preferences in VirtualBox!
The powerful Portage packages manager allows you to continuously tweak, upgrade, and optimize components like the kernel, compiler flags, and applications. Since Gentoo compiles everything from source code, it is a highly versatile and lightweight distro focused on performance.
Some additional ideas as you continue using Gentoo:
- Experiment with different kernel configurations
- Emerge various desktop environments like GNOME or MATE
- Optimize compilation flags in
make.conf - Install hardware drivers for graphics, audio, etc
- Set up disk encryption, firewalls, containerization
I hope this guide was helpful as an introduction to installing Gentoo in VirtualBox. Let me know if you have any other topics related to Gentoo that you would like covered!


