In my first entry i will explain how to compile a Linux kernel. In my case i’ll compile the last stable version of kernel Linux (3.1.3) , in a Debian squeeze with the traditional method. In another entry i will explain the debian way, executing a scripts from the kernel-package. It’s necessary before starting, check your hardware with command utilities like lspci, lsusb, look the directory /proc/cpuinfo for check you cpu architecture and list the modules is loaded with lsmod. This is important collect this information, because for compile a kernel you need to include some devices drivers, supports for any filesystem or any peculiarity of your hardware. There are many features of the kernel configuration that you can install it as a module (M) or built in kernel (*), you can change this with the spacebar. My recommend is if you are not sure, about a feature is included with you hardware make this as module, so the kernel will not consume your system resources.
In this tutorial i’ll show the main settings that you can need for a typical system, for more information you can visit the official site of Linux kernel documentation: http://www.kernel.org/doc/Documentation/ and see the changelog of the Linux version for the new features: http://www.kernel.org/pub/linux/kernel/v3.0/ChangeLog-3.1.3
Well! the game begins:
1.- In the first step we have to install the dependencies, using the package manager:
# aptitude install build-essential libncurses5-dev kernel-package module-init-tools initramfs-tools
2.- Next we will download the kernel Linux 3.1.3 into the directory /usr/src:
# cd /usr/src && wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.3.tar.bz2
3.- Well, now when the download finishes, we have to unpack the source code:
# tar -xjvf linux-3.1.3.tar.bz2
4.- [optional] i recommend copy an old .config file, of another Linux source if you have anyone, in my case is the default kernel of debian installation.
# cp /usr/src/linux-headers-`uname -r`/.config /usr/src/linux-3.1.3/.config
5.- Now we’ll a create a simple menu for configuring our kernel, is necessary change the current directory for the path of the new kernel (/usr/src/linux-3.1.3/).
# make menuconfig
6.- Before start adding configuration, if you follow the step four, you have to load the .config file.
7.- I’ll show any settings that may be interesting:
– General setup -> Local version: This you can add a string for your linux name. In my case i add -krn1:
– General setup -> Initial RAM filesystem and RAM disk: this feature is important to be selected, because we’ll use an initram disk, to load essential modules used by the kernel at the time of booting the system:
– processor type and feature -> There are some important settings like the support of virtualization, symetric multi-processing support…
– Networking support -> Networking option -> TCP/IP support: enable the support for TCP/IP.
– Device drivers -> SCSI device support: enable support for scsi interface.
– Device drivers -> Multiple devices driver support (RAID and LVM): enable the support for raid and lvm disk.
– Filesystems : enable support for different filesystems:
8.- When you finish with your configuration, you can exit and save it.
9.- In this part you have to be patient, we’ll start with the kernel compilation:
# make all
10.-It can take some time, depending on the hardware of your machine. So you can get up from the chair, take some air, make a coffe, call your mother…
11.- When the process of compilation finishes, now we’ll copy the image of our compiled kernel to the /boot directory:
# cp /usr/src/linux-3.1.3/arch/x86/boot/bzImage /boot/bzImage-3.1.3-krn1
12.- Now we’ll install the modules, this part call the depmod script and make the file modules.dep for the dependencies of the modules:
# make modules_install
13.- Next we’ll create an initram filesystem, this command will create and image in the /boot directory:
# update-initramfs -c -k 3.1.3-krn1
14.- Everything is prepared, just need set a new entry on the grub file configuration. It can be different depending of the grub version, grub legacy use /boot/grub/menu.lst, in my case i used grub 2 my configuration file is /boot/grub/grub.cfg:
# vi /boot/grub/grub.cfg
15.- Aaaaand we can restart our system, boot and enjoy with the new kernel:
That’s it!!! I hope this tutorial has helped you!! bye bye!!
One thought on “How to compile a Linux kernel”
good job, man!! See you later!!