ZFS on Root guide

This guide assumes you have already created your partition layout needed for your system. We will also assume your partition layout is:

  /dev/sda1 /boot (formatted with vfat)
  /dev/sda2 /
Install ZFS module
Note: The adding of the archzfs-testing repo and pacman -Sy zfs-dkms will also need to be done inside chroot.

First we need to install the ZFS binaries we need and also the kernel module.

In /etc/pacman.conf add:

 [archzfs-testing]
 Server = https://archzfs.com/$repo/$arch

Now we need to initialize pacman keyring

 pacman-key --init
 pacman-key --populate artix
 pacman-key -r F75D9D76
 pacman-key --lsign-key F75D9D76

Install ZFS module

 pacman -Sy zfs-dkms

Load the module

 modprobe zfs
Create the ZFS pool

Next we create the ZFS pool, named zroot.
This is to create a standard single pool, no mirror or RAID

 zpool create -o ashift=12 zroot /dev/sda2
Create the ZFS datasets

Next, decide how you want your ZFS datasets(can be looked as partitions) to be laid out.
Create your layout how you want now, or it is near impossible to redo besides doing another install

The following is how I do my basic layout

 zfs create -o compression=lz4 -o mountpoint=none zroot/ROOT
 zfs create -o compression=lz4 -o mountpoint=/ zroot/ROOT/default
 zfs create -o compression=lz4 -o mountpoint=none zroot/HOME
 zfs create -o compression=lz4 -o mountpoint=/home/{USERNAME} zroot/HOME/{USERNAME}
Set ZFS pool to import

Tell the bootloader which pool to import/use

 zpool set bootfs=zroot/ROOT/default zroot

Set ZFS' cachefile

 zpool set cachefile=/etc/zfs/zpool.cache zroot
Artix install preparation

Now we need to export the pool

 zpool export zroot

Now we import the pool, prior to installation. This mounts the pool to the location we need to install Artix Linux in.

 zpool import -d /dev/sda2 -R /mnt zroot

Create the boot directory and mount

 mkdir /mnt/boot
 mount /dev/sda1 /mnt/boot
Swap

If you want a swap partition inside ZFS pool, it is easy to do and eliminates need of a separate partition.
We need to create a dataset just for swap:

 zfs create -V 4G -b $(getconf PAGESIZE) -o compression=zle       -o logbias=throughput -o sync=always       -o primarycache=metadata -o secondarycache=none       -o com.sun:auto-snapshot=false $POOLNAME/swap

Replace -V 4G with size you need
Now we format it:

 mkswap -f /dev/zvol/$POOLNAME/swap

Mount it:

 swapon /dev/zvol/$POOLNAME/swap

Now you can follow Installation

Notes

General ZFS information

 The more memory you have the better ZFS will do, as ZFS itself uses memory for it's L2ARC for cache
 which is one thing that generally makes ZFS feel faster. I personally run ZFS on a 8GB RAM system fine.

Boot Manager

 I recommend using rEFInd boot manager with ZFS, as it makes it easier, but you can choose to use GRUB and follow guides
on how to configure it.

After installing rEFInd and following the install guide
Create a linux_refind.conf in /boot with the following

 "Boot Artix Linux" "root=ZFS=bootfs rw"

Swap partition

You can create a swap partition inside the ZFS pool:

 zfs create -V {SIZE} zroot/swap
 mkswap /dev/zvol/zroot/swap
 swapon /dev/zvol/zroot/swap

Dataset does not auto mount

OpenRC

Create a zfs init script in /etc/init.d with the following:

 #!/sbin/openrc-run

command="zfs mount -a" Make the init script execuatable:

 chmod +x /etc/init.d/zfs

Add zfs to default runlevel

 rc-update add zfs default

mkinitcpio hook

We also need to add a ZFS hook to the mkinitcpio.conf
Edit /etc/mkinitcpio.conf and change the hook to look like this:

 HOOKS=(base udev autodetect modconf block keyboard zfs filesystems)

FSTAB

 Following the normal installation guide, only add your /boot information, as ZFS does not need to be in it.
 If you created a swap partition add it also to the fstab.

kmod

 Currently kmod-27-1 has issue with linux-lts-5.4.20. Downgrade to kmod-26-3

Multiple ZFS partitions

 Only one ZFS partition should be on a single disk, as ZFS auto imports datasets and would cause file conflicts.
 For example, one pool has /usr/bin and another pool's /usr/bin gets imported as well.