Skip to content

Menu

  • Home
  • Sysadmin
  • Debian
  • Security
  • Docker

Blog by Constantin Herold | Theme by ThemeinProgress | Proudly powered by WordPress

Spaaacesysadmin & dev stuff

Compile Linux Kernel

February 23, 2021Debian, Sysadmin Standard
Read time 2 minutes

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

Download Kernel

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.

wget https://cdn.kernel.org/pub/linux/kernel/vx.x/linux-x.x.x.tar.xz

After that extract the kernel.

tar xvf linux-*.tar.xz
cd linux-*

Configure Kernel

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.

make menuconfig

Build Kernel

Compile the kernel with make, depending on your hardware this can take up to 1 hour.

make -j $(nproc)

Install Kernel

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.

Write a Reply or Comment Cancel reply

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

Recent Posts

  • Create SWAP on ZFS ZVOL
  • Raspberry Pi Grafana Kiosk
  • Proxmox Grafana Dashboard
  • Proxmox Full Disk Encryption with SSH Remote Unlock
  • Login Mail Alert Using Rsyslog

Categories

  • Debian
  • Docker
  • Monitoring
  • Personal
  • Proxmox
  • Raspberry Pi
  • Security
  • Sysadmin