Assumptions: You have a host with Ansible and a network.
Download the Gentoo iso from here.
Download the role from here.
You will need to edit:
gentoobase/vars/main.yml - encrypt password
Boot with the ISO (cached), ensuring that networking is present.
Once booted, set a password and start the ssh daemon.
Unmount the ISO.
SSH as the root user to the target server.
mkdir .ssh
Copy the pubkey of the user executing the playbook into /root/.ssh/authorized_keys
CD to your playbook role directory.
Unpack the role tarball
Create the playbook below.
Playbook
---
- name: Base Gentoo Installation
gather_subset: min
hosts: vms
tasks:
- import_role:
name: gentoobase
...
ansible-playbook -u root gentoo_install_base.yml
This will take ~3 hours to complete the base system.
Timings are based on a VM (i7 6700K x4, 16Gb RAM)
If you wish to change any settings, edit:
roles/gentoobase/vars/main.yml
Now go outside and get some fresh air.
The below is to understand the build process.
Manual Steps
Partition the HDD:
gdisk /dev/Xda
part1 = 512M 8300 [boot]
part2 = 100M ef00 efi [efi]
part3 = LVM 8e00 [LVM]
part4 = 4G 8200 [swap]
Create LVMs:
pvcreate /dev/Xda2
vgcreate vg00 /dev/Xda2
lvcreate -L 20G -n root vg00
lvcreate -L 10G -n home vg00
Format FileSystems:
mke2fs -t ext4 -L BOOT /dev/Xda1
mkfs.vfat -F 32 -n EFI /dev/Xda2
mke2fs -t ext4 -L ROOT /dev/mapper/vg00-root
mke2fs -t ext4 -L HOME /dev/mapper/vg00-home
Mount FileSystems:
mount -t ext4 /dev/mapper/vg00-root /mnt/gentoo
mkdir -p /mnt/gentoo/boot/EFI
mount -t ext4 /dev/vda1 /mnt/gentoo/boot
mount -t vfat /dev/vda2 /mnt/gentoo/boot/EFI
mount swap if configured
SCP the stage3 and portage files to the VM
Download Tarballs:
wget https://gentoo.osuosl.org/snapshots/portage-latest.tar.xz
Unpack files:
tar xpf stage3...xz -C /mnt/gentoo
tar xpf portage-latest...xz -C /mnt/gentoo/usr/
Mount Some More FileSystems:
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
mount --rbind /run /mnt/gentoo/run
mount --make-rslave /mnt/gentoo/run
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm
Setup Rsync Mirror:
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
DNS:
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
Setup Portage:
mkdir /mnt/gentoo/var/db/repos/gentoo
mkdir /mnt/gentoo/etc/portage/repos.conf
nano -w /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
[DEFAULT]
main-repo = gentoo
[gentoo]
location = /usr/portage
sync-type = rsync
sync-uri = rsync://rsync.europe.gentoo.org/gentoo-portage
Chroot into the VM:
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
Set Locale:
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
nano -w /etc/locale.gen
en_GB.UTF-8 UTF-8
Execute locale-gen
Set Profile:
eselect profile list (choose the number in brackets)
"[30] default/linux/amd64/23.0/no-multilib/systemd (stable)"
eselect profile set 30
Let's Start Building:
emerge -av gentoo-sources
ln -s /usr/src/linux-<version>-gentoo /usr/src/linux
cd /usr/src/linux
make defconfig && make && make modules_install
cp arch/x86_64/boot/bzImage /boot/kernel-<version>
cp .config /boot/config-<version>-gentoo (optional)
cpan Locale::gettext
emerge -q vim genkernel grub lvm2 gptfdisk efibootmgr
Setup Grub:
grub-install --target=x86_64-efi --efi-directory=/boot/EFI /dev/Xda
vi /etc/default/grub
GRUB_CMDLINE_LINUX="rootfstype=ext4 init=/usr/lib/systemd/systemd dolvm"
Update fstab:
blkid
Copy the UUID for /boot and /
UUID1=$(blkid | grep Xda1 | grep -Po "(UUID.*?)\"\s")
UUID2=$(blkid | grep Xda2 | grep -Po "(UUID.*?)\"\s")
echo -e "${UUID1}\t/boot\text4\tdefaults\t1 2" >> /etc/fstab
echo -e "${UUID2}\t/\text4\tdefaults\t1 1" >> /etc/fstab
cd /etc/
cp -p genkernel.conf genkernel.conf.orig
vi genkernel.conf
uncomment:
MAKEOPTS="$(portageq envvar MAKEOPTS)"
LVM="yes"
genkernel initramfs --lvm (this does not overwrite the kernel above)
grub-mkconfig -o /boot/grub/grub.cfg
passwd
emerge -q networkmanager gentoolkit gpm
systemctl enable sshd NetworkManager