This article is focused on using ZFS as the rootfs on Gentoo and designed to be used with the Handbook. Over time more advanced setups will be added so please check the TODO section to see if there is something that can be added to improve this article.
Currently only the admincd includes the zfs tools required to setup as root.
Follow the Handbook section on Preparing the disks returning at the creating file systems section.
This guide will be using the example below however it should be simple enough to adapt this to the user's needs.
/dev/sda1 | 1024 MiB | EFI System Partition | /boot /dev/sda2 | 2048 MiB | swap | swap /dev/sda3 | Rest of Disk | ZFS (or Encrypted ZFS) | /, /home, ...
Create a 1GB FAT32 filesystem:
Swap performance on a ZFS partition is known to be poor and using a swapfile isn't supported, instead it is recommended to use it's own partition.
Alternately, ZRAM could be used on systems with a large amount of RAM but do note ZFS will cache data to RAM for speed.
Create a Zpool
zpool create -f -o ashift=12 -o cachefile= -O compression=lz4 -O atime=off -m none -R /mnt/gentoo tank /dev/sda3
Create ZFS Datasets
This guide will be only creating a root and /home dataset however the user is free to create any extras that is needed.
zfs create tank/os
zfs create -o mountpoint=/ tank/os/main
zfs create -o mountpoint=/home tank/home
Return to the Handbook - Installing the Gentoo installation files and return just before entering chroot command.
Copy Zpool Cache
cp /etc/zfs/zpool.cache /mnt/gentoo/etc/zfs
Return to Handbook - Installing Gentoo base system and return here at Kernel configuration and compilation.
The user can choose between manually configured kernel or the distribution kernel.
If using the dist-kernel then the useflag
dist-kernel will need to be added to make.conf:
emerge -av sys-kernel/gentoo-kernel
Or, if you prefer using the precompiled binary,
emerge -av sys-kernel/gentoo-kernel-bin
ZFS program and kernel module
emerge -av sys-fs/zfs sys-fs/zfs-kmod
Tell Dracut to include the ZFS module to the initramfs.
add_dracutmodules+=" zfs "
Build the initramfs for the dist-kernel
emerge --config gentoo-kernel