We want to use bcachefs which is not in the mainline yet therefore we have to compile our own custom kernel.
Start with the outdated but still relevant official tutorial and pull the latest. At the moment 6.1 is the newest kernel. To compile, preferably use a non-root user and start cloning the source files:
cd
mkdir kustomkernel
cd kustomkernel
git clone https://evilpiepirate.org/git/bcachefs-tools.git
git clone https://evilpiepirate.org/git/bcachefs.git
Note: the kernel source files are huge, 2.5GB downloaded, over 4GB when uncompressed…
Note: to check what's the kernel version for bcachefs run git describe --tags from the bcachefs dir:
root@antares:/home/shrew/kustomkernel/bcachefs# git describe --tags
v6.1-1813-g3684119f4f18
After getting the source files we need some dependencies to be able to compile:
su - # as root
apt-get update
apt-get upgrade
apt-get install build-essential devscripts -y
apt build-dep linux -y
Compiling bcachefs-tools and the kernel may still cause a lot of trouble due to no yet unresolved dependencies:
root@antares:~/kustomkernel/bcachefs-tools# make
/bin/sh: 1: pkg-config: not found
Makefile:71: *** pkg-config error, command: pkg-config --cflags \
"blkid uuid liburcu libsodium zlib liblz4 libzstd libudev libkeyutils". Stop.# or
libaio.h: No such file or directory
To make thing easy the missing commands and the packages may be named differently:
| missing dependency | deb package to install | note |
|---|---|---|
| pkg-config | pkg-config | |
| blkid | libblkid-dev | |
| uuid | uuid--dev | already present |
| liburcu | liburcu-dev | |
| libsodium | libsodium-dev | |
| zlib | zlib1g-dev | already present |
| liblz4 | liblz4-dev | |
| libzstd | libzstd-dev | |
| libudev | libudev-dev | |
| libkeyutils | libkeyutils-dev | |
| libaio.h | libaio-dev | needed later |
The magick command to resolve all of this, also ncurses which is needed to fine-tune the kernel:
apt-get install -y \
pkg-config \
libblkid-dev \
uuid-dev \
liburcu-dev \
libsodium-dev \
zlib1g-dev \
liblz4-dev \
libzstd-dev \
libudev-dev \
libkeyutils-dev \
libaio-dev \
ncurses-dev \
libncurses-dev
To compile bcache-tools use a non-root user:
# as non-root!
cd
cd kustomkernel # or whatever your git clone dir is
cd bcachefs-tools/
make deb
If all went well, the output files appear in the parent directory:
shrew@antares:~/kustomkernel/bcachefs-tools$ ll ..
total 11924
drwxr-xr-x 1 shrew shrew 582 Dec 27 21:46 bcachefs
drwxr-xr-x 1 shrew shrew 2336 Dec 27 23:24 bcachefs-tools
-rw-r--r-- 1 shrew shrew 3995 Dec 27 23:24 bcachefs-tools_1.0.8-2~bpo8+1_amd64.build
-rw-r--r-- 1 shrew shrew 6226 Dec 27 23:24 bcachefs-tools_1.0.8-2~bpo8+1_amd64.buildinfo
-rw-r--r-- 1 shrew shrew 1456 Dec 27 23:24 bcachefs-tools_1.0.8-2~bpo8+1_amd64.changes
-rw-r--r-- 1 shrew shrew 656296 Dec 27 23:24 bcachefs-tools_1.0.8-2~bpo8+1_amd64.deb
-rw-r--r-- 1 shrew shrew 11534244 Dec 27 23:24 bcachefs-tools-dbgsym_1.0.8-2~bpo8+1_amd64.deb
LINK I was mostly following this tutorial on how to compile a kernel.
LINK This one is useful as well and is about bcachefs specifically.
Step 1. Get the current config
# as non-root!
cd
cd kustomkernel # or whatever your git clone dir is
cp /boot/config-5.10.0-20-amd64 bcachefs/.config
Step 2. Fine tune the kernel config
cd bcachefs/
make clean # just in case, to start from clean state
make olddefconfig # takes the old .config as a base and adds new kernel options with their defaults
make menuconfig # the actual command to fine-tune the kernel settings
I ran into a problem:
shrew@antares:~/kustomkernel/bcachefs$ make menuconfig
* Unable to find the ncurses package.
* Install ncurses (ncurses-devel or libncurses-dev
* depending on your distribution).
* You may also need to install pkg-config to find the
* ncurses installed in a non-default location.
to fix it:
pkg-config ncurses #pkg-config finds and links commands that are not where the OS expects them to be
#
# alternatively fix it manually:
# ln -s `which ncurses6-config` /usr/bin/ncurses
Step 3. Run make menuconfig , and set the following
* The signature checking certificates cause issues so must be disabled, you can double-check in the .config file directly:
# CONFIG_TRUSTED_KEY
# CONFIG_SYSTEM_TRUSTED_KEYRING
# CONFIG_SYSTEM_TRUSTED_KEYS=""
LINK Good video on kernel configuration by MentalOutlaw: “Tips for customizing your Kernel"
Step 4. Prepare NIC drivers
We have two NIC cards:
$ lspci | egrep Ethernet
00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (Lewisville) (rev 04)
03:05.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8169 PCI Gigabit Ethernet Controller (rev 10)
The onboard NIC is Intel 82579LM which did not work for me so using the Realtek RTL8169 one
LINK The official install guide for the Intel e1000e drivers
To avoid problems during make install like these below:
RTL8169 PCI RTL8169 PCI RTL8169 PCIW: Possible missing firmware /lib/firmware/rtl_nic/rtl8168e-2.fw for module r8169
RTL8169 PCI RTL8169 PCI RTL8169 PCIW: Possible missing firmware /lib/firmware/rtl_nic/rtl8168e-3.fw for module r8169
…
The workaround is to get linux-firmware and copy the whole rtl_nic dir and i915 into the /lib/firmware
git clone https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
# as root, we need write permissions to /lib/*
cp -r linux-firmware/rtl_nic/ /lib/firmware/
cp -r linux-firmware/i915/ /lib/firmware/
NOTE: because in Step 3. we set the Realtek firmware to be compiled into the kernel directly, it will not show up on the list of loaded modules when you run lsmod
Step 5. Compile!
Here you can use the root user;
cd
cd kustomkernel
cd bcachefs
make -j 4 # or use as many cores as you have
make modules_install
make install
update-initramfs -c -k all
In less than two hours you will have your kernel compiled!
That's it!
After reboot simply check you are using the new kernel with uname -r
uname -r
6.1.0+