Featured image of post Ubuntu - Building own Kernel

Ubuntu - Building own Kernel

One of the reasons why I like Ubuntu is it’s simple. Most stuff works out-of-the-box or is configurable pretty easy. So it’s also pretty easy to compile your own kernel.

The reason I wanted to build my own kernel were some issues with the amdgpu graphics card (I ranted about). Since Kernel 4.15 AMD has pushed it’s recent open-source drivers upstream, so I wanted to give it a try.

# In a nutshell

In principle you have to follow those simple steps

  1. Ensure GRUB has a timeout > 0 so you are able to boot an old kernel, in case something went wrong (which will probably the case)
  2. Download kernel sources from kernel.org
  3. Extract the sources into a directory and open a terminal there
  4. Copy current kernel configuration:

With the following command

cp /boot/config-`uname -r` .config
  1. Check current configuration using make localmodconfig
  2. Compile using make -j8 (-j4 for 4 parallel processes instead of 8)
  3. Install by using sudo make modules_install install

# Detailled walkthrough

For now I’m assuming we want to compile the current stable kernel, witch is 4.15.6

  1. Download kernel sources from kernel.org - I won’t post a direct link to a kernel, because that will become outdated the moment you read this
  2. Extract the sources into a directory and change into that directory

I download the file and extract it with tar. For me it was like

mkdir Kernel && cd Kernel
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.15.6.tar.xz
tar xf linux-4.15.6.tar.xz
cd linux-4.15.6
cp /boot/config-`uname -r` .config          # Copy config of the currently used kernel
make localmodconfig                         # Apply configuration which are not set yet

In general it should be save to hit the return key and just use the default values. But keep that in mind, if you run into problems you might have a more detailed look and the options

Now it’s time to compile the kernel. Use -j4 to use 4 threads for building. I in general use up to 16, but that depends on your system. People report in general good results in taking a number between 1x and 2x the number of CPU cores you have. I have 8, so I choose 16, but that’s up to you

make -j16

Now watch the build process and grab a cup of coffee. That might take a while ….

If the build process completes, then run a simply a make modules_install to install the kernel modules and a make install to install the new kernel

sudo make modules_install install

In Ubuntu this triggers a grub-update as well, so it the next time you boot, your new kernel should be selected automatically.

terminal with archy showing the new Kernel version

Nice :-)

Licensed under CC BY-NC-SA 4.0
Last updated on Feb 26, 2018 18:49 UTC