Gentoo with systemd on a Hetzner Server (Part 2)

Installing the base system

After preparing the system’s disks the operating system can now be installed. The best resource for installing Gentoo is the Installation Handbook which I will follow as well. I will add explainations to the process and commands when nessesary for a better understanding.

Mounting the disks

mkdir /mnt/gentoo
mount /dev/md1 /mnt/gentoo/
mkdir -p /mnt/gentoo/{boot,usr/portage}
mount /dev/md0 /mnt/gentoo/boot/
mount /dev/vg/portage /mnt/gentoo/usr/portage/
mkdir /mnt/gentoo/usr/portage/distfiles
cd /mnt/gentoo/

Fetching the base system

Now quickly download the stage3 tarball and extract it. I decided to go with the hardened no-multilib amd64 stage file, since I do not plan to run any 32bit software on the Server. If I ever need to switch to a multilib later there is a nice post by Charles Svitlik on how to do it without reinstalling.

tar xjpf stage3-*.tar.bz2

Into the chroot

This is strait forward. The only thing to watch out is the /dev/shm which is just a symlink in the Hetzner rescue system and has to be replace by something real.

cp -L /etc/resolv.conf /mnt/gentoo/etc/
mount /dev/vg/distfiles /mnt/gentoo/usr/portage/distfiles/
mount -t proc proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
rm /dev/shm && mkdir /dev/shm
mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

Use flags ’n‘ CFLAGS stuff

Before starting to install any software lets set the CFLAGS for compiling and the use flags so that emerge can pick the right packages for us. On the CFLAGS just the -march=native was added to let gcc decide for the best arch. The use flags are extended by the flag systemd.

CFLAGS="-march=native -O2 -pipe"
USE="bindist mmx sse sse2 systemd"

Disk stabbing

The disks are mounted, but the new linux will not remember them! So its f-stabbing time.

/dev/md0                /boot           ext2            noauto,noatime  1 2
/dev/md1                /               ext4            noatime         0 1
/dev/sda3               none            swap            sw,pri=1        0 0
/dev/sdb3               none            swap            sw,pri=1        0 0
/dev/vg/portage         /usr/portage    ext2            noatime         1 2
/dev/vg/distfiles       /usr/portage/distfiles  ext2    noatime         1 2
tmpfs           /var/tmp/portage                tmpfs   uid=portage,gid=portage,mode=775,size=2048M,noatime     0 0

The last line will make portage able to use the RAM temporarly while compiling, which is a hugh speed up when enough RAM is available. Please refer to the Gentoo Wiki on Portage temp directory. Mount the RAM-drive using mount /var/tmp/portage. Later you can have per ebuild environments which either use the tmpfs or not which is pretty neat and another reason I do love Gentoo!

Re-emerge the world

Now that preparations are done let’s recompile everything for fun 🙂

emerge -DNeav @world

Timezone and Locale

Sets quickly setup the timezone and locale, so we can start working on the kernel. After rebooting the system we will comeback to this again using the systemd tools.

echo "Europe/Berlin" > /etc/timezone
emerge --config sys-libs/timezone-data
nano -w /etc/locale.gen
eselect locale list
eselect locale set 6
env-update && source /etc/profile


Last but not least the Kernel. Here I again refer to the systemd wiki page and the Gentoo Handbook on that matter.

The finishing touch

Last steps before the first reboot of the system are to install the system services, as well as configuring and installing the network and bootloader.

System services

emerge dhcpcd lvm2 mdadm vim sudo
systemctl enable dhcpcd
systemctl enable systemd-networkd
systemctl enable systemd-resolved
systemctl enable sshd
systemctl enable lvm2-monitor.service

The last command opens up a editor with which the sudoer file is changed. Look for the commented line %wheel and uncomment it, so that users from this group can run sudo commands.

Network configuration

Good thing is, that Hetzner has an DHCP server, which eases up the configuration a lot. To configure the network create a new file nano -w /etc/systemd/network/ and paste the content.



Arch Linux Wiki systemd-networkd has some good tips on how to use systemd for network configuration.

Grub the bootloader

Before emerging the grub bootloader it must be chosen which architectures should be supported. I choose efi-64 and the legacy bios boot pc.

GRUB_PLATFORMS="efi-64 pc"

Now emerge and install the bootloader

emerge grub 
grub2-install /dev/sda
grub2-install /dev/sdb
grub2-mkconfig -o /boot/grub/grub.cfg


Before leaving the chroot create a new user and change the password for root.

useradd -m -G users,wheel,portage -s /bin/bash zeUser
passwd zeUser


Remember to set the link to the resolv.conf which will be created by systemd-resolvd, otherwise we stick to the settings we copied before entering the chroot.

ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount /mnt/gentoo{/boot,/sys,/proc,/usr/portage/distfiles,/usr/portage,/var/tmp/portage,}


Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.