Skip to content

About

Script to install the Linux kernel from source on Debian-based distributions, for all architectures.

Topics

Resources

Stars

26 stars

Watchers

2 watching

Forks

Latest commit

 

History

82 Commits

Folders and files

Repository files navigation

kernel-installer

Automatic install script for The Linux kernel

Inspired by LinuxKernelBuild

GitHub release licence Bash

Script to install the latest [stable/mainline/longterm] kernel from source on Debian-based distributions and the Fedora/RHEL family.

kernel-installer Image

Dependencies

Will be installed when running script.

# Debian/Ubuntu
wget curl git rsync fakeroot build-essential libncurses-dev xz-utils libssl-dev bc lz4 libelf-dev flex bison
# Fedora/RHEL
wget curl git rsync ca-certificates procps-ng findutils which diffutils hostname bc binutils bison dwarves elfutils-libelf-devel flex gcc make openssl openssl-devel perl python3 ncurses-devel cpio kmod xz lz4 rpm-build dracut grubby

Notes

lz4 compression support (ZRAM_BACKEND_LZ4) [Y/n/?] y
lz4hc compression support (ZRAM_BACKEND_LZ4HC) [Y/n/?] y
zstd compression support (ZRAM_BACKEND_ZSTD) [Y/n/?] y
deflate compression support (ZRAM_BACKEND_DEFLATE) [Y/n/?] y
842 compression support (ZRAM_BACKEND_842) [Y/n/?] y
lzo and lzo-rle compression support (ZRAM_BACKEND_LZO) [Y/n/?] y
Default zram compressor
  1. lzo-rle (ZRAM_DEF_COMP_LZORLE)
  2. lzo (ZRAM_DEF_COMP_LZO)
  3. lz4 (ZRAM_DEF_COMP_LZ4) (NEW)
  4. lz4hc (ZRAM_DEF_COMP_LZ4HC) (NEW)
> 5. zstd (ZRAM_DEF_COMP_ZSTD)
  6. deflate (ZRAM_DEF_COMP_DEFLATE) (NEW)
  7. 842 (ZRAM_DEF_COMP_842) (NEW)

Download the script

Quick install with default options:

With Curl:

curl -sSL https://github.com/tmiland/kernel-installer/raw/main/kernel_installer.sh | bash || exit 0

With Wget:

wget -qO - https://github.com/tmiland/kernel-installer/raw/main/kernel_installer.sh | bash || exit 0

When run outside a git checkout, a pinned and checksum-verified copy of the function library (src/slib.sh) is fetched automatically.

For latest release

curl -s https://api.github.com/repos/tmiland/kernel-installer/releases/latest \
| grep "browser_download_url.*sh" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -

For main branch

wget https://github.com/tmiland/kernel-installer/raw/main/kernel_installer.sh

Set execute permission:

chmod +x kernel_installer.sh

For usage, run:

./kernel_installer.sh -h

Help output

If called without arguments, installs stable kernel using /opt/linux

--help                 |-h   display this help and exit
--kernel               |-k   kernel version of choice
--stable               |-s   stable kernel version 6.15.6
--mainline             |-m   mainline kernel version 6.16-rc6
--longterm             |-l   longterm kernel version 6.12.38
--dir                  |-d   install directory
--kexec                |-x   load new kernel without reboot
--config               |-c   set configuration target
--custom-config        |-cc  set custom configuration directive, can be used multiple times
--verbose              |-v   increase verbosity
--get-verified-tarball |-gvt cryptographically verify kernel tarball
--nproc                |-n   set the number of processing units to use
--enable-debug-info    |-edi enable debug info
--lowlatency           |-low convert generic config to lowlatency
--list-installed       |-li  list installed kernels
--default-compression  |-dc  select default compression algorithm
--changelog            |-cl  view changelog for kernel version
--update               |-upd check for script update
--uninstall            |-u   uninstall kernel (use with -k option)

To use opt --kernel:

./kernel_installer.sh --kernel 5.17.8

Else use:

./kernel_installer.sh --stable, --mainline or --longterm separately

To use --dir opt:

./kernel_installer.sh --dir /path/to/dir

To load kernel without reboot:

./kernel_installer.sh --kexec

To use --config:

./kernel_installer.sh --config menuconfig

default is olddefconfig

Configuration targets

config          - Update current config utilising a line-oriented program
nconfig         - Update current config utilising a ncurses menu based program
menuconfig      - Update current config utilising a menu based program
xconfig         - Update current config utilising a QT based front-end
gconfig         - Update current config utilising a GTK based front-end
oldconfig       - Update current config utilising a provided .config as base
localmodconfig  - Update current config disabling modules not loaded
localyesconfig  - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig       - New config with default from ARCH supplied defconfig
savedefconfig   - Save current config as ./defconfig (minimal config)
allnoconfig     - New config where all options are answered with no
allyesconfig    - New config where all options are accepted with yes
allmodconfig    - New config selecting modules when possible
alldefconfig    - New config with all symbols set to default
randconfig      - New config with random answer to all options
listnewconfig   - List new options
olddefconfig    - Same as silentoldconfig but sets new symbols to their default value
kvmconfig       - Enable additional options for guest kernel support
tinyconfig      - Configure the tiniest possible kernel

Custom configuration directives

In order to enable specific kernel configs, one can use --custom-config like the following example:

./kernel_installer.sh --custom-config "scripts/config --set-val CONFIG_DM_VDO m"

The directive must be a scripts/config command; raw CONFIG_* assignments (e.g. CONFIG_DM_VDO=y) are not accepted.

Note that --custom-config can be used multiple times like:

./kernel_installer.sh --custom-config "scripts/config --set-val CONFIG_DM_VDO m" --custom-config "scripts/config --set-val CONFIG_KERNEL_ZSTD y"

To use --get-verified-tarball:

./kernel_installer.sh --get-verified-tarball

Used together:

./kernel_installer.sh --stable --config menuconfig --kexec --dir /path/to/dir --get-verified-tarball

Watch install log:

tail -f ./kernel_installer.log

Note: you will need to run this script as root

If root password is not set, type:

sudo passwd root

Then:

su root

Full write-up on the blog: https://tmiland.com/kernel-installer/

Uninstall kernel

To uninstall previously installed kernel:

./kernel_installer.sh --uninstall --kernel 5.17.7
  • You will be prompted with a yes/no answer

Testing

Tested and working on: Debian 12/13, Ubuntu 22.04/24.04 and Fedora 44 (see test-install.yml)

Maintenance

Updating the vendored slib

src/slib.sh is a curated subset of virtualmin/slib (tracked via tmiland/slib). Updates are two-phase, and CI enforces the second one on main:

# Phase 1 - vendor the new file (defaults to tmiland/slib@master)
scripts/update-slib.sh
git add src/slib.sh && git commit -m 'chore: update vendored slib.sh' && git push

# Phase 2 - pin the pushed commit (updates SLIB_REV / SLIB_SHA256)
scripts/update-slib.sh --finalize <commit>
git add kernel_installer.sh && git commit -m 'chore: bump slib pin' && git push
  • Use --source virtualmin/slib to pull upstream directly. Sync your fork first with gh repo sync tmiland/slib -b master.
  • Sources contain extra Virtualmin-only helpers and are not lint-clean as-is (e.g. #!/bin/sh shebang); the vendored copy is a trimmed, lint-clean subset. Review git diff src/slib.sh and the helper's shellcheck output before committing.
  • Until phase 2 lands on main, the slib pin CI job fails (that is the reminder).

Feature request and bug reports

Donations

Buy Me A Coffee

  • PayPal me
  • [BTC] : 33mjmoPxqfXnWNsvy8gvMZrrcG3gEa3YDM

Disclaimer

*** Use at own risk ***

License

MIT License Image

MIT License

About

Script to install the Linux kernel from source on Debian-based distributions, for all architectures.

Topics

Resources

Stars

26 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages