mkinitrd, with notes for LILO and GRUB.
1. Before you start
- Work as
rootor usesudowhere required. - Keep at least one working kernel in the bootloader (do not replace the only one).
- Make sure you have free space (a few GB in
/usr/srcand/boot). - Note the current kernel:
uname -r
uname -m
2. Required packages
Install build tools and base libraries. Package names may vary.
Typical packages
gcc,make,binutilsbc,bison,flexopenssl-devel/libssl-develfutils,pahole(for BTF)perl,python(some targets/scripts)ncurses-devel/libncurses-dev(formenuconfig)
Useful tools
wgetorcurlto download sourcesxz/tarto extract archivesgitif you build from kernel.org repositorymkinitrd(Slackware) to create initrd for the generic kernel
3. Get the kernel sources
You can use your distro sources or download the official tarball. Example with tarball:
cd /usr/src
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.x.y.tar.xz
tar -xf linux-6.x.y.tar.xz
ln -sfn linux-6.x.y linux
cd linux
Replace 6.x.y with the version you want to compile.
4. Backup the current configuration
The safest way is to start from the current kernel configuration.
zcat /proc/config.gz > .config
If /proc/config.gz does not exist, try the distro file:
cp /boot/config-$(uname -r) .config
cp .config .config.backup-$(date +%F)
5. Configure the kernel
- Update the old configuration for new sources:
make oldconfig
If you prefer automatic defaults for new options:
make olddefconfig
- Open the text configurator:
make menuconfig
Check especially:
- Disk/controller drivers (SATA/NVMe)
- Root filesystem (ext4, xfs, btrfs, etc.)
- EFI/UEFI support if used
- Network (LAN/Wi-Fi)
- CPU microarchitecture (do not overdo if you want compatibility)
6. Build the kernel and modules
Clean (only if you are starting from a previously used tree) and build:
make -j"$(nproc)"
Build and install modules into /lib/modules/<version>:
make modules_install
7. Install the kernel
Install kernel, System.map, and config into /boot:
make install
On some distros make install also updates the bootloader automatically; on others it does not.
Verify what was created:
ls -lh /boot
ls -lh /lib/modules | tail
8. Create initramfs (if needed)
On Slackware, if you use a generic kernel (recommended), you must create the initrd for the new kernel.
Slackware (mkinitrd)
mkinitrd -c -k <new-kernel-version> -f ext4 -r /dev/sdXY -m ahci:ext4
Adjust filesystem, root device, and modules to your real values.
For a more precise command it is also recommended to use:
/usr/share/mkinitrd/mkinitrd_command_generator.sh -r
9. Update the bootloader
Do not remove the previous kernel entry. Add or regenerate while keeping at least one fallback entry.
GRUB
grub-mkconfig -o /boot/grub/grub.cfg
LILO (still common on Slackware)
Edit /etc/lilo.conf adding a new image and then:
lilo -v
lilo after changes, the system may still point to the old kernel or not boot the new entry.
10. Reboot and verify
- Reboot the system.
- Select the new kernel from the bootloader.
- After login verify:
uname -r
dmesg | less
lsmod | head
Check network, audio, filesystems, video drivers, and main services.
11. Rollback procedure (if something goes wrong)
- Reboot.
- Select the previous kernel from the bootloader.
- Fix the configuration and recompile, or remove the new entry from the bootloader.
/boot.
12. Practical Slackware note
On Slackware it is often better to:
- Start from the config of the installed huge/generic kernel.
- Use a generic kernel +
initrdfor daily use. - Update
/etc/lilo.confcarefully (or GRUB if used). - Keep a “rescue” entry or the old kernel.
Final checklist
[ ] Sources downloaded/extracted
[ ] .config copied from current kernel
[ ] make oldconfig / menuconfig completed
[ ] make && make modules_install && make install
[ ] initramfs created (if required)
[ ] bootloader updated
[ ] old kernel kept as fallback
[ ] reboot and tests completed