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.
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.
--no-auto-key-import and --no-auto-key-retrieve to prevent silent key injectionSYSTEM_TRUSTED_KEYS, SYSTEM_REVOCATION_KEYS, MODULE_SIG_KEY)set -Eeuo pipefail) with ERR, INT, and TERM signal trapsreadlink -f to prevent symlink-based path traversal/boot/config-*), defconfig, localmodconfig, or nonemenuconfig, nconfig, oldconfig, olddefconfig, or skip entirelynproc)LOCALVERSION suffix and KDEB_PKGVERSION override6.15-rc7 automatically use kernel.org /testing directoryAutomatically 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 |
module or builtin for paravirtual driversqemu-guest-agent or open-vm-toolsapt-get -f install fallback after dpkg -iupdate-grub after successful installationlinux-image + linux-headers by default, optionally include linux-libc-dev.deb packagesValidate all inputs, paths, and environment configuration without making any system changes:
sudo DRY_RUN=1 ./debian_kernel_build.sh 6.12.93
sudo)cdn.kernel.orgAll build dependencies are installed automatically by the script:
bcbinutilsbisonbuild-essentialca-certificatescpiodirmngrdpkg-devfakerootflexgitgnupgkmodlibelf-devlibncurses-devlibssl-devopensslpaxctlperlpython3wgetxz-utilszstdOptional:
dwarves(pahole) ยทlz4ยทliblz4-tool
This guide walks you through the entire process. No prior kernel-building experience is required.
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
Visit kernel.org to find the latest stable version (e.g., 6.12.93). You can also use release candidates like 6.15-rc7.
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:
cdn.kernel.org over HTTPS.config from your currently running kernel (/boot/config-*)menuconfig for you to review and customize kernel options โ just save and exit when donemake -j$(nproc) bindeb-pkg).deb packages (linux-image and linux-headers).deb packages are preserved)sudo reboot
After rebooting, confirm the new kernel is active:
uname -r
You should see the version you just built (e.g., 6.12.93).
# Standard interactive build with menuconfig
sudo ./debian_kernel_build.sh 6.12.93
# 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
# 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
# Build a release candidate kernel (automatically uses kernel.org /testing directory)
sudo ./debian_kernel_build.sh 6.15-rc7
# 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
# 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
# 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
All behavior is controlled through environment variables. Every option has a sensible default โ you only need to set the ones you want to change.
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
โโโโโโโโโโโโโโโโโโโ
โ 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
โโโโโโโโโโโโโโโโโโโ
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
kexec automatically. Use a controlled reboot to activate the new kernel.DISABLE_DEBUG_INFO=0 if you need crash analysis, kgdb, BTF, or SystemTap workflows.CONFIG_MODE=olddefconfig and DISABLE_DEBUG_INFO=1 (the default) produces the fastest builds.This script adheres to professional shell scripting standards:
-S style severity levelset -Eeuo pipefail with ERR, INT, and TERM trapsLC_ALL=C for reproducible text parsing across environments2026.06.14-r5 โ Security Audit and Hardeningseed_kernel_config to avoid masking return values.--no-auto-key-import to prevent silent key injection from untrusted sources during OpenPGP signature verification.wget --timeout=60 and --tries=3 to prevent indefinite hangs on slow or unreachable network endpoints during kernel tarball and signature downloads.on_error trap exit code: when the ERR trap fires with exit_code=0 (edge case in complex pipelines), the trap now defaults to exit 1 to prevent silent success.errexit in run_localmodconfig by using set -Ee instead of set -e to keep the error trap active after re-enabling strict mode.LC_ALL=C export early in initialization for reproducible text parsing across different locale environments during build operations.KERNEL_WORKDIR using readlink -f (when available) to resolve symbolic links and prevent path traversal issues in build directory setup.wget -c (continue) flag from signature download to prevent partial or corrupt file reuse during OpenPGP verification.wget --no-hsts flag to avoid unnecessary HSTS database writes during kernel downloads.2026.06.14-r4 โ VM Optimization Auditlocalmodconfig handling so it remains safe under errexit and pipefail.kmod and python3 to the required dependency set for modern kernel package builds.VM_DRIVER_MODE=module|builtin.VIRTIO_MENU and SCSI_LOWLEVEL enablement to improve dependency resolution for VirtIO and VMware SCSI drivers.REFRESH_BOOTLOADER=1 to refresh GRUB when update-grub exists after successful package installation.DRY_RUN=1 support for syntax, path, and argument validation without making system changes.mitigations=off, no unsafe kernel command-line tweaks, and no global scheduler or sysctl tuning.2026.06.14-r3 โ VM Guest Detectionsystemd-detect-virt and DMI/SMBIOS data.virtio-pci, virtio-blk, virtio-scsi, virtio-net, virtio-balloon, virtio-console, virtio-rng, virtio-vsock, virtio-fs, 9p over virtio, and net-failover.vmxnet3, vmw_pvscsi, vmw_balloon, vmw_vmci, VMware VMCI vsock transport, vmwgfx, and vmmouse.VM_DRIVER_MODE=module|builtin.INSTALL_VM_GUEST_TOOLS.2026.06.14-r2 โ Internationalization and RC Support-rcN use the kernel.org /testing directory automatically.KERNEL_WORKDIR validation to avoid accidental root-level or empty-directory operations.dirmngr to dependencies to improve GnuPG WKD/key discovery reliability.localmodconfig pipeline wrapper compatible with pipefail..deb packages while making cleanup path-scoped and safe.2026.06.14-r1 โ Initial Hardened Releaseset -Eeuo pipefail and an ERR trap.flex, bison, dwarves/pahole, dpkg-dev, ca-certificates, gnupg, wget, zstd, and lz4 fallback support./opt/linux cleanup with an isolated build directory per kernel version and timestamp.dpkg filename globs with package discovery from actual build artifacts.apt/dpkg invocation.This project is licensed under the GNU General Public License. See the LICENSE file for details.