Quick & Dirty Tutorial on Linux Kernel Compilation

So do you want to compile your own kernel? do you want to have a lean kernel? Well good news. this will be quick and dirty tutorial of doing just that. now I will say this, this is going to be somewhat hard simply because I don’t know your hardware, and all hardware of course is different but similar. HOWEVER chances are you are using Intel as your CPU. and hope you have Intel NICs or Intel Wi-Fi cards cause that process will make the headache less painful. anyways let’s continue.


This Tutorial should work for all Distros. However I am doing this on Gentoo.

Let’s begin. I am going to get my Kernel version from my Package Manager but however in your case you will want to come to this website to do this.

Download the latest kernel tarball. which as of writing this is kernel 4.12.7 from this site. Kernel.org now we are going to unpack this. if you are using GNOME like I am just click on the tarball and it will unpack itself in the directory. if not just use from the command line. open up a terminal.

chances are your downloaded tarball is in your downloads folder so type this into the command line.

x = "extract"
p = "keep permissions"
f = “file name type of archive”

everything should be like so.


This is the difficult part. and the reason why is because I don’t know what hardware you have but chances are everything is working on your system right now. so to make it easy for yourself. take the kernel config from your current kernel, copy it into the new kernel directory then we’re going to compile it with those settings. Like so

#This process will take a lot of time depending the hardware. but onces this is done you will have a brand new kernel installed.

Congratulations you’ve compiled your own kernel.

14 Likes

Just a heads up,

Compiling kernel on a broadwell i3 @ 2.1 GHz, 2c/4t takes about ~3 hours.

1 Like

it depends on a lot of factors. how much stuff you have enabled within the kernel. and how many things you modulize. I personally run a module free system and just built any required firmware into the Kernel. my kernel compilations take about 45 minutes to an hour.

but knowing how regular distros are populated to “just work” I could see it taking 3 hours. but then again it depends on the hardware. if you are doing this with a Quad-core this could be much faster. on Laptops not so much.

an hour? jesus.

my 4c/8t laptop can get it done in under 15 minutes though i do run a very lean kernel and make it very device specific

1 Like

my laptop is 2c/4t Haswell i3. I try my best to turn off a bunch of crap I don’t know what it does or doesn’t use. also no modules what so ever. everything is built into the kernel.

Many distros/setups don’t have a kernel .config in /boot but include it embedded in the kernel itself. You can try zcat /proc/config.gz > config.
Another very nice trick is to use make localmodconfig. It basically creates a kernel that only has currently used stuff enabled. Hence it’s a quick and dirty way to test a new kernel easily but won’t necessarily work if you later connect some new gadget unto your PC.
Personally I went balls deep in and installed Gentoo and manually configured the kernel. make menuconfig and make nconfig have a nice search feature.

that would also work. however that feature would have to be enabled within the kernel to work. if you use GRUB which I’m kinda confident everyone and their mother uses GRUB. it will work. but that method also works too.

I have to say, you’ve made me curious.

Why do you think someone who doesn’t know what ls does or how to unpack an archive using tar would need or want to compile their own kernel?

cause not everyone knows BASH… and to assume people know how to do everything on Linux is dumb.

Also this is the problem with the Linux community. we’ve been using Linux for years so it comes easy to us, so we get frustrated when others don’t pick it up fast. but we were all in that predicament of not knowing anything about it prior to use at one point.

All fine and well, but I still can’t see who that person is who doesn’t know bash (as you put it) but wants to compile their own kernel with the distro stock kernel config.

To save time I normally use a Debian Testing Kernel as a base and make the changes I want before compiling.

This was just a quick thing. But I’ve gotten to the point where I wasted time configuring my own kernel for a few hours. So now every time I upgrade to the latest kernel I just transfer the config files and recompile. Also I no longer use kernel modules. I just build things into the kernel

1 Like

cause knowledge is good, mate-o.

1 Like

A noob. Someone who’s still learning the basics and wants to try doing it out of curiosity.

yeah I had a lot of stuff. :upside_down_face: