Just a quick 'n dirty tutorial about Kali Linux Kernel building
Hey there :)
So, you want to be included in the leet-boys club, and build your own kernel ?. Okay, we can do that.
Here I'm using the the sources from Kali that's included in the repo's, and I would recommend you do the same.
We won't be going into building from pristine sources from kernel.org or including custom patches to our kernel,, that's another tutorial, here we keep it as simple as possible, so everybody can follow along.
I assume you're running this on some kind of Kali host environment, either a workstation, be it installed or a virtual host. It's perfectly fine to run it in a virtual host, it's just takes a while longer, depending on the machine specs.
So, let's start with installing some build-dependencies. Fire up a terminal, and let's rock :)
apt install build-essential libncurses5-dev fakeroot xz-utils
Next, we need to figure out what kernel version we need. Let's build one like the one we have, just for the fun of it. So grab the kernel sources from apt.
apt-cache search linux-source
#Mine's linux-source-5.6, as seen here
linux-source-5.6 - Linux kernel source for version 5.6
#Install
apt install linux-source-5.6
When it's done, it should have made a folder under /usr/src/, mine's /usr/src/linux-config-5.6. In that folder is the source, compressed as a xz. We need to move it to another folder, mine's /root/kernel
#uncompress the xz archive
unxz linux-source-5.6.tar.xz
#uncompress TAR archive
tar -xaf linux-source-5.6
#move sources into /root/kernel/
mv linux-source-5.6 /root/kernel/
We're there..almost. So jump into /root/kernel/linux-source-5.6, and check everything's there. Here's my folder.
/kernel/linux-source-5.6# ls
arch certs CREDITS Documentation fs
init Kbuild kernel LICENSES Makefile net samples security tools virt
block COPYING crypto drivers include ipc Kconfig lib MAINTAINERS
mm README scripts sound usr
Now, we run make menuconfig
.config - Linux/x86 5.6.14 Kernel Configuration
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌────────────────────────────────── Linux/x86 5.6.14 Kernel Configuration ──────────────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty submenus ----). Highlighted │
│ letters are hotkeys. Pressing <Y> includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> │
│ to exit, <?> for Help, </> for Search. Legend: [*] built-in [ ] excluded <M> module < > module │
│ capable │
│ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ *** Compiler: gcc (Debian 9.3.0-14) 9.3.0 *** │ │
│ │ General setup ---> │ │
│ │ [*] 64-bit kernel │ │
│ │ Processor type and features ---> │ │
│ │ Power management and ACPI options ---> │ │
│ │ Bus options (PCI etc.) ---> │ │
│ │ Binary Emulations ---> │ │
│ │ Firmware Drivers ---> │ │
│ │ [*] Virtualization ---> │ │
│ │ General architecture-dependent options ---> │ │
│ │ [*] Enable loadable module support ---> │ │
│ │ [*] Enable the block layer ---> │ │
│ │ IO Schedulers ---> │ │
│ │ Executable file formats ---> │ │
│ │ Memory Management options ---> │ │
│ │ [*] Networking support ---> │ │
│ │ Device Drivers ---> │ │
│ │ File systems ---> │ │
│ │ Security options ---> │ │
│ └────────────────v(+)───────────────────────────────────────────────────────────────────────────────────┘ │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ <Select> < Exit > < Help > < Save > < Load > │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘
You'll see something like this. This is the bread and butter. It's here we step through the kernel configuration. It will have default settings allready made for us, so simply just accept the defaults the first time, and save the settings in the file called .config
Start the build with
make clean
make deb-pkg LOCALVERSION=-custom KDEB_PKGVERSION=$(make kernelversion)-1
It will take a long time to build, mine took about 7 hours, so sit back and get some coffee, turn on some Netflix. Or maybe go do something else for a while, and come back to it :)
If it completed without errors, you should have some deb files, linux-headers-* and linux-image-*. These are the kernel headers and the kernel itself, so let's install it, and try to boot it.
#install
apt install linux-image-* linux-headers-*
#reboot
reboot
If we're lucky, you should have a booting machine, if not, revert to the old kernel, and try again. Now, CHECK everything works, and when you're sure, clean up the old kernels under /boot.
Happy surfing :)