Compile Linux Kernel
Most Linux distros ship with a longterm kernel that can be quite old. If you happen to buy new hardware the driver support can be troublesome.
So in order to get things like network interfaces, wifi, bluetooth, audio etc. working you might have to build the kernel yourself or switch to a rolling release distro.
Install Build Dependencies
Before you can build the kernel you have to install some dependencies.
apt install -y build-essential make libncurses-dev wget bzip2 bc chrpath gawk texinfo libsdl1.2-dev whiptail diffstat cpio libssl-dev flex bison libelf-dev
Start by creating a directory for the kernel build.
mkdir -p ~/build/kernel cd ~/build/kernel
Then navigate to https://www.kernel.org in your browser and copy the tarball link for the latest stable kernel.
Download the kernel using wget.
After that extract the kernel.
tar xvf linux-*.tar.xz cd linux-*
The Kernel can be adjusted by many options.
To use the same options as your current distro copy the boot config.
cp -v /boot/config-$(uname -r) .config
Enable new default options by running oldconfig.
yes "" | make oldconfig
If you build the kernel yourself you don’t have the keys to sign it for secure boot, so you have to disable it.
If you had secure boot enabled in the bios you have to disable it there as well.
sed -ri '/CONFIG_SYSTEM_TRUSTED_KEYS/s/=.+/=""/g' .config
As this will be for productive use we disable debug info.
sed -ri '/CONFIG_DEBUG_INFO/s/=.+/=n/g' .config
If you want to change some options now you can run menuconfig otherwise continue with the build.
Compile the kernel with make, depending on your hardware this can take up to multiple hours. On my i9-9900K @5.0GHz it takes 15~ minutes.
make -j $(nproc)
The last step is to install the freshly build kernel into your system.
make modules_install make install update-initramfs -u update-grub reboot
If something goes wrong you can always select to boot another kernel in grub.