Preparing Fedora 26 laptop with ZFS and encryption — zfs (part 6)

Andrzej Rehmann
5 min readAug 4, 2017

--

zfs list

Before we install ZFS it’s good practice to update the kernel first .

su -
dnf update kernel\*
Accept updating kernel.

Reboot the machine if the kernel was updated.

After rebooting install kernel-devel and dkms by typing:

# reboot first if you updated kernel!
dnf install kernel-devel dkms

Install ZFS. Go to http://zfsonlinux.org/ and click on Fedora which should redirect you to https://github.com/zfsonlinux/zfs/wiki/Fedora. From there copy and paste:

dnf install http://download.zfsonlinux.org/fedora/zfs-release$(rpm -E %dist).noarch.rpmgpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux

Install ZFS.

dnf install zfs

When ZFS installs enable its modules.

systemctl preset zfs-import-cache zfs-import-scan zfs-mount zfs-share zfs-zed zfs.target

Confirm ZFS was installed.

dkms status

Load ZFS.

modprobe zfs

Get the luks partition UUID name of /dev/sda4.

lsblk

Create ZFS pool on /dev/sda4 and check if it was created.

zpool create -m none -o ashift=12 -O relatime=on -O compression=lz4 -O xattr=sa <zpool_name> /dev/mapper/luks-<partition_UUID>zfs list

ZFS says we have 209G of available space which sounds about right.

What’s left is to create a ZFS create mountpoints for /home and /var/lib/docker (if you use Docker).

Reboot and log in as root by clicking on the Not listed? and typing root as the user name.

Click on the “Not listed?”.
Log in as root.

Logged in as root, open terminal and let’s create mountpoint for /home .

First Move your home to another location as ZFS needs an empty directory to create a mountpoint.

mv /home/<user_name> /home_<user_name>_copy
ls -la /home # make sure it's empty!

Then remove the the /home directory. And create ZFS mountpoint for it.

rm -rf /home
zfs create -o mountpoint=/home <zpool>/home

You could leave it at this but I will add two more mountpoints, one for my personal home and one for my folder where i keep all of my projects. This makes creating and managing ZFS snapshots easier.

zfs create <zpool>/home/andrzej.rehmann
zfs create <zpool>/home/andrzej.rehmann/projects
zfs list
Don’t mind the docker mountpoint, we will add it later.

Move back your home to /home/<user_name> and restore selinux context and put the right ownership on all our files (remember we are root at the moment).

mv /home_<user_name>_copy /home/<user_name>
restorecon -R /home
chown -R <user_name>:<user_name> /home/<user_name>
chmod 700 /home<user_name>

Check if the size of you home pool increased (it should).

zfs list

If you don’t use Docker then skip this step.

Create mountpoint for docker and restore selinux context

zfs create -o mountpoint=/var/lib/docker <zpool>/docker
restorecon -R /var/lib/docker

Docker will automatically detect z ZFS file system when you install it.

Log out from being a root and log in as you.

Log out from being a root.

After you log in check the size of your zfs pool.

zfs list

We can see that pool lithiumpool/home has 38.3M used space. It means that /home and whatever folder is inside (eg. our /home/<user_name>) is stored on a ZFS managed partition /dev/sda4.

Never update kernel and zfs or dkms toghether. Update kernel last.

dnf update --exclude=kernel\*
dnf update

This is the end of this series. In future posts I would like to talk about how to use ansible to configure your Fedora laptop and how to git manage your home directory so it’s synchronized between all of your laptops and backed up by github/bitbucket.

Special thanks to Marcin Skarbek for setting up my laptop and explaining all of this stuff to me with excruciating details.

--

--