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:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
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:
$ make config # Go through each and every option by hand $ make defconfig # Use the default config for your architecture $ make menuconfig # Edit the config with ncurses gui $ make gconfig # Editing with gtk GUI app
Sometimes, the kernel is built with an option that it saves it’s configuration in
/proc/config.gz. If this is your case, you can copy it inside the tree and use
make oldconfig. This will ask only for the new features, that were not present in the previous version.
$ zcat /proc/config.gz > .config $ make oldconfig
On Fedora, the configuration of currently installed kernels can be found in the
$ ll /boot/config* -rw-r--r--. 1 root root 123540 Mar 20 17:31 /boot/config-126.96.36.199-1.fc15.i686 -rw-r--r--. 1 root root 125193 Apr 21 15:54 /boot/config-188.8.131.52-6.fc15.i686 -rw-r--r--. 1 root root 125204 May 8 14:23 /boot/config-184.108.40.206-2.fc15.i686
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:
$ make -j4
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 modules *.ko (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:
# cp arch/i386/boot/bzImage "/boot/vmlinuz-"`make kernelrelease` # make modules_install
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:
# cp System.map "/boot/System.map-"`make kernelrelease`
The file contents looks like this:
$ head System.map 00000000 A VDSO32_PRELINK 00000040 A VDSO32_vsyscall_eh_frame_size 000001d5 A kexec_control_code_size 00000400 A VDSO32_sigreturn 0000040c A VDSO32_rt_sigreturn 00000414 A VDSO32_vsyscall 00000424 A VDSO32_SYSENTER_RETURN 00400000 A phys_startup_32 c0400000 T _text c0400000 T startup_32
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.
# dracut "" `make kernelrelease`
This will generate the image and store it into
/boot/initramfs-kernelrelease.img. To inspect the file use
# lsinitrd /boot/initramfs-kernelrelease.img
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:
title Fedora (220.127.116.11-3.fc15.i686) root (hd0,0) kernel /boot/vmlinuz-3.1.0-rc7 ro root=UUID=58042206-7ffe-4285-8a07-a1874d5a70d2 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=cz-us-qwertz rhgb quiet initrd /boot/initramfs-3.1.0-rc7.img
In grub2 you should be able to do this automatically by this command
# grub2-mkconfig -o /boot/grub2/grub.cfg
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 ;-).
- Love R., Linux Kernel Development, Addison-Wesley, 2010.
- Dracut manual
- Building a custom kernel @ fedoraproject.org
This is a little walk-through the whole build process of Ogre 3D rendering engine. It’s primarily for users of Fedora GNU/Linux distribution or any similar distro that uses rpms and yum. I chose the variant using cmake, so first thing you want to do is install cmake.
$ su -c 'yum install cmake cmake-gui'
After that there are also some prerequisites, that you need to install. For the Cg package you’ll need to enable rpmfusion nonfree repositary by writing
$ su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'
Then install the dependencies using
$ sudo yum install gcc-c++ libXaw-devel freetype-devel freeimage-devel \ zziplib-devel boost-devel ois-devel Cg doxygen \ cppunit-devel
Some of them are optional, but I like to install them all, just in case. Since the hard-drive space is no longer an issue, it could save you from having to build it all over again. After that proceed to downloading the latest version of Ogre3d source and unpack it somewhere.
$ cd ~/Downloads $ tar xjf ogre_src_v1-7-3.tar.bz2
This will extract the sources into a new directory. Let’s rename it to
source. Then we’ll need another directory where all the binaries will be places. Let’s call it
build. After that run
$ mv ogre_src_v1-7-3/ source/ $ mkdir build $ cmake-gui
In the gui set both paths to the source and to the build directory and hit Configure button, leave the defaults (Unix Makefiles and Use default native compilers).
Check the Advanced and Grouped check-boxes and make sure you have installed everything you might need. If you compile ogre without some features here, you’ll need to do it all over again (I did it 4 times when I compiled Ogre for the first time). You should have installed zzip, zlib, freeimage, freetype, boost, opengl, X11, and ois. If you don’t, I highly recommend to install those libs and hit configure again. When you’re done, hit Generate.
At this point, we’re done with the cmake, you can close the window and get back to your terminal window. Now we proceed to the building process itself. Change to the
build/ directory and run
make to compile Ogre3D and wait.
$ cd build $ make
There will be percentage coming up as the library builds. It takes (on my machine) a solid half-hour to build, so feel free to go get some coffee. The only thing left is installing the compiled library to your system using the classic
$ su -c 'make install'
Enjoy your Ogre!