Kernel SliTaz 5.1

Building your own Linux kernel for SliTaz: to trim it for an old machine, or to turn on an option or a driver the stock kernel lacks. The new kernel is installed next to the stock one, which stays in the boot menu as a way back.

SliTaz 5.1 ships two kernel families:

The i486 kernels of both families are built for 686 class processors (Pentium Pro and later). The steps below are the same on i486 and x86_64: build on the system you will boot, or in a SliTaz chroot of the same architecture.

Before you build: is it already there?

A missing driver is often just a module package that is not installed. Look for the module by its file name:

$ spk-search rtw88_8821ce.ko --file

and install the package it names with spk-add. To see whether an option is set in the running kernel:

$ zcat /proc/config.gz | grep 'CONFIG_NTFS3_FS[= ]'
CONFIG_NTFS3_FS=m

=y is built into the kernel, =m is a module, and "is not set" means it is not there: then a new kernel is the way.

What you need

# spk-add slitaz-toolchain gcc83 perl bc flex bison xz elfutils-dev openssl-dev libcrypto ncursesw-dev

The default compiler of SliTaz 5.1 is GCC 6.3, too old for some options of Linux 6.12: with it, the configuration step quietly turns off the return thunk mitigation (CONFIG_MITIGATION_RETHUNK). The official kernel is built with GCC 8.3 from the gcc83 package, called as gcc-83: pass it to every make command below with CC=gcc-83 HOSTCC=gcc-83. elfutils-dev is needed by objtool, a tool the x86_64 build runs; ncursesw-dev by make menuconfig.

Get the source

Build as a normal user, in your home. Take the kernel.org release of the version you run (here 6.12.115, see uname -r) or a newer 6.12:

$ mkdir -p ~/kernel && cd ~/kernel
$ wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.12.115.tar.xz
$ tar -xJf linux-6.12.115.tar.xz
$ cd linux-6.12.115

The plain kernel.org source boots SliTaz. The official package adds a few small patches of its own (for example root=<device>:<directory> to boot from a subdirectory); they are in the stuff/ directory of the linux-lts receipt if you want them.

The configuration

Start from the configuration of the running kernel, kept in /proc/config.gz (the linux-lts-debug package also installs it as /boot/config-<version>):

$ zcat /proc/config.gz > .config

Then give your kernel its own name. Open .config and change the CONFIG_LOCALVERSION line, for example:

CONFIG_LOCALVERSION="-custom"

The release becomes 6.12.115-custom: its modules go into /lib/modules/6.12.115-custom and never mix with those of the stock kernel in /lib/modules/6.12.115-slitaz. Keep slitaz out of that name: when linux-lts is upgraded, its install script rewrites the boot entries whose kernel name contains the old -slitaz version.

Update the configuration for this source, then change what you want:

$ make CC=gcc-83 HOSTCC=gcc-83 olddefconfig
$ make CC=gcc-83 HOSTCC=gcc-83 menuconfig

make kernelrelease prints the name the kernel will have.

A kernel for this machine only

localmodconfig keeps only the modules loaded right now, and drops the rest: the stock configuration has about 1900 modules, a laptop uses 100 to 150 of them. The build is much faster and the kernel smaller. Plug in and use everything first (USB key, webcam, printer, sound, wifi), or its driver goes away:

$ lsmod | wc -l
$ yes '' | make CC=gcc-83 HOSTCC=gcc-83 localmodconfig

yes '' answers the default to each question about options that are new in this source.

No initramfs

An installed SliTaz boots its kernel without an initramfs: the kernel itself must mount the root partition. The driver of the disk (SATA_AHCI, BLK_DEV_NVME, BLK_DEV_SD...) and the filesystem of the root partition (EXT4_FS...) must stay built in, =y, never =m. The stock configuration has them built in; keep it that way. For the same reason a VirtIO disk in a virtual machine needs CONFIG_VIRTIO_BLK=y and CONFIG_VIRTIO_PCI=y (both are modules in the stock kernel).

The live system is different: its rootfs.gz is an initramfs the kernel unpacks, so keep CONFIG_BLK_DEV_INITRD=y and the compression of the ISO you boot (CONFIG_RD_LZMA, CONFIG_RD_ZSTD).

Build

$ make -j$(nproc) CC=gcc-83 HOSTCC=gcc-83 bzImage modules

-j runs one job per processor. Count from a few minutes with localmodconfig on a recent machine to hours for the full configuration on an old one.

Install it next to the stock kernel

As root, from the source directory:

# make CC=gcc-83 HOSTCC=gcc-83 modules_install
# cp arch/x86/boot/bzImage /boot/vmlinuz-6.12.115-custom

modules_install copies the modules to /lib/modules/6.12.115-custom and runs depmod. Do not name your kernel /boot/bzImage: a linux-lts upgrade replaces that file.

The GRUB entry

The installer writes /boot/grub/grub.cfg itself, on BIOS and UEFI machines alike; there is no grub-mkconfig step. Open it as root and copy the SliTaz entry, which looks like this:

menuentry "SliTaz Cooking (Kernel 6.12.115)" {
	linux /boot/vmlinuz-6.12.115-slitaz root=PARTUUID=... rootwait video=-32
}

Paste the copy below it, then change its title and the kernel file name, and keep the rest of the linux line as it is:

menuentry "SliTaz, custom kernel" {
	linux /boot/vmlinuz-6.12.115-custom root=PARTUUID=... rootwait video=-32
}

The stock entry stays first and boots by default, until you trust the new kernel: then move your entry to the top, or set default=1.

A system installed with Syslinux has /boot/syslinux/syslinux.cfg instead: copy its LABEL slitaz block the same way.

Check it

After the reboot:

$ uname -r
6.12.115-custom
$ dmesg | grep -i -E 'error|fail' | head

The 3.16 kernel of core-retro SliTaz 4.0

On an i486 system, the linux-source package installs get-linux-source. As root, it downloads the 3.16 source, applies the SliTaz patches and configuration into /usr/src/linux-3.16.55, and prints the next steps (make menuconfig, make bzImage modules). The same rules apply: a name of its own, built-in disk and filesystem drivers, an entry next to the stock one.

Troubleshooting

"Kernel panic - not syncing: VFS: Unable to mount root fs": the disk driver or the filesystem of the root partition is a module, or missing. Set it to =y and build again. Boot the stock entry meanwhile.

The new kernel boots but a device does not work: its module was not loaded when you ran localmodconfig. Set it to m with make menuconfig, build and install the modules again.

"gelf.h: No such file or directory" or "libelf.h" during the build: install elfutils-dev. "openssl/opensslv.h": install openssl-dev.

menuconfig says it cannot find ncurses: install ncursesw-dev.

The wifi or graphics card needs firmware: the firmware lives in /lib/firmware, shared by every kernel. Nothing to do if it works with the stock kernel.