Skip to main content

Kernel

Compile the Linux kernel

Tested on Ubuntu 20.04.

# Fetch and unpack a source tree
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.16.3.tar.xz
tar -xavf linux-*.tar.xz
cd linux-5.16.3

# Build dependencies
sudo apt install git fakeroot build-essential ncurses-dev xz-utils \
libssl-dev bc flex libelf-dev bison

make menuconfig # configure (or: cp /boot/config-$(uname -r) .config && make olddefconfig)
make -j4 # build, using 4 jobs
sudo make modules_install
sudo make install

# Generate the initramfs for the version you just built, then update the bootloader
sudo update-initramfs -c -k 5.16.3
sudo update-grub

sudo reboot
uname -mrs # confirm the new kernel is running

The version passed to update-initramfs -k must match the kernel you built (5.16.3 here), not some other installed version — otherwise GRUB boots an image with no matching initramfs.

Buildroot

An alternative that builds a whole minimal system, not just the kernel:

wget https://buildroot.org/downloads/buildroot-2021.02.8.tar.gz
tar -xavf buildroot-*.tar.gz
cd buildroot-*
make menuconfig
make

See the Buildroot minimal system page for a worked STM32MP example.

Yocto host tools

A Yocto/BitBake build aborts early if required host tools are missing:

ERROR: The following required tools (as specified by HOSTTOOLS) appear to be
unavailable in PATH ...: pzstd zstd
sudo apt install -y zstd liblz4-tool
bitbake core-image-minimal

More Yocto notes are in the Yocto section.