Unofficial zfs on root installation instructions

With the latest Apollo ISO being released, we made some changes to make installing on zfs possible.

However, support for zfs isn’t setup by default. You will need to make a handful of manual changes to do a zfs install.

Here are the instructions for an online or community edition install. Without zfs modules being included, an offline install is not easily possible.

First we need to add zfs support to the ISO because we don’t ship the ISO with zfs modules.

sudo pacman -Sy zfs-dkms
sudo modprobe zfs

You will get some errors when mkinitcpio runs, you can ignore those since we are on the live ISO and any generated initramfs would never be used anyway

Now we need to make some changes to the Calamares config:

Next open up /etc/calamares/modules/pacstrap.conf and add zfs-dkms to the basePackages array. It should look something like this:

# basePackages is an array of package names to pass to pacstrap
#
basePackages:
  - zfs-dkms
  - base
  - base-devel

I added it at the top but it can be added anywhere in the list

Edit /etc/calamares/modules/partition.conf and find the key availableFileSystemTypes and add "zfs" to the list. Like this:

availableFileSystemTypes:  ["ext4","btrfs","xfs","zfs"]

Next edit the appropriate settings file in /etc/calamares/. For example, if you doing an online install, edit /etc/calamares/settings_online.conf. You need to add zfs between partition and mount in the exec section. Like this:

- exec:
  - partition
  - zfs
  - mount

Be careful because yaml is very sensative to whitespace. Make sure you have the same number of spaces as the other lines.

We need to make two changes to /etc/calamares/modules/services-systemd.conf

First edit the services array by adding zfs-import-cache and zfs-mount. When you are done, it might look something like this:

   - name: "vmtoolsd"
     mandatory: false
   - name: "vmware-vmblock-fuse"
     mandatory: false
   - name: "zfs-import-cache"
     mandatory: false
   - name: "zfs-mount"
     mandatory: true

In the same file, edit the targets array to add zfs-import and zfs. Be sure to remove the []. It should look like this:

 targets:
   - name: "zfs"
     mandatory: true
   - name: "zfs-import"
     mandatory: true

If you would like to change any of the zfs defaults, you can edit that /etc/calamares/modules/zfs.conf. Otherwise, feel free to leave it at the defaults.

Lastly, make one modifcation to /etc/calamares/scripts/chrooted_cleaner_script.sh, Near the bottom of the script add export ZPOOL_VDEV_NAME_PATH=1 like this:

########################################
########## SCRIPT STARTS HERE ##########
########################################

export ZPOOL_VDEV_NAME_PATH=1
_check_install_mode
_endeavouros
_virtual_machines

That’s it! From here you can run the installer as normal.

NOTE: I recommend you not use a swapfile on zfs. Either use zram or a dedicated swap partition.

16 Likes

Zfs-inport-cache has extra space. Is it intentional?

1 Like

Surely looks like a typo.
But let’s hear what @dalto says.

1 Like

No, I will fix that now. That extra indent would break it.

Thanks for noticing that.

Made a very unofficial script (hack) about zfs preparation before install. Use at your own risk!!!
It changes only the online install settings.
Here the script seems to work OK.

#!/bin/bash

Main() {
    sudo sed -i /etc/calamares/modules/pacstrap.conf \
        -e '/^  - base$/i \  - zfs-dkms'
    sudo sed -i /etc/calamares/modules/partition.conf \
        -e 's|^\(avail.*,"btrfs",\)|\1"zfs",|'
    sudo sed -i /etc/calamares/modules/services-systemd.conf \
        -e '/^   - name: "firewalld"/i \   - name: "zfs-import-cache"\n     mandatory: false\n   - name: "zfs-mount"\n     mandatory: true' \
        -e '/^ targets:/a \   - name: "zfs"\n     mandatory: true\n   - name: "zfs-import"\n     mandatory: true' \
        -e 's|^\( targets:\) \[\]|\1|'

    sudo sed -i /etc/calamares/settings_online.conf \
        -e '/^  - mount$/i \  - zfs'

    sudo sed -i /etc/calamares/scripts/chrooted_cleaner_script.sh \
         -e '/^_check_install_mode$/i \ \nexport ZPOOL_VDEV_NAME_PATH=1'

    sudo pacman -Sy zfs-dkms --noconfirm  # ignore errors!
    sudo modprobe zfs


    # The following lines are not related to zfs and are not needed after the Apollo ISO.
    # They make a simple fix to chrooted_cleaner_script.sh.

    if [ -n "$(grep "2022\.04\.08" /usr/lib/endeavouros-release)" ] ; then
        sudo sed -i /etc/calamares/scripts/chrooted_cleaner_script.sh \
             -e 's|^rm -R /etc/calamares /opt/extra-drivers|rm -rf /etc/calamares /opt/extra-drivers|'
    fi
}

Main "$@"
1 Like

zfs

1 Like

I gave it a try in vmware today and it worked!

But after first boot I see one error message during boot and one in the journal

The boot mesage is about a failed fsck which obvioulsy is not working with zfs. Any chance to get rid of that message?

The second error message is about a systemd-gpt-auto-generator. I dont know what that means.

Other than that the system is up and running with zfs. That is really great. @dalto thank you!

1 Like

Thanks!

I will take a look at those and see what I can find.

At some point in time I would want to try this on my laptop. But there I would need native zfs encryption. How would that work?

1 Like

Check the encryption box in Calamares.

Although you remind me that I haven’t tested that in a while. I probably should give it a test in a VM. However, it is designed to use zfs encryption instead of luks when applied to zfs.

It did not work. Crash after a few seconds.

And by the way, that uses luks but not native zfs encrpytion.

Did you use manual partitioning or erase disk?

I used “erase disk”

I am not sure I ever tested that. I originally implemented it months ago so I will have to test some things.

Hmm…I did an install and am not getting this one. I will try another install.

I am getting this though. Seems like it may be a recent systemd issue.

I will take a look at the encryption now.

The issues with encryption are a potential bug or lacking feature in the zfs-dkms package. I found installing zfsbootmenu in one of the setup scripts the following comments and workaround. Running the commands in a chroot of the new installation before rebooting will fix the encryption unlock issues with your existing installation method. All credit goes to ZFSBootMenu I just noticed this trying to follow the instructions.
https://github.com/zbm-dev/zfsbootmenu:

The initcpio hook that ships with zfs-dkms do not support encryption

Use the hook from archzfs instead

zfsutils=“https://raw.githubusercontent.com/archzfs/archzfs/master/src/zfs-utils
cpiolib="/usr/lib/initcpio"
curl -L -o “${cpiolib}/hooks/zfs” “${zfsutils}/zfs-utils.initcpio.hook”
curl -L -o “${cpiolib}/install/zfs” “${zfsutils}/zfs-utils.initcpio.install”
curl -L -o “${cpiolib}/install/zfsencryptssh” “${zfsutils}/zfs-utils.initcpio.zfsencryptssh.install”
mkinitcpio -p linux

I just realized I forgot to follow-up after my encryption testing.

If you use manual partitioning, zfs encryption seems to work fine. However, grub fails to install. I think during my testing I was using systemd-boot.

I will have to do some research and see if grub supports booting off a zfs encrypted /boot

Sounds like I may need to research booting with rEFInd too - in all that spare time I don’t have. Oh well - I have the info ready to go when I can get to it! :grin:

404 Page not found

Fixed:
The URL has a colon at the end which needs to be removed to make it work.

Remove the : from the end.