DebianKernelBuild

๐Ÿง ALSYUNDAWY Linux Kernel DEB Builder

Production-grade shell script to download, verify, configure, build, and optionally install upstream vanilla Linux kernel Debian packages โ€” fully automated, VM-aware, and security-hardened.

Latest Version ShellCheck Bash Maintenance Status License GitHub Issues GitHub Pull Requests GitHub Stars GitHub Forks GitHub Contributors Donate with PayPal Sponsor with GitHub


โœจ Overview

This script builds an upstream vanilla Linux kernel directly from kernel.org into Debian packages using the in-tree Kbuild target make bindeb-pkg. It handles the entire lifecycle โ€” from downloading and cryptographically verifying the source tarball to configuring, compiling, packaging, and installing the resulting .deb files.

Designed for Debian, Ubuntu, Proxmox VE, and all Debian-based distributions.


๐Ÿš€ Key Features

๐Ÿ” Security and Integrity

โš™๏ธ Build Pipeline

๐Ÿ–ฅ๏ธ VM Guest Optimization

Automatically detects the hypervisor at runtime using systemd-detect-virt and DMI/SMBIOS data, then applies hypervisor-specific kernel configuration:

Hypervisor Detection Kernel Options Enabled
KVM / QEMU / Proxmox kvm, qemu, bochs, proxmox Full VirtIO stack: virtio-pci, virtio-blk, virtio-scsi, virtio-net, virtio-balloon, virtio-console, virtio-input, virtio-rng, virtio-crypto, virtio-vsock, virtio-fs, 9p, net-failover
VMware vmware VMXNET3, PVSCSI, VMware Balloon, VMCI, VMCI vsock, vmwgfx, vmmouse
Generic VM virtualbox, xen, microsoft HYPERVISOR_GUEST, PARAVIRT, PARAVIRT_CLOCK, HIGH_RES_TIMERS, PCI_MSI, VSOCKETS

๐Ÿ“ฆ Package Management

๐Ÿงช Dry-Run Mode

Validate all inputs, paths, and environment configuration without making any system changes:

sudo DRY_RUN=1 ./debian_kernel_build.sh 6.12.93

๐Ÿ“‹ Requirements

All build dependencies are installed automatically by the script:

bc binutils bison build-essential ca-certificates cpio dirmngr dpkg-dev fakeroot flex git gnupg kmod libelf-dev libncurses-dev libssl-dev openssl paxctl perl python3 wget xz-utils zstd

Optional: dwarves (pahole) ยท lz4 ยท liblz4-tool


๐Ÿ“– Quick Start โ€” Step by Step

This guide walks you through the entire process. No prior kernel-building experience is required.

Step 1 โ€” Download the Script

Open a terminal on your Debian-based system and run:

wget https://raw.githubusercontent.com/alsyundawy/DebianKernelBuild/master/debian_kernel_build.sh
chmod +x debian_kernel_build.sh

Step 2 โ€” Choose Your Kernel Version

Visit kernel.org to find the latest stable version (e.g., 6.12.93). You can also use release candidates like 6.15-rc7.

Step 3 โ€” Run the Build

Run the script with sudo and pass the kernel version as the argument:

sudo ./debian_kernel_build.sh 6.12.93

The script will automatically:

  1. Install all required build dependencies via APT (you do not need to install anything manually)
  2. Detect your VM hypervisor (KVM, VMware, etc.) if you are running inside a virtual machine
  3. Install VM guest tools (qemu-guest-agent or open-vm-tools) when a supported hypervisor is detected
  4. Download the kernel source tarball from cdn.kernel.org over HTTPS
  5. Verify the OpenPGP signature to ensure the source has not been tampered with
  6. Extract the source tree into an isolated, timestamped build directory
  7. Seed .config from your currently running kernel (/boot/config-*)
  8. Open menuconfig for you to review and customize kernel options โ€” just save and exit when done
  9. Sanitize the config (disable debug info, clear Debian cert paths, apply VM optimizations)
  10. Compile the kernel using all available CPU cores (make -j$(nproc) bindeb-pkg)
  11. Install the generated .deb packages (linux-image and linux-headers)
  12. Refresh the GRUB bootloader so the new kernel appears in the boot menu
  13. Clean up the source tree and archives (the .deb packages are preserved)

Step 4 โ€” Reboot

sudo reboot

Step 5 โ€” Verify

After rebooting, confirm the new kernel is active:

uname -r

You should see the version you just built (e.g., 6.12.93).


๐Ÿ’ก Usage Examples

Basic Usage

# Standard interactive build with menuconfig
sudo ./debian_kernel_build.sh 6.12.93

Non-Interactive / Automation

# Fully non-interactive build โ€” ideal for CI pipelines or scripted deployments
sudo CONFIG_MODE=olddefconfig INSTALL_AFTER_BUILD=0 ./debian_kernel_build.sh 6.12.93

VM Guest Builds

# VMware guest with modular paravirtual drivers
sudo VM_GUEST_OPTIMIZE=vmware VM_DRIVER_MODE=module ./debian_kernel_build.sh 6.12.93

# KVM/Proxmox guest with built-in drivers and custom kernel suffix
sudo VM_GUEST_OPTIMIZE=kvm VM_DRIVER_MODE=builtin LOCALVERSION=-pvefast ./debian_kernel_build.sh 6.12.93

Release Candidate Kernels

# Build a release candidate kernel (automatically uses kernel.org /testing directory)
sudo ./debian_kernel_build.sh 6.15-rc7

Build Only (No Install)

# Build packages but do not install them, and keep the source tree
sudo INSTALL_AFTER_BUILD=0 CLEANUP_SOURCE=0 ./debian_kernel_build.sh 6.12.93

Testing and Debugging

# Skip OpenPGP verification (use only for emergency testing)
sudo VERIFY_TARBALL=0 ./debian_kernel_build.sh 6.12.93

# Dry-run โ€” validate inputs and environment without making any changes
sudo DRY_RUN=1 ./debian_kernel_build.sh 6.12.93

# Build with debug symbols enabled (for crash analysis, kgdb, BTF, SystemTap)
sudo DISABLE_DEBUG_INFO=0 ./debian_kernel_build.sh 6.12.93

Custom Branding

# Add a custom suffix to the kernel version string
sudo LOCALVERSION=-alsyundawy ./debian_kernel_build.sh 6.12.93

# Override the Debian package version
sudo KDEB_PKGVERSION=1.0-custom ./debian_kernel_build.sh 6.12.93

๐Ÿ”ง Environment Options

All behavior is controlled through environment variables. Every option has a sensible default โ€” you only need to set the ones you want to change.

Build Configuration

Variable Default Description
KERNEL_WORKDIR /opt/linux Base directory for isolated build trees
JOBS $(nproc) Number of parallel make jobs
LOCALVERSION (empty) Custom kernel version suffix (e.g., -alsyundawy)
KDEB_PKGVERSION (empty) Override the Debian package version string

Kernel Configuration

Variable Default Description
CONFIG_SEED running Initial .config source: running ยท defconfig ยท localmodconfig ยท none
CONFIG_MODE menuconfig Configuration frontend: menuconfig ยท nconfig ยท oldconfig ยท olddefconfig ยท none
DISABLE_DEBUG_INFO 1 Disable CONFIG_DEBUG_INFO and BTF to reduce build time and size
SANITIZE_DEBIAN_CERTS 1 Clear Debian-specific certificate paths for vanilla sources

Security and Verification

Variable Default Description
VERIFY_TARBALL 1 Verify OpenPGP signature of the kernel tarball before extraction
GPG_AUTO_LOCATE_KEYS 1 Auto-import kernel.org developer keys via WKD

VM Guest Optimization

Variable Default Description
VM_GUEST_OPTIMIZE auto VM detection mode: auto ยท kvm ยท qemu ยท proxmox ยท vmware ยท generic ยท none
VM_DRIVER_MODE module Paravirtual driver linkage: module (loadable) ยท builtin (compiled-in)
INSTALL_VM_GUEST_TOOLS 1 Auto-install qemu-guest-agent or open-vm-tools when a hypervisor is detected

Installation and Cleanup

Variable Default Description
INSTALL_AFTER_BUILD 1 Automatically install linux-image and linux-headers after build
INSTALL_LIBC_DEV 0 Also install linux-libc-dev from this build
REFRESH_BOOTLOADER 1 Run update-grub after successful package installation
CLEANUP_SOURCE 1 Remove source tree, tarball, and signature after build
DRY_RUN 0 Validate all inputs and environment without making any system changes

๐Ÿ”„ Build Pipeline Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Validate Input  โ”‚  Version format, env vars, boolean checks
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Install Deps    โ”‚  APT packages, optional tools (dwarves, lz4)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Detect VM       โ”‚  systemd-detect-virt + DMI/SMBIOS probing
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Guest Tools     โ”‚  qemu-guest-agent / open-vm-tools (optional)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Download        โ”‚  wget from cdn.kernel.org (HTTPS, timeout, retries)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Verify (GPG)    โ”‚  OpenPGP signature via detached .tar.sign
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Extract         โ”‚  tar -xf into isolated build directory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Seed .config    โ”‚  running kernel / defconfig / localmodconfig
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Config Frontend โ”‚  menuconfig / nconfig / oldconfig / olddefconfig
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Sanitize Config โ”‚  Certs, debug info, VM options, olddefconfig sync
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Build (bindeb)  โ”‚  make -jN bindeb-pkg โ†’ .deb packages
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Install         โ”‚  dpkg -i with auto dependency repair
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Cleanup         โ”‚  Remove source, preserve .deb packages
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Summary         โ”‚  List packages, boot notes, VM recommendations
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ—‘๏ธ Uninstall

The custom kernel is installed as standard Debian packages. You can remove it at any time using APT:

# List all installed kernel packages
dpkg -l | grep linux-image

# Remove a specific kernel version
sudo apt remove --purge linux-image-6.12.93
sudo apt remove --purge linux-headers-6.12.93

# Update the bootloader to remove stale entries
sudo update-grub

โš ๏ธ Important Notes


๐Ÿ›ก๏ธ Code Quality

This script adheres to professional shell scripting standards:


๐Ÿ“ Changelog

2026.06.14-r5 โ€” Security Audit and Hardening

2026.06.14-r4 โ€” VM Optimization Audit

2026.06.14-r3 โ€” VM Guest Detection

2026.06.14-r2 โ€” Internationalization and RC Support

2026.06.14-r1 โ€” Initial Hardened Release


๐Ÿ‘ค Author โ€” HARRY DS ALSYUNDAWY


๐Ÿ“„ License

This project is licensed under the GNU General Public License. See the LICENSE file for details.