[root@rhce-ryanrudolf]# rm -rf / 2> /dev/null

things I break/fix for fun and learning

Jan 10, 2019 - 3 minute read - Comments

Compiling Linux Kernel 5

Linux kernel 5.0 RC1 has been released last Jan07. After several days of deciding if I should give it a shot, finally I had the time to do it on my machine. It’s been a while since I’ve compiled a kernel from source and this is a good learning experience to refresh that knowledge. Currently I am running kernel 4.19.13-300, about 2 revisions behind of the latest kernel. Kernel 5.0 is also known as kernel 4.21.

Steps in compiling kernel -

  1. Download the tarball from kernel.org -

    wget https://git.kernel.org/torvalds/t/linux-5.0-rc1.tar.gz
  2. Once the download is complete, extract the tarball -

    tar xvzf linux-5.0-rc1.tar.gz
  3. Change into the directory of the tarball -

    cd linux-5.0-rc1
  4. Copy the running kernel config -

    cp /boot/config.4.19.13-300.fc29.x86_64 .config
  5. Time to build! Use make help for the different options.

  6. For my environment, I use make oldconfig

  7. Once completed, it’s time to build the compressed kernel image using make bzImage. This will take a while depending on the speed of the computer, from minutes to several hours.

  8. Next is to build the modules using make modules. This will take a while also, depending on the speed of the computer, from minutes to several hours.

  9. Once everything is done, it’s time to install the modules. As root user -

    make modules_install
  10. And finally install the kernel. As root user -

    make install
  11. Next step is to generate grub entries for the new kernel. As root user -

    grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
  12. And finally, have grub use the new kernel as the default boot entry. As root user -

    grub2-set-default 0
  13. Reboot and profit!

All in all, the whole process took about 3.5hrs. I’m compiling it on a 2nd Gen Core-i5 2540M, 16GB RAM and SSD. While this is a good learning experience, I need to devote at least 3.5hrs if ever there’s a new kernel available. Not to mention that the whole time, my laptop temps are in the 70C range! I don’t have that luxury, and I don’t want to shorten the lifespan of my laptop by exposing it to high temperatures in a prolonged time. So instead of compiling from sources, I’ve decided to use one of the repositories of Fedora.

Fedora Vanilla Kernel Repositories

  1. Download the repository and save them to /etc/yum.repos.d. As root -

    curl -s https://repos.fedorapeople.org/repos/thl/kernel-vanilla.repo > /etc/yum.repos.d/kernel-vanilla.repo
  2. Enable and install the repo that contains the mainline kernel. As root -

    dnf --enablerepo=kernel-vanilla-mainline update
  3. Reboot and profit! This is now how it looks like -

    rhce-ryanrudolf@x220-ryanrudolf tech-and-finance]$ uname -srv
    Linux 5.0.0-0.rc1.git0.1.vanilla.knurd.1.fc29.x86_64 #1 SMP Mon Jan 7 17:42:54 UTC 2019
    [rhce-ryanrudolf@x220-ryanrudolf tech-and-finance]$ 

My system now shows I am running the latest Linux kernel 5.0-rc1. Whenever there is an update (RC2, RC3, etc etc) on the mainline kernel, I can just easily use the package manager instead of devoting 3.5hrs for manual compiling.

Like this page? Share it!