genkernel
Build an initial RAM disk and kernel
TLDR
Automatically compile and install a generic kernel
Build and install the bzImage|initramfs|kernel|ramdisk only
Apply changes to the kernel configuration before compiling and installing
Generate a kernel with a custom name
Use a kernel source outside the default directory /usr/src/linux
SYNOPSIS
genkernel [options] <action>
PARAMETERS
all
Builds the kernel, modules, and a corresponding initramfs. This is the most commonly used action for a complete build.
bzImage
Builds only the kernel bzImage (the compressed kernel executable) without modules or initramfs.
initramfs
Builds only the initramfs from the currently installed kernel modules. Useful for updating the initramfs without recompiling the kernel.
install
Installs the previously built kernel, modules, and initramfs to the appropriate locations (e.g., /boot and /lib/modules).
clean
Cleans the genkernel build directories and temporary files generated during previous runs.
--menuconfig
Launches make menuconfig interactively before compiling the kernel, allowing custom kernel configuration. The resulting .config is then used for the build.
--oldconfig
Uses the existing .config file and prompts for new kernel options, similar to make oldconfig. Useful for minor updates to an existing configuration.
--mrproper
Performs a full clean of the kernel source tree before compilation, equivalent to make mrproper. This removes all generated files, including configuration files.
--kernel-config=<path>
Specifies an alternative kernel configuration file to use instead of the default. This allows building with a custom .config from a specific location.
--mountboot
Automatically mounts the /boot partition if it's not already mounted before attempting to install the kernel and initramfs.
--symlink
Creates symbolic links for the newly installed kernel and initramfs (e.g., vmlinuz-genkernel-x86 and initramfs-genkernel-x86), making it easier to update bootloader configurations.
--ramdisk-modules
Includes all compiled kernel modules in the initramfs. This creates a larger initramfs but ensures maximum compatibility during early boot, especially for diverse hardware.
--hostonly
Includes only modules necessary for the current host's detected hardware in the initramfs. This typically results in a much smaller and faster-loading initramfs.
--lvm
Adds support for Logical Volume Manager (LVM2) to the initramfs, essential for booting from LVM-managed root filesystems.
--luks
Adds support for Linux Unified Key Setup (LUKS) encryption to the initramfs, required for booting from encrypted root filesystems.
--bootloader
Attempts to update the bootloader configuration (e.g., GRUB) after kernel installation, making the new kernel bootable.
--no-install
Prevents genkernel from installing the compiled kernel and modules after a successful build. Useful for testing or manual installation.
--no-clean
Prevents genkernel from cleaning its temporary build directories after completion, useful for debugging build issues.
--kernel-sources=<path>
Specifies the path to the Linux kernel source tree to be used for compilation. Defaults to /usr/src/linux.
--compress-initramfs=<compressor>
Specifies the compression algorithm for the initramfs (e.g., gzip, bzip2, lzma, xz, zstd). Defaults vary based on system configuration.
--force
Forces certain actions, such as overwriting existing files without prompting.
--verbose
Increases the verbosity of the output, showing more details about the compilation process.
--help
Displays a help message with available commands and options.
DESCRIPTION
genkernel is a powerful utility designed specifically for Gentoo Linux to simplify and automate the process of compiling the Linux kernel, its modules, and a corresponding initramfs (initial RAM filesystem). Its primary goal is to provide a 'just works' kernel for a wide range of hardware, reducing the need for users to manually configure complex kernel options via make menuconfig. This automation makes system upgrades and hardware changes significantly easier, as it ensures all necessary drivers for common hardware are included.
While it aims for a generic kernel, genkernel offers numerous options to fine-tune the build, allowing users to include support for specific features like LVM, LUKS encryption, software RAID, or network booting, directly within the initramfs. It handles the full compilation process, from cleaning the source tree to installing the compiled kernel and modules, and can even update bootloader configurations.
CAVEATS
genkernel is primarily designed for Gentoo Linux and might not be directly applicable or easily portable to other distributions. While it simplifies kernel compilation, the resulting 'generic' kernel can sometimes be larger than a hand-tuned one, potentially consuming more disk space and memory. It relies heavily on the kernel source tree being correctly installed and managed, typically via Gentoo's emerge and eselect kernel tools. For highly specific or bleeding-edge hardware, manual kernel configuration via --menuconfig might still be necessary to ensure optimal driver selection or performance.
DEFAULT KERNEL CONFIGURATION
When run without a specified kernel configuration (e.g., --menuconfig or --kernel-config), genkernel typically starts with a default configuration. This default is often based on the kernel running on the system or a generic configuration provided by Gentoo, which genkernel then modifies by auto-detecting hardware and enabling essential drivers for system functionality.
INITRAMFS IMPORTANCE
The initramfs generated by genkernel is a critical component for many modern Linux systems. It provides a minimal root filesystem in RAM that contains necessary modules and utilities (like LVM, LUKS, or network drivers) to mount the actual root filesystem. This allows booting from complex storage configurations or network locations before the main system is fully available, offering significant flexibility for diverse system setups.
INTEGRATION WITH GENTOO
genkernel is deeply integrated into the Gentoo ecosystem. It expects kernel sources to be managed via emerge (e.g., sys-kernel/gentoo-sources) and typically uses default paths like /usr/src/linux for source code. Its installation process aligns with Gentoo's standards, placing compiled artifacts in well-defined locations, facilitating seamless system updates and bootloader interaction within a Gentoo environment.
HISTORY
genkernel emerged as a crucial utility for Gentoo Linux users, specifically to address the complexity of manual kernel compilation which is a hallmark of Gentoo. In the early days of Gentoo, users were expected to compile their kernels from scratch, a process that, while offering ultimate control, could be daunting and time-consuming. genkernel was developed to automate this process, making Gentoo more accessible while retaining its flexibility. It has since evolved to include various features for initramfs generation and bootloader integration, remaining a core component of the Gentoo ecosystem, simplifying updates and system maintenance for a wide range of users.
SEE ALSO
kernel(7), make(1), grub-mkconfig(8), emerge(1), eselect(1)