How to rebuild Linux Kernel

Let me first tell why one should rebuild a Linux Kernel.The main reason was  to optimize the kernel to your environment (hardware and usage patterns). With modern hardware there is rarely a need to recompile unless there is a particular feature of a new kernel that you must have. The performance gains are probably not noticeable unless specific benchmarks are being run.

This said, the newest Linux kernel (2.6.34.1)has noticeable improvements for the typical desktop user as a result of the improved scheduling system in the new kernel. Even for older kernels, rebuilding is often necessary for low memory situations, esoteric hardware, and in cases where every ounce of performance must be extracted.

Download your tarball from the index page at http://kernel.org , which links to the latest versions. If you are using FTP, go to ftp.kernel.org/pub/linux/kernel/[version] — these subdirectories all contain an empty file named LATEST_IS_[version] to help you find the latest. Kernel.org has almost-complete kernel archives back to version 0.99 if you’re feeling really adventurous.

Unpack the tarball in your home directory. If you’re planning to do a lot of compiling and installing kernels (and other good stuff), you may want to read the Note on /usr/src at the bottom of this page first.
         tar xivf linux-2.6.0.tar.bz2

(Replace xivf with xzvf if you downloaded the .gz)

cd into the linux directory. You’ll now need to configure the kernel to select the features you want/need. There are several ways to do this..

make config

Command line questions.

make oldconfig

(Useful only if you kept a .config from a previous kernel build. With the newest kernels, the .config of the currently-running kernel is used by default if it’s available, so you usually won’t need this feature.)

make menuconfig

(ncurses based)

make gconfig

(GTK+ based X-Windows configuration)

make xconfig

(QT based X-Windows configuration)

Now we can build the kernel (for older kernel like 2.4.x first build the dependencies with "make dep").
         make

Wait. When its finished, it will have built both the kernel (bzImage) and the modules (for older kernels like 2.4.x, you need to run "make bzImage ; make modules").

Become root to be able to install modules and kernel. Everything before this point can and should be done as a normal user, there is really no need to be root to compile a kernel. It’s actually a very bad idea to do everything as root because root is too powerful, one single mistake is enough to ruin your system completely.

Install the modules.
         make modules_install

Install the new kernel..
         make install

If your distribution uses lilo:

Edit /etc/lilo.conf, and add these lines…
         image = /boot/vmlinuz2.6.34.1
         label = 2.6.0

Also copy your root=/dev/??? line here too.

Run /sbin/lilo, reboot, and enjoy.

If your distribution uses grub:

Edit /boot/grub/grub.conf:
          title=Linux 2.6.34.1
          root (hd0,1) #  or whatever your current root is
          kernel /boot/vmlinuz-2.6.34.1 root=/dev/hda1 # or whatever…

If you’re using Ubuntu, you will need to edit menu.lst instead of grub.conf

If your menu.lst needs an initrd line, you can generate the necessary info by doing something like

update-initramfs -k 2.6.29.3 -c

update-initramfs seems to be the replacement for mkinitrd (which is mentioned in the "more indepth tutorial" mentioned below.

Most distributions have an installation routine that links a new /boot/vmlinuz-[version] to simply vmlinuz, so you may want to add a stanza like this to grub.conf:
          title=My very latest kernel install
          root (hd0,1) #  or whatever your current root is
          kernel /boot/vmlinuz root=/dev/hda1 # or whatever…

This will let you boot fresh kernels for testing without constantly editing grub.conf.

Note: This will work for lilo, too, but you still have to run /sbin/lilo after every install.

If you get modversion problems (symbols ending in _Rxxxxxxxx), have a look at this question in the linux-kernel mailing list FAQ to solve the problem.

Still not getting it? Try this more indepth tutorial

Note on /usr/src

If you’re just trying out this procedure, do the unpacking and building in your home directory as discussed above. In a professional environment, though, the source would be stored in /usr/src or /usr/local/src, where compiling would also be done. To allow this, and at the same time avoid becoming root for the entire procedure, use your favorite GNOME or KDE utilities to create a group "devel" (or "hack" or whatever) and add yourself to that group. Then change the group owner of /usr/src to the new group and grant write privileges to the group.

That way you can unpack the kernel tarball into /usr/src (or whatever) and configure and build there without doing everything as root. Of course, you’ll still need to sudo or become root when you install the new kernel and edit the lilo/grub configuration files.

This will help keep the kernel source separate from your resume, diary, and jpegs of your Main Squeeze.

Advertisements

About aronnirmal

A student pursuing Masters in Compter Applications. Intrested in Linux, Computer Hardware and networking,eco-enviorment related issues and politics.

Posted on July 20, 2010, in linux, Open source and tagged , . Bookmark the permalink. Comments Off on How to rebuild Linux Kernel.

Comments are closed.

%d bloggers like this: