Skip to content

Instantly share code, notes, and snippets.

@mcheshkov
Last active October 29, 2023 18:40
Show Gist options
  • Save mcheshkov/69dfc70fd1ec5bdb875105979c20b75b to your computer and use it in GitHub Desktop.
Save mcheshkov/69dfc70fd1ec5bdb875105979c20b75b to your computer and use it in GitHub Desktop.
Building OpenZFS for Fedora CoreOS
#!/bin/bash
FEDORA_MAJOR="38"
ARCH="x86_64"
KERNEL_VERSION="6.3.8-200.fc38"
ZFS_VERSION="2.1.12"
podman run \
--interactive \
--tty \
--rm \
-v $(pwd):/data:z \
-e FEDORA_MAJOR=${FEDORA_MAJOR} \
-e ARCH=${ARCH} \
-e KERNEL_VERSION=${KERNEL_VERSION} \
-e ZFS_VERSION=${ZFS_VERSION} \
fedora:${FEDORA_MAJOR} \
/data/internal_build.sh
#!/bin/bash
set -Eeuo pipefail
set -x
KERNEL_FULL_VERSION="${KERNEL_VERSION}.${ARCH}"
ZFS_NAME="zfs-${ZFS_VERSION}"
ZFS_FILENAME="zfs-${ZFS_VERSION}.tar.gz"
WORKDIR=$(mktemp -d)
cd $WORKDIR
dnf install -y \
koji
koji download-build --arch=${ARCH} --rpm kernel-devel-${KERNEL_FULL_VERSION}
dnf install -y \
./kernel-devel-${KERNEL_FULL_VERSION}.rpm
dnf install -y \
wget
wget https://github.com/openzfs/zfs/releases/download/${ZFS_NAME}/${ZFS_FILENAME}
tar xfv ${ZFS_FILENAME}
cd ${ZFS_NAME}
# https://openzfs.github.io/openzfs-docs/Developer%20Resources/Custom%20Packages.html#get-the-source-code
dnf install -y --skip-broken \
epel-release \
gcc \
make \
autoconf \
automake \
libtool \
rpm-build \
kernel-rpm-macros \
libtirpc-devel \
libblkid-devel \
libuuid-devel \
libudev-devel \
openssl-devel \
zlib-devel \
libaio-devel \
libattr-devel \
elfutils-libelf-devel \
kernel-devel-$(uname -r) \
python3 \
python3-devel \
python3-setuptools \
python3-cffi \
libffi-devel \
ncompress
dnf install -y --skip-broken --enablerepo=epel --enablerepo=powertools \
python3-packaging \
dkms
./configure --with-linux=/usr/src/kernels/${KERNEL_FULL_VERSION}
# kmodtool patch is obsolete somewhere from zfs 2.1.6
# /lib/modules/${kernel_uname_r}/System.map ${kernel_uname_r} branch is already present
#dnf install -y \
# patch
#patch -i /data/patches/*.patch -p 1
make -j1 rpm-utils rpm-kmod
cp kmod-zfs-${KERNEL_FULL_VERSION}-${ZFS_VERSION}-1.fc${FEDORA_MAJOR}.x86_64.rpm /data/packages/
From: Mikhail Cheshkov <mcheshkov@gmail.com>
Date: Sat Aug 7 17:15:45 UTC 2021
Subject: Adjust kmodtool %post script to generate System.map in /lib/modules
diff -u a/scripts/kmodtool b/scripts/kmodtool
--- a/scripts/kmodtool 2021-07-28 19:13:53.373619061 +0300
+++ b/scripts/kmodtool 2021-07-28 19:15:24.643052684 +0300
@@ -182,9 +182,9 @@
%{?KmodsRequires:Requires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
%{?KmodsRequires:BuildRequires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
%post -n kmod-${kmodname}-${kernel_uname_r}
-${prefix}${depmod_path} -aeF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} > /dev/null || :
+${prefix}${depmod_path} -aeF /lib/modules/${kernel_uname_r}/System.map ${kernel_uname_r} > /dev/null || :
%postun -n kmod-${kmodname}-${kernel_uname_r}
-${prefix}${depmod_path} -aF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} &> /dev/null || :
+${prefix}${depmod_path} -aF /lib/modules/${kernel_uname_r}/System.map ${kernel_uname_r} &> /dev/null || :
EOF
else
@johnmmcgee
Copy link

Does this still work as expected?

@mcheshkov
Copy link
Author

@johnmmcgee Not really, new ZFS versions does not require patch. I'll upload update in a second

@mcheshkov
Copy link
Author

This one worked for me and recent CoreOS kernel.

@johnmmcgee
Copy link

What is the way to install this after it is completed?

@mcheshkov
Copy link
Author

You should have a packages dir with a file named like kmod-zfs-6.3.8-200.fc38.x86_64-2.1.12-1.fc38.x86_64.rpm
Install it as any other RPM on your system, for example dnf install on Fedora/CentOS/RHEL and rpm-ostree install on Silverblue/CoreOS

@johnmmcgee
Copy link

How do you handle os updates?

@mcheshkov
Copy link
Author

I only used this with CoreOS, so no idea how to properly upgrade regular Fedora.

Updates that doesn't touch kernel should be happy with simple rpm-ostree upgrade.
But if there's a new kernel version it will fail with message like this:
package kmod-zfs-%OLD_KMOD_VERSION% from @commandline requires kernel-uname-r = %OLD_KERNEL_VERSION%, but none of the providers can be installed

Basically, you need to remove old ZFS kmod and install new together with kernel upgrade. One way to do this is something like this:

  1. Get current package name, i.e. from that error message, or from rpm-ostree status output
  2. Get new kernel version, i.e. from rpm-ostree upgrade --preview, look for kernel package.
  3. Build kmod for new kernel.
  4. Run rpm-ostree upgrade --uninstall kmod-zfs-%OLD_KMOD_VERSION% --install /var/local/packages/zfs/kmod-zfs-%NEW_KMOD_VERSION%.rpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment