Press "Enter" to skip to content

Compile and install latest kernel (5.1.16) on Debian Buster

Hi! Here are my notes on how to compile the latest version of the Linux kernel, at this moment version 5.1.16, on Debian 10 ‘Buster’, from source code. Remember to change versions and/or paths to match your preferences if necessary.

## Download the source code and pgp signature from https://www.kernel.org/
## to a directory of your choice
mkdir -p /usr/src/
cd /usr/src/
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.sign
## Uncompress the source code and check the signature
xz -d -v linux-5.1.16.tar.xz
gpg --verify linux-5.1.16.tar.sign
## Untar the source code and cd into the directory
tar xf linux-5.1.16.tar
cd linux-5.1.16/
## Copy over actual kernel config file and run 'make menuconfig'
cp -v /boot/config-$(uname -r) .config
## Install necessary packages
apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc
make menuconfig
## Go to Cryptographic API  ---> Certificates for signature checking --->
## and leave 'File name or PKCS#11 URI of module signing key' and 
## 'Additional X.509 keys for default system keyring' blank if not
## already blank
## Compile using make or make -j n where n is the number of processors to use
#make
make -j 4
## Install kernel modules
make modules_install
## Optimize and compile new kernel
cd /lib/modules/5.1.16/
find . -name *.ko -exec strip --strip-unneeded {} +
cd /usr/src/linux-5.1.16/
make install
## Done

14 Comments

  1. Mark
    Mark July 14, 2019

    Works like a charm, thanks!

  2. Jürgen S
    Jürgen S September 12, 2019

    You may want to add ‘bc’ to the list of packages for apt-get install.

    • tat0
      tat0 September 15, 2019

      Hi, thanks for the heads up, bc is used during the kernel build to generate time constants in header files, so it should be installed previously if not already in the system. Added bc to the list of packages to install.

  3. Xserty
    Xserty October 20, 2019

    How about ‘make modules’ ?

    • tat0
      tat0 October 21, 2019

      Hello, there is no need for ‘make modules’. ‘make’ itself builds kernel and modules by default. Type ‘make help’ for further details.

      • Xserty
        Xserty October 21, 2019

        That shows how many years ago I compiled my last kernel! 😮

  4. Scott
    Scott December 14, 2019

    /usr/src/linux-5.1.16# make modules_install

    cp: cannot stat ‘./modules.builtin’: No such file or directory
    make: *** [Makefile:1293: _modinst_] Error 1

    • tat0
      tat0 December 22, 2019

      Hi, It seems that you do not have any modules compiled. I would need all the output from previous step (make) to check for any error. If no error in make there is probably some misconfiguration in config step (make menuconfig).

    • Nick
      Nick February 2, 2020

      Run
      make modules
      before
      make modules_install

      • tat0
        tat0 February 3, 2020

        Hi, thanks for pointing this. In theory there is no need for ‘make modules’. ‘make’ itself builds kernel and modules by default. In this case that points to an error during the ‘make’ step. Type ‘make help’ for further details.

  5. Kwai Chang
    Kwai Chang December 22, 2019

    By doing like this, I got a 18GB sized kernel. Original 4.19.06 kernel is 240 MB.

    • tat0
      tat0 January 1, 2020

      Hi, while compiling, it can get even more than 18 GB size but sounds improbable to me to get that much after a successful compilation. Check my numbers after a clean compilation on a Debian Buster vanilla install:


      root@tjure:~# uname -a
      Linux tjure 5.1.16 #1 SMP Mon Jul 8 19:36:07 CEST 2019 x86_64 GNU/Linux
      root@tjure:~# ls -l /boot|grep 5.1.16
      -rw-r--r-- 1 root root 208900 Jul 8 20:53 config-5.1.16
      -rw-r--r-- 1 root root 53111968 Nov 16 21:55 initrd.img-5.1.16
      -rw-r--r-- 1 root root 3510556 Jul 8 20:53 System.map-5.1.16
      -rw-r--r-- 1 root root 5405056 Jul 8 20:53 vmlinuz-5.1.16
      root@tjure:~# ls -lh /boot|grep 5.1.16
      -rw-r--r-- 1 root root 205K Jul 8 20:53 config-5.1.16
      -rw-r--r-- 1 root root 51M Nov 16 21:55 initrd.img-5.1.16
      -rw-r--r-- 1 root root 3.4M Jul 8 20:53 System.map-5.1.16
      -rw-r--r-- 1 root root 5.2M Jul 8 20:53 vmlinuz-5.1.16
      root@tjure:~# du -h --max-depth=1 /lib/modules|grep 5.1.16
      264M /lib/modules/5.1.16
      root@tjure:~# du -h --max-depth=1 /usr/src/linux-5.1.16
      46M /usr/src/linux-5.1.16/Documentation
      31M /usr/src/linux-5.1.16/net
      37M /usr/src/linux-5.1.16/sound
      204K /usr/src/linux-5.1.16/LICENSES
      740K /usr/src/linux-5.1.16/virt
      9.3M /usr/src/linux-5.1.16/kernel
      3.6M /usr/src/linux-5.1.16/crypto
      4.5M /usr/src/linux-5.1.16/scripts
      53M /usr/src/linux-5.1.16/include
      131M /usr/src/linux-5.1.16/arch
      4.9M /usr/src/linux-5.1.16/lib
      52K /usr/src/linux-5.1.16/usr
      196K /usr/src/linux-5.1.16/init
      554M /usr/src/linux-5.1.16/drivers
      40M /usr/src/linux-5.1.16/fs
      2.9M /usr/src/linux-5.1.16/security
      33M /usr/src/linux-5.1.16/tools
      3.8M /usr/src/linux-5.1.16/mm
      68K /usr/src/linux-5.1.16/certs
      1.7M /usr/src/linux-5.1.16/block
      264K /usr/src/linux-5.1.16/ipc
      1.6M /usr/src/linux-5.1.16/samples
      958M /usr/src/linux-5.1.16

      Probably it has not finished compilation successfully or have unused temporally files in folder. Hope this helps.

  6. TinLethax
    TinLethax December 26, 2019

    Hello. I’m new to kernel building and currently running on 5.1.0 . Can I use the “make oldconfig”by using .config from /boot/config-* to build kernel ? Because my kernel is the branch version with some specific drivers (Linux on YogaBook).

    • tat0
      tat0 January 1, 2020

      Sure, you can 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *