All HowTo's Linux Ubuntu, Mint & Debian Linux

Minimal Gentoo Installation…Fast

This post has now been updated (slightly) 05/01/16.

For more in depth installation details visit Gentoo Wiki

Download the latest install CD from your local mirror for example,
Internode File Mirror

Create a bootable USB using Rufus or Unetbootin and boot your machine from the USB drive.

When booting from the USB the Keyboard and Mouse should be detected by default, if you have issues with them not working then try toggling USB Legacy support in the BIOS.

Now that you are booted into a Gentoo environment you are going to want to check that your networking device is enabled and has an address as we will need it during the install.
Some commands to help with this are

ifconfig
ifconfig | grep inet
dhclient -r ; dhclient

Once your network is up and running we can proceed to partitioning the disk, use lsblk to find which disk is correct in your case and replace sda below.

lsblk
parted -a optimal /dev/sda
mklabel gpt
unit MB
mkpart primary 1 20
name 1 grub
set 1 bios_grub on
#
mkpart primary 21 500
name 2 boot
#
mkpart primary 501 1501
name 3 swap
#
mkpart primary 1502 -1
name 4 root
#
quit

Make the file systems on the new partitions, adjust the file system choices before hitting enter if needed.

mkfs.ext2 /dev/sda2 ; mkfs.ext4 /dev/sda4 ; mkswap /dev/sda3 ; swapon /dev/sda3

Mount the new partitions to /mnt/gentoo

mount /dev/sda4 /mnt/gentoo ; mkdir /mnt/gentoo/boot ; mount /dev/sda2 /mnt/gentoo/boot

Now make sure that the date is set correctly so that you will be able to download the required files, remembering that it will be in UTC time not local time.

date

Set the date (Just replace the MMDDhhmmYYYY with the correct date):

date MMDDhhmmYYYY

Example:

date 060410302015

Download the stage3 tar

cd /mnt/gentoo ; wget http://mirror.internode.on.net/pub/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20151231.tar.bz2 ; tar -xvjpf stage3-*.tar.bz2 --xattrs

Now to create our make.conf

rm -f /mnt/gentoo/etc/portage/make.conf ; vi /mnt/gentoo/etc/portage/make.conf

Just change the number in MAKEOPTS to be one more than you have CPU cores in your system for example 8 cores = -j9

CFLAGS="-O2 -pipe"
CXXFLAGS="${CFLAGS}"
CHOST="x86_64-pc-linux-gnu"
MAKEOPTS="-j3"
USE="caps hardened -ipv6 -systemd"
GENTOO_MIRRORS="ftp://mirror.internode.on.net/pub/gentoo/"
PORTDIR="/usr/portage"

Now copy the resolv.conf from the live system.

cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

Mount our new environment, for this example we are not using systemd but these mounts will work just fine

mount -t proc proc /mnt/gentoo/proc ; mount --rbind /sys /mnt/gentoo/sys ; mount --make-rslave /mnt/gentoo/sys ; mount --rbind /dev /mnt/gentoo/dev ; mount --make-rslave /mnt/gentoo/dev

Now chroot into our new environment:

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(AGIX chroot) $PS1"

Now we need to pull in a snapshot of portage

emerge-webrsync

You can read the Gentoo news later run this for now,

eselect news read >> /root/news

Set the system profile

eselect profile set 1

Set the timezone and the locale for the system (obviously change to match you location etc.)

echo "Australia/South" >> /etc/timezone ; emerge --config sys-libs/timezone-data ; echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen ; locale-gen ; eselect locale set 3

Now update the environment

env-update && source /etc/profile

Setup the package.use file

cat /etc/portage/package.use/iputils >> /root/package.use ; rm -rf /etc/portage/package.use ; mv /root/package.use /etc/portage/package.use
echo "sys-kernel/genkernel cryptsetup" >> /etc/portage/package.use

Now for the linux kernel

emerge --ask -jv sys-kernel/gentoo-sources sys-kernel/genkernel ; genkernel --menuconfig all ; ls /boot/kernel* >> /root/kernel_files ; ls /boot/initramfs* >> /root/initramfs_files

Install some useful applications,

emerge --ask -jv app-editors/vim app-admin/syslog-ng sys-process/cronie sys-apps/mlocate app-admin/sudo app-admin/logrotate app-misc/screen app-text/tree app-portage/gentoolkit app-portage/portage-utils net-misc/dhcpcd net-misc/netifrc

And start the important ones with the system,

rc-update add syslog-ng default ; rc-update add cronie default ; rc-update add sshd default

Setup the FStab, again adjust the file system choices if needed.

vi /etc/fstab
/dev/sda2	/boot		ext2	defaults,noatime	0 2
/dev/sda3	none		swap	sw			0 0
/dev/sda4	/		ext4	noatime			0 1
/dev/cdrom	/mnt/cdrom	auto	noauto,user		0 0

Set the hostname for the system

vi /etc/conf.d/hostname

Networking setup steps, you may need to repeat these if you adapter’s id changes

vi /etc/conf.d/net
dns_domain_lo="DOMAIN"
config_eth0="dhcp"

Create the init script

cd /etc/init.d
ln -s net.lo net.eth0
rc-update add net.eth0 default

Double check the keymap for the system and then set the password for root

cat /etc/conf.d/keymaps | grep -i "keymap="
passwd

Check the system clock settings, should be UTC by default but you can set it to local if that suits you

cat /etc/conf.d/hwclock | grep -i "clock="

Install Grub

emerge --ask -jv sys-boot/grub ; grub2-install /dev/sda
grub2-mkconfig -o /boot/grub/grub.cfg

Now we should be able to shutdown the system and the power back on into your working Gentoo installation. Please keep in mind that if you are using ssh to connect to the machine your installing on you will need to edit the sshd config to allow root login otherwise you will not be able to access your machine.

shutdown -h now

When the system comes backup login using the password that you set and run the following to make sure that your network device is working.

ifconfig -a

Sometimes when the machine is shutdown after installation it will change the name of the network device from say eth0 to enp2s0, if this happens just repeat the steps in the networking setup section above replacing eth0 with new adapter id and remove the old one.

If you do not see your networking device listed after running the below command then you will need to reconfigure the kernel with your device driver enabled.

ifconfig -a

Now update the system and you should be all set to start using it

emerge @world --update --deep --newuse -aqv --autounmask-write ; dispatch-conf

One final reboot

reboot

That is all there is to it, you now a have a basic Gentoo installation suitable for use with any of the other Gentoo projects mentioned on Agix Linux Blog.

If you have any questions or run into some issues while following this article please let me know in the comments section below.