This report describes detail on how to compile kernel on Ubuntu.
This report can also be read online via: https://hackmd.io/@0xff07/rJaQvcGW0
uname -a
outputdmesg
Clone Linus' tree (kernel/git/torvalds/linux.git
). In kernel.org there are 3 remotes listed in the Clone section. I chose the one from Google source (https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git), as I think less people would use it and may be faster to clone.
Install the build dependencies. I'm using Ubuntu 22.04. On Ubuntu, the apt
tool has ability to resolve the build dependencies from source package. This however requires enabling source packages channels from the source list. To do this, edit the /etc/apt/source.list
:
Uncomment (by removing the #
in the beginning) the deb-src
lines and run apt update
. Note that proper privilege may be needed for editing the file.
After the apt update
, install the build dependencies:
According to BuildYourOwnKernel in Ubuntu community WiKi this may not be enough. There are other package that may be needed:
The make menuconfig
could be used for building kernel. But for Ubuntu configuration, there may need some tweaks.
/boot
directoryThe /boot
directory contains configuration for the current kernel. I used as a starting point:
Now there's a basic configuration. Run the menuconfig
:
Some options in Ubuntu kernel configuration are configured specifically for Debian packaging the kernel binary. Those options may lead to error during mainline kernel compilation, as the mainline kernel tree is no Debian source package. Those options needs to be removed.
First, scroll down to the Cryptographic API
, then Certificates for signature checking
. There should be a line that looks like this in the menuconfig:
This is the path of the key file used by Canoncial. The debian
directory in the path is specific for Debian packaging and doesn't exist in the mainline kernel.
Press enter on this option, and remove the line. It should looks like this:
Another file that needs to be removed is:
Remove the path as well. It should now looks like this:
Save the configuration by navigating bottom tabs to < Save >
, and then select < Exit >
in the bottom.
This is a very standard make
. I tee
the build log into another file:
The next step would be installing the modules. This however comes with a catch. If I install all modules without stripping them, the size of initrd.image
would explode and is unable to boot. So I stripped the module while installing:
Finally, install the kernel:
Instead of modifying the /etc/default/grub
, I use grub-reboot
the set the next boot entry. Pass what menu entry should be selected in the next boot:
And the reboot:
After reboot, confirm kernel version using uname
:
It shows the following
Or using dmesg
In the beginning, it shows: