Kernel Builder
The Kernel Builder is a application written in rust that scans for available kernel sources in a configured directory and allows you to select which kernel to build, as well as install the modules, copy the compiled kernel to the boot partition, as well as generating the necessary initramfs.
Prerequisites
- Basic knowledge of kernel configuration and compilation
- to use the initramfs generation you have to enable the
dracutfeature and dracut has to be installed on your system
Installation
or install it with cargo install from crates.io
You also need a config.toml with the needed paths configured in $HOME/.config/kernel-builder/config.toml:
= "/boot/vmlinuz-linux"
= "/boot/initramfs-linux.img" # Optional, only needed if `dracut` feature is enabled
= "/usr/src/.config"
= "/usr/src"
= true # Optional, backup current kernel before installing new one
= "last" # Optional, suffix for backup kernel (default: "last")
= 3 # Optional, cleanup old kernels keeping N newest + current
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
kernel |
Path | Required | Path to install the kernel image |
initramfs |
Path | Optional | Path for initramfs (requires dracut feature) |
kernel-config |
Path | Required | Path to your kernel .config file |
kernel-src |
Path | Required | Directory containing kernel sources |
keep-last-kernel |
bool | false |
Backup current kernel before installing new one |
last-kernel-suffix |
string | "last" |
Suffix for backed up kernel |
cleanup-keep-count |
number | Optional | Cleanup old kernels keeping N newest + current |
verbose |
bool | false |
Enable debug logging (via --verbose CLI flag) |
Usage
If correctly setup you should just run kernel-builder, it should ask
for root permission if not already run as root. You can override options by
setting environment variables prefixed with KB_. For example to override the
kernel path:
KB_KERNEL=/boot/efi/vmlinuz-linux-lts
CLI Options
)
Gentoo Configuration
Since kernel-builder manages kernel sources in /usr/src, you may want to
prevent Portage from automatically removing old kernel sources during
emerge --depclean.
Option 1: Use Portage Sets (Recommended)
Create a portage set to manage kernel sources separately from @world:
# Create the sets directory and file
Now update kernel sources with:
And emerge -u @world won't touch kernel sources.
Option 2: Exclude from Depclean
Add to /etc/portage/make.conf:
EMERGE_DEFAULT_OPTS="--exclude sys-kernel/gentoo-sources"
This prevents emerge --depclean from removing any gentoo-sources version.
Combined Approach (Most Control)
Use both options above for maximum control:
emerge -u @worldupdates everything except kernel sourcesemerge @kernelsupdates kernel sources when you decideemerge --depcleanwon't touch kernel sources
Contributing
There is still room for improvements, so if you would like to contribute to the project, please feel free to submit a pull request or open an issue.
License
This script is released under the EUPL License. See the LICENSE file for more information.