kernel-builder 0.7.1

Select, build and install kernel version from local sources.
Documentation
kernel-builder-0.7.1 has been yanked.

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 dracut feature and dracut has to be installed on your system

Installation

git clone https://github.com/koopa1338/kernel-builder
cd kernel-builder
cargo install --path .

or install it with cargo install from crates.io

cargo install kernel-builder

You also need a config.toml with the needed paths configured in $HOME/.config/kernel-builder/config.toml:

kernel = "/boot/vmlinuz-linux"
initramfs = "/boot/initramfs-linux.img" # Optional, only needed if `dracut` feature is enabled
kernel-config = "/usr/src/.config"
kernel-src = "/usr/src"
keep-last-kernel = true           # Optional, backup current kernel before installing new one
last-kernel-suffix = "last"      # Optional, suffix for backup kernel (default: "last")
cleanup-keep-count = 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 kernel-builder

CLI Options

kernel-builder [OPTIONS]

Options:
  -v, --verbose      Enable debug logging
      --no-build     Skip kernel build
      --no-modules   Skip installing kernel modules
      --no-initramfs Skip generating initramfs (requires `dracut` feature)
      --menuconfig   Open menuconfig before building
      --replace      Replace current kernel without backup
  -h, --help        Print help
  -V, --version     Print version

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
mkdir -p /etc/portage/sets
echo "sys-kernel/gentoo-sources" > /etc/portage/sets/kernels

Now update kernel sources with:

emerge @kernels

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 @world updates everything except kernel sources
  • emerge @kernels updates kernel sources when you decide
  • emerge --depclean won'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.