Saturday, February 12, 2011

How To Complie Linux Kernel (For Beginners)

Compiling Linux Kernel, according to a popular myth, is a very tough job. Personally I find it really easy and I'll walk you step by step through this process. I am using Fedora 13 KDE for the compilation.

Before building your kernel I would advice you to backup your data and grub.conf.
  1. Download the source from The convention is that that even numbered sources like 2.2, 2.4, 2.6 etc are stable while odd numbered like 2.3 and 2.5 are not suited for production environment. I am using kernel 2.6.37 for this tutorial.
  2. Assuming that you have placed your source on /usr/src/, extract the kernel source form the archive using the following command:
    tar xvjf linux-2.6.37.tar.bz2
  3. Now, it is a good practice to clean the build area before any compilation.
    make mrproper
  4. Let us start with the configuration now. Kernel source comes with several configuration tools to make your life easier. I will use xconfig but a GNOME user might want to go for gconfig.
    make xconfig
  5. Now select the modules and features you want your kernel to have. I would recommend checking Loadable Module Support. I also got rid of all Mac driver since I use a Dell. Likewise you can strip down your kernel easily. Save the file once you are done.
  6. Once we got the .config file we should go to the Makefile and add a customization marker to differentiate my kernel from the default ones. I'll assign a value to the variable EXTRAVERSION in the Makefile. For me it was EXTRAVERSION = -aditya.
  7. Now just run the make command and be patient. It took my machine around 2 hours for the compilation. I am running an Intel Core 2 Duo and 3 Gig of RAM.
  8. Once the kernel is compiled install the modules.
    make modules_install
  9. Now I would copy my kernel and the system map to the /boot.
    cp /usr/src/linux-2.6.37/arch/i386/boot/bzImage /boot/vmlinuz-2.6.37-aditya
    cp /usr/src/linux-2.6.37/ /boot/
  10. Run the new-kernel-pkg to create the list of module dependencies, update grub.conf etc.
    new-kernel-pkg -v --mkinitrd --depmod --install 2.6.37-aditya
And you are done. You actually built a kernel. Now reboot and enjoy it :)

Update: Please check out the comments for some cool tips.

Tuesday, February 1, 2011

Basic System Monitoring Commands

I am going to discuss some basic system monitoring commands here. Nothing big, most of the systems will have it pre-installed.
  • top: Displays pid, user, CPU, physical memory and swap usage in real time. You can press M - to sort by memory, S - to sort by time, P - to sort by CPU interactively. You can also press u and k to check out user processes and kill one respectively.
  • ps: It shows a list of processes. Use option -A for the entire list, -ef to get a detailed view and -u for user processes.
  • vmstat: It provides statistics for processors, memory, swap, I/O and CPU.
  • df: This is used to get information about the file system. It'll show you the size, used space, available space, used %, and mount information.
  • du: It is used to check out the size of files. It goes recursively if you do not specify the file name.
  • iostat: It provides the information about the Kernel version, average cpu usage and hardware devices. You might need to install sysstat package for this.
  • who and w: Provides information regarding the number of people logged in. w provides more detailed report.