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
Works like a charm, thanks!
You may want to add ‘bc’ to the list of packages for apt-get install.
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.
How about ‘make modules’ ?
Hello, there is no need for ‘make modules’. ‘make’ itself builds kernel and modules by default. Type ‘make help’ for further details.
That shows how many years ago I compiled my last kernel!
/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
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).
Run
make modules
before
make modules_install
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.
By doing like this, I got a 18GB sized kernel. Original 4.19.06 kernel is 240 MB.
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.
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).
Sure, you can