By popular demand. I’m posting an update to my Linux Kernel + ZFS custom build guide. As always, feedback/suggestions appreciated. I’m definitely ‘not’ a kernel building/git expert.
Things To Note / Assumptions
This procedure is written on Ubuntu 19.04. Reason being, it’s my daily-driver distro. That’s what I’m most comfortable with. However, I assume a lot of this procedure can be applied to other Distros with some adjustments.
Starting with ZFS 0.8 the SPL module will be included in the main ZFS project code. So building SPL is no longer necessary. However, if you are building 0.7.*, you’ll need to include SPL. See my previous post linked above for details.
Kernel and ZFS Git repo will be located in ~/build. For this guide, I’ll be building Kernel 5.0.9 and ZFS 0.8.0-RC4
Install Prerequisites
Install required dependencies/tools to build the Linux kernel.
sudo apt install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache flex bison libelf-dev
Install required dpendencies/tools to build ZFS
sudo apt install build-essential autoconf libtool gawk alien fakeroot linux-headers-$(uname -r) zlib1g-dev uuid-dev libattr1-dev libblkid-dev libselinux-dev libudev-dev libdevmapper-dev
Download Linux kernel and ZFS Git repos
mkdir ~/build && cd ~/build
git clone git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack ubuntu_kernel
cd ./ubuntu_kernel
git checkout tags/v5.0.9
cd ../
git clone https://github.com/zfsonlinux/zfs.git
cd ./zfs
git checkout tags/zfs-0.8.0-rc4
cd ../
Note: To determine the correct tags. I usually use git tag
or navigate to the gitub page and look at Releases.
Download/apply Ubuntu specific patches
Ubuntu has some Distro specific patches they apply to the kernel prior to building. Download and apply them.
Navigate your favorite web browser to the Ubuntu Kernel Mainline site. Find the kernel version you’re looking to build (in our example v5.0.9).
Download all the patches listed on the page into the ‘./build’ directory. I usually use wget. Ex:
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.0.9/0001-base-packaging.patch
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.0.9/0002-UBUNTU-SAUCE-add-vmlinux.strip-to-BOOT_TARGETS1-on-p.patch
…etc…etc…
The final result will look like this:
timtierney@darter-pop:~/build$ ls
0001-base-packaging.patch
0002-UBUNTU-SAUCE-add-vmlinux.strip-to-BOOT_TARGETS1-on-p.patch
0003-UBUNTU-SAUCE-tools-hv-lsvmbus-add-manual-page.patch
0004-debian-changelog.patch
0005-configs-based-on-Ubuntu-5.0.0-14.15.patch
ubuntu_kernel
zfs
Now patch the kernel. Make sure you apply them in numerical order.
cd ./ubuntu_kernel
patch -p1 < ../0001-base-packaging.patch
patch -p1 < ../0002-UBUNTU-SAUCE-add-vmlinux.strip-to-BOOT_TARGETS1-on-p.patch
…etc…etc…
Copy Working Kernel Config and Prepare
Make sure you’re in the ‘ubuntu_kernel’ folder and execute the following
cp /boot/config-"$(uname -r)" .config
yes '' | make oldconfig
make prepare scripts
Configure, Build, and Install ZFS
cd ../zfs
sh autogen.sh
./configure --prefix=/ --libdir=/lib --includedir=/usr/include --datarootdir=/usr/share --enable-linux-builtin=yes --with-linux=$HOME/build/ubuntu_kernel --with-linux-obj=$HOME/build/ubuntu_kernel
./copy-builtin $HOME/build/ubuntu_kernel
make -j <number of CPU cores>
sudo make install
Enable ZFS and Build The Kernel
cd ../ubuntu_kernel
make menuconfig
When the menu displays, move the cursor down to Filesystems and press Enter.
Highlight ZFS and press ‘Y’ to include it in your .config file.
‘Tab’ over to Save and press enter. Accept the default filename of ‘.config’ and press Enter. Then ‘Tab’ over to Exit and press Enter
make clean
make -j <number of CPU cores> deb-pkg LOCALVERSION=-custom
Install Kernel DEB Package
Inside the ‘build’ directory, there wil now be several ‘.deb’ packages. Install them!
cd ../
sudo dpkg -i *.deb
Reboot and you should be on the latest LInux kernel with ZFS support.