Gentoo ZFS Install

ZFS on root

ref: ZFS/rootfs

Partitions

Layout

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.

Disk Partitioning

Device

Size

Partition

Mount Point

/dev/sda1

1024 MiB

EFI System Partition

/boot/efi

/dev/sda2

2048 MiB

swap

swap

/dev/sda3

Rest of Disk

ZFS Partition

/, /boot, /home,

The document used /efi as the mount point, but other docs use /boot/efi.

Boot

mkfs.vfat -F 32 /dev/sda1

Swap

mkswap /dev/sda2
swapon /dev/sda2

ZFS Setup

Generate host ID

Randomly generate host ID into /etc/hostid allowing output overwrite.

zgenhostid -f

Alternatively, set a specific host ID, 0x00bab10c in this example.

zgenhostid -f 0x00bab10c

Create a ZFS pool

Load ZFS kernel module and create a ZFS pool tank on /dev/sda3.

modprobe zfs

zpool create -f \
    -o ashift=12 \
    -o autotrim=on \
    -o compatibility=openzfs-2.1-linux \
    -O acltype=posixacl \
    -O xattr=sa \
    -O relatime=on \
    -O compression=lz4 \
    -m none tank /dev/sda3

Note

The option -o compatibility=openzfs-2.1-linux makes sure that GRUB works. If you are using ZFSBootMenu, you can skip that option.

Create ZFS file systems

zfs create -o mountpoint=none tank/os
zfs create -o mountpoint=/ -o canmount=noauto tank/os/gentoo
zfs create -o mountpoint=/home tank/home

zpool set bootfs=tank/os/gentoo tank
zpool export tank
zpool import -N -R /mnt/gentoo tank
zfs mount tank/os/gentoo
zfs mount tank/home
mount -t zfs

Here is an example of the command output in case of successful mounting of file systems.

tank/os/gentoo /mnt/gentoo type zfs (rw,relatime,xattr,posixacl)
tank/home on /mnt/gentoo/home type zfs (rw,relatime,xattr,posixacl)

Update device symbolic links:

udevadm trigger

Return to the Handbook

  • EFI_system_partition_filesyste and return just before entering chroot command.

cp /etc/hostid /mnt/gentoo/etc

Return to the Handbook

  • Installing Gentoo base system and return here at Kernel configuration and compilation.

Kernel

Edit /etc/portage/make.conf

vim /etc/portage/make.conf
# Add the following line for distrubution kernel support
USE="dist-kernel"
emerge -av sys-kernel/gentoo-kernel

Note

if you prefer using the pre-compiled binary, emerge -av sys-kernel/gentoo-kernel-bin

ZFS userland utilities and kernel module

The sys-fs/zfs and sys-fs/zfs-kmod packages are necessary to allow your system to interact with and manage your ZFS pools.

emerge -av sys-fs/zfs sys-fs/zfs-kmod

Initramfs

Create a directory for Dracut configuration files if it does not exist.

mkdir -p /etc/dracut.conf.d

Then, create a file zol.conf with the following content in this directory:

vim /etc/dracut.conf.d/zol.conf

FILE /etc/dracut.conf.d/zol.confDracut configuration for ZFS

nofsck="yes"
add_dracutmodules+=" zfs "

Build the initramfs for the distribution kernel

emerge --config sys-kernel/gentoo-kernel

Note

Or, if the binary version was installed, emerge –config sys-kernel/gentoo-kernel-bin

Return to the Handbook

  • Configuring the system and return here at Configuring the bootloader for anything other than sys-boot/grub.

Bootloader

zfs set org.zfsbootmenu:commandline="quiet loglevel=4" tank/os

Warning

Therefore, the -systemd USE flag must be added to sys-kernel/installkernel to prevent that from happening.

If the ESP was not mounted previously, it is necessary to do it now:

mkdir -p /boot/efi
mount /dev/sda1 /boot/efi

ZFSBootMenu

Installing ZFSBootMenu (prebuilt)

Create a directory for the bootloader and download the EFI binary into it.

mkdir -p /boot/efi/EFI/BOOT
curl -L https://get.zfsbootmenu.org/efi -o /boot/efi/EFI/BOOT/BOOTX64.EFI

emerge -av sys-boot/efibootmgr
efibootmgr -c -d /dev/sda -p 1 -L "ZFSBootMenu" -l \\BOOT\\EFI\\BOOT\\BOOTX64.EFI

Rebooting the system

Exit the chrooted environment and unmount all mounted partitions, do not forget to export the pool. After that, the system can be rebooted.

exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -n -R /mnt/gentoo
zpool export tank
reboot