Why would someone want to have a custom kernel? Well, maybe you like the cutting-edge features or maybe you want to hack on it! Anyway, this post explains step-by-step, how to download, build and install your custom kernel on Fedora. I’ll be building kernel from the mainline tree for i686.
Warning: Keep in mind that if something goes wrong you might end up irreversibly damaging your system! Always keep a fail-safe kernel to boot to, just in case!
1. Getting the kernel tree
Linux kernel tree is developed using git revision control system. There are a LOT of different versions and different trees of the kernel maintained by various people. The development tree is linux-next, Linus’ mainline is called simply linux, there is also linux-mm which had a similar purpose as linux-next today. You need to pick one and clone it locally. In this how-to, I’ll stick with the linux tree from Linus that is at least a tiny bit more stable than linux-next. Use the following to get the source:
2. Patching the source
Since this is really bleeding-edge code, there might be some problems with compilation or other bugs. Now is the time to patch the tree to resolve all these issues. Also if you want to hack a little and do some of your own changes to the kernel, now is the time! Don’t be afraid, it’s not that hard …
3. Configure the kernel
Kernel is a pretty big piece of software and it provides a shitload of configuration options. Various limits and settings can be adjusted in this phase. You can also decide, what parts of kernel such as what drivers will be included in your build. Like I said, there is a lot of options and a couple of ways of setting them:
Sometimes, the kernel is built with an option that it saves it’s configuration
/proc/config.gz . If this is your case, you can copy it inside the tree
make oldconfig . This will ask only for the new features, that were
not present in the previous version.
On Fedora, the configuration of currently installed kernels can be found in
4. Build it
When you’re done configuring, you can advance to the build. The only advice I can give you here to take advantage of -j option that make offers if you’re on a system with multiple cores. To build the kernel using 2 jobs per core on a dual-core processor use:
It will significantly improve the build times. Either way, it will take some time to build, so it’s time to get a coffee!
Result of successful build should be a bzImage located in
arch/i386/boot/bzImage and a bunch of built
(kernel object). It’s vital to point out, that bzImage isn’t just a
bzip2-compressed kernel object. It’s a specific bootable file format, that
contains compressed kernel code along with some boot code (like a stub for
decompressing the kernel etc).
To install the new kernel, rename and copy the bzImage to boot and install the modules by writing:
The modules will be installed to
/lib/modules . Also a file called
System.map will be created in the root of kernel source tree which is a
symbol look-up table for kernel
debugging. You can place it into
/boot along with the image:
The file contents looks like this:
When all the files are in place, you need to generate the initial ramdisk ( initramfs). The initial filesystem that is created in RAM is there to make some preparations before the real root partition is mounted. For instance if you’re root is on a RAID or LVM, you’ll need to pre-load some drivers etc. It usually just loads the block device modules necessary to mount the root.
There’s an utility called dracut, that will generate this for you.
This will generate the image and store it into
/boot/initramfs-_kernelrelease_.img . To inspect the file use
7. Bootloader Settings
In the final step, before you can actually boot the new kernel is to configure your bootloader and tell it that the new kernel is there. There was a transition between Fedora 15 and Fedora 16 from GRUB 0.97 (nowdays known as grub-legacy) to new GRUB2 so I’ll explain both.
In the old version (which I am currently using on F15) you need to edit the
/boot/grub/menu.lst file and add new entry with paths to your kernel and
initrd. The entry might look like the following:
In grub2 you should be able to do this automatically by this command
After this step you can reboot and let your machine chew on some fresh meat directly from the developers! Probably as fresh as it’ll ever get! Boot up and enjoy :-).