Configuration#
The Linux kernel provides a vast of options that can be selected. Many of them are meant to provide a wide range of hardware support and software features. Configuring interactively with make nconfig will need a lot of time and research.
“It’s a common misconception to think that there is a separate Linux kernel code base for an enterprise-class server, a data center, a workstation, and a tiny, embedded Linux device – no, they all use the very same unified Linux kernel source! Thus, carefully configuring the kernel for a particular use case (server, desktop, embedded, or hybrid/custom) is a powerful feature and a requirement.” – Kaiwan N. Billimoria in Linux Kernel Programming
For a minimal kernel, the best approach is to make allnoconfig to deactivate any option. This will probably result in a kernel booting right into a kernel panic, because essential drivers are missing.
Personally, I use a laptop with Fedora Silverblue compiling everything in a Toolbox container. This is my initial setup
toolbox create styxos
toolbox enter styxos
sudo dnf install gcc make flex bison elfutils-libelf-devel openssl-devel bc debootstrap qemu-system-x86 qemu-img ncurses-devel
mkdir -p styxos/kernel
cd styxos
git submodule add --depth 1 https://github.com/torvalds/linux src
git fetch origin tag v6.19 --depth 1
git checkout tags/v6.19You can update your kernel version by just git checkout a more recent tag and recompile.
Enabling Modules Step-by-Step#
I created the following list of options along try-and-error compiling and booting into a Qemu virtual machine. The resulting kernel is able to handle virtual network, block devices and the attached /var file system.
cd kernel/src
make allnoconfig
# Core & Exec
./scripts/config --enable 64BIT
./scripts/config --enable NAMESPACES
./scripts/config --enable CGROUPS
./scripts/config --enable PRINTK
./scripts/config --enable BLK_DEV_INITRD
./scripts/config --enable RD_GZIP
./scripts/config --enable BINFMT_ELF
./scripts/config --enable BINFMT_SCRIPT
# Driver Infrastructure
./scripts/config --enable TTY
./scripts/config --enable SERIAL_8250
./scripts/config --enable SERIAL_8250_CONSOLE
./scripts/config --enable DEVTMPFS
./scripts/config --enable DEVTMPFS_MOUNT
# Network Stack (Essential for TCP/IP and Sockets)
./scripts/config --enable NET
./scripts/config --enable INET
./scripts/config --enable UNIX
./scripts/config --enable PACKET
# Bus & Virtio for Qemu
./scripts/config --enable PCI
./scripts/config --enable PCI_MSI
./scripts/config --enable VIRTIO_MENU
./scripts/config --enable VIRTIO_PCI
./scripts/config --enable NETDEVICES
./scripts/config --enable ETHERNET
./scripts/config --enable VIRTIO_NET
# File system
./scripts/config --enable BLOCK
./scripts/config --enable BLK_DEV
./scripts/config --enable VIRTIO_BLK
./scripts/config --enable EXT4_FS
# Hypervisor Features (KVM)
./scripts/config --enable HYPERVISOR_GUEST
./scripts/config --enable VIRTUALIZATION
./scripts/config --enable PARAVIRT
./scripts/config --enable PARAVIRT_CLOCK
make olddefconfig
make -j$(nproc)