Skip to Content

Compiling Kernels 101

d4de's picture


You will need to compile your own kernel for several reasons, either you want to learn more about the process itself, you want to upgrade your kernel itself to patch security measures or you just need to add few modules/options to the kernel to be able to run certain hardware or software.

First things first, you need first to collect information about your hardware and the overall configuration you are using atm, so you don't end up with mis-configured options, or not compiling important modules like file systems you use to on your HDD, for example there is a big difference between compiling a file system support in the kernel itself or as a module. Let's assume you use EXT3 as your currently file system that you actually have your Linux distro installed on, if you compile it as a module you will end up with a dead system, because modules doesn't run at boot time so that's why you need to make sure that you compiled EXT3 in the kernel itself as modules only run if needed not like kernel compiled options which all going to be loaded upon booting your distro. Also you will need to make sure of which protocols you will need to have to be able to have a functioning network connection, for example if you are on a LAN you will just need the basic IPv4 or IPv6 along with other few protocols to be compiled just in case you needed them, however if you are connecting through DSL/ADSL/ADSL2 you will need one of both PPPoE or PPPoA which in this case you need to ask your ISP of which one you are using if you already don't know.

Compiling your own kernel isn't a l337 thing to do, or at least not as I thought about it, however it is a good learning experience and a good thing to know how to do it just in case you needed to do anything related to your kernel.


Let's jump into the process, first you will need to get the kernel source code, which you can get from (Linux-2.6.xx.x.tar.gz)

Put the tarball in /usr/src, and as root unpack it. You will find a symbolic link there named linux, you will have to rename it to whatever other name, then make a new symbolic link to the new unpacked kernel we downloaded earlier by typing ln -s linux-2.6.xx.x linux. It's for programs that depend on kernel headers, so it's not required to be done to be able to compile a kernel successfully.

Now you will have to configure your kernel, and to tell you the truth it's really a tedious thing to do, so I'll not dig deep into this as I'm not that experienced at it after all.

To know which modules you are currently using, like filesystems and device drivers (drivers are compiled as modules in the kernel), just type lsmod, and you will see all the currently used modules that you need to make sure that you install, however you may also need several more modules for future usages, so be very careful at what options and modules you are omitting and including.

Now we are ready to go configure the kernel by changing the active directory to /usr/src/linux (remember we made a symbolic link for it before) and type make menuconfig.

Also if you are not so sure about what you really need, you should also consider this command make oldconfig, this command will load the new kernel configurations with the configs your already have for your installed kernel, so you will just be asked about the new things that came up with the new kernel.

there are several things I've been reading to be looking for to not to do, which are.

* * Compile your harddisk controller and your native filesystem into your kernel, not as modules. * You should check for compiling as modules, vfat fs and ntfs if you are planning on mounting windows partitions. But if you are planning for mounting windows partitions at boot time, you must compile these file systems as kernel options. * Make sure to compile sound card support as a module or you will not be able to use sndconfig at a later time.

I want also to add, if you are looking for some extra speed up you will need to look out for the following,

* * At Code Maturity Level Options, uncheck "Prompt for development and/or incomplete code/drivers"; you need this option only if you are developing or testing something in the kernel. * At General Setup, uncheck "Cpu set support" unless you have more than one processor, dual or quad-core processors count as more than one. * At Block Layer, uncheck everything unless you have disks that are larger in size than 2TB. * At Processor Type and Features, uncheck "Symmetric multi-processing support" unless you have more than one processor, or a Duo or Quad one. Pick the right processor at Processor Family, and the amount of RAM you have at High Memory Support. * At Preemption Model, pick the "Preemptible Kernel (Low Latency Desktop)" option. Finally, check "Preempt the Big Kernel Lock," and at "Timer Frequency" pick 1000Hz. * At Kernel Hacking, uncheck everything if you won't be doing any kernel development.


Now after you configured your kernel, it's time to go for compiling it by typing these commands,

make all make install make modules make modules_install

make install will copy /usr/src/linux/arch/x86/boot/bzImage to /boot/vmlinuz so you will end up with two kernel files, /boot/vmlinuz.old which is your old kernel and /boot/vmlinuz which is your brand new kernel.

Now we will configure your bootloader (either Grub, or lilo) to have the new kernel as an option to boot.

-=- lilo (add these following lines to your /etc/lilo.conf file, then type lilo)

  • first, edit your current image argument to be /boot/vmlinuz.old (remember make install changed your old kernel file to vmlinuz.old)

--- Add this lines ---- image=/boot/vmlinuz label=linux-2.6.xx.x root=/dev/hdax read-only

-=- grub (add these following lines to your /boot/grub/menu.lst file)

  • like we did with the lilo configuration, you have to change the "kernel ..." line to have /boot/vmlinuz.old.

--- Add these lines --- title Slackware, kernel 2.6.xx.x root (hdx,y) kernel /boot/vmlinuz root=/dev/hdax ro quiet splash savedefault boot

Please note that you need to change the 2.6.xx.x to the corresponding kernel version (ex., although you will need to change the (hdx,y) to your correct root HDD and it's partition (ex. (hd0,1))

I hope that this little how-to helped you to know the basics of compiling a kernel.

Dr. Radut | book