Home > Guides > Linux Development > Building the Linux Kernel (Ubuntu)

Building the Linux Kernel (Ubuntu)

Introduction

These are my notes on how to build your own Linux kernel for Ubuntu, as the information online is scattered all over the place and dated. Fortunately, Canonical recently followed suit and it is now possible to simply build a mainline Linux kernel, rather than having to build Canonical's fork. While this may be useful if you need more recents drivers, because drivers such as amdgpu are typically behind on Ubuntu, this guide is targeted at users who want to either write their own drivers or modify existing drivers in the Linux kernel.

Building

Copy the kernel configuration from an existing Ubuntu installation:

cp -v /boot/config-$(uname -r) .config

Update the kernel configuration to be compatible with the forked Linux kernel tree:

make olddefconfig

Build the Linux kernel and the kernel modules (the number after -j depends on how many CPU cores/threads you have and want to use):

make -j16

Install the kernel modules:

sudo make INSTALL_MOD_STRIP=1 modules_install

Install the Linux kernel (this should also (re)build the initramfs and update the GRUB configuration file):

sudo make install

Reboot your system:

sudo reboot

GRUB should now present you with the option to boot the newly installed kernel.

Tips & Tricks

The commands that get passed to the kernel by GRUB during boot are located in /etc/default/grub. You can modify the kernel command line in /etc/default/grub, then you can run the following to update the GRUB configuration file:

sudo update-grub

If you want to rebuild the initramfs, you can run the following:

sudo update-initramfs -u

If you like my work or if my work has been useful to you in any way, then feel free to donate me a cup of coffee. Any donation is much appreciated!