Compile Linux kernel

Getting sources

To get main repo kernel

Default kernel is located here

git clone git://

There is whole list of different kernels maintainer ones and much more.

some distros have their own kernels. Here whole list of kernels based on ubuntu version

And also there is little different native kernel building ways for some distros


Easyes way startup config is just to get whatever you running now. If you hw works good with current distro then use current kernel config its is stored in procfs /proc/config.gz. Lets go to our kernel repo and do

zcat /proc/config.gz > .config

now you are ready to compile kernel that will work at begining

Making yout own config

When you making you own optimised config you need to check your current hardware settup. If you whant minimal kernel there is two options. Just remove hardware that will be newer used. Like if you have have laptop only with intel video card then everything that realted to other video cards could be removed. Second approach is to make only bare minimum without kernel modules. Here is interesting. You get you runnung kernel. And plug all deiveces that you whant to work. Drivers will be autoloaded for this devices and you staticly compile them in. And you will able to run your stuff only with staticly compiled kernel without loadable modules.

List all loaded modules


See all conntected USB devices


See all PCI devices and modules that they are using

lspci -k

This bare minimum of command that you whant to run to start modifing your kernel.


Run to configure kernel

make menuconfig

config is saved in .config file. And now we are ready to compile our first kernel



It depends from distro to distro expected way how to install new/fresh/clean kernel


Install modules. They all will go /lib/modules/your kernel version

make modules_install

Compy compiled kernel to boot directory

cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux318

Create initram image

mkinitcpio -k <kernelversion> -g /boot/initramfs-<file name>.img

All of this should be enought to run kernel with qemu

Linux patches


Linux security enhancments

Latest patches could be downloaded from

Apply patch

cd linux-4.7.10
patch -p1 < ../grsecurity-3.1-4.7.10-201610222037.patch

Should work without troubles


MAC based securty mechanism