Kernel Compilation
Kernel Compilation guide for the 2.4 series.
Written by Thomas York - straterra@hotmail.com Straterra
Read over the ENTIRE GUIDE at least twice (2x) before trying to compile your first kernel.
Added 2.6 information -- erik
Prequisites
- Download the latest kernel from kernel.org.
- It is HIGHLY recommended that you create a folder just for your new kernel. It can be in your user directory or anywhere else you want it to be.
- You must have the GCC Compiler
- You must have NCurses.
- You must have access as root.
- You must have have a bootloader (grub and lilo, the two most popular, are described below)
- You must be familiar with a text file editor (vi, nano, etc)
Getting Ready to Compile
- Extract the tar.bz2 file by using
tar jxvf linux-VERSION.tar.bz2
- Change into the newly created directory by using the
cd
command. - Run the command
make menuconfig
. This command will open up a semi-graphical menu where you can pick what you want in your kernel. See Kernel Checklist.- NOTE : If you already have a config file, you should instead run the command
make oldconfig
. Make sure that you have placed the config file in/usr/src/linux-VERSION
, and that the config file has been named.config
. - NOTE : When you navigate through the menus, you use the keys 'M' to make the selection a module and 'Y' to compile it into the kernel. The difference is that if you compile it as a module, you can always unload it later. This is ideal if something causes conflicts. For this reason, I prefer to compile as much as possible as modules. It's your kernel, do what YOU want to do. :) Bear in mind that some options MUST be compiled into the kernel statically (not modular) - for example, support for your root filesystem type must be static.
- NOTE : If you are unsure what a certain selection does, you can press the '?' while having the confusing item selected. It is recommended you learn what EVERYTHING does your first time around, whether you will compile it in your not. This allows you to not have to press the '?' key every time..you already learned them! :)
- NOTE : If you already have a config file, you should instead run the command
- When you exit out of menuconfig, it will ask if you want to save. Say YES. This is critical. If you do not answer YES you will have to go back and do it all over again.
Compiling v2.4
make dep
- This will organize all module dependencies.make bzImage
- This option may take a while, depending on how much content you decided to compile directly into the kernel, processor speed, ram, etc..make modules
- Again, if you selected for alot of content to be compiled as modules this may take some time.su
- Enter your root password. This allows you to have the access to install the compiled kernel.make modules_install
- This command will install all of your modules.cp System.map /boot/System.map
- To replace the old System.map file.cp arch/i386/boot/bzImage /boot/bzImage-VERSION
- Replacing the variable VERSION with the version of the 2.4 kernel you compiled.
Compiling v2.6
make
- This will build the kernel (vmlinux), compressed kernel (bzImage), and modules.su
- Enter your root password.make modules_install
- Installs the modules.cp System.map /boot/System.map-VERSON
- Replace VERSION with the kernel version number.cp arch/i386/boot/bzImage /boot/bzImage-VERSION
- Replace VERSION with the kernel version number.
Lilo Configuration
- Edit /etc/lilo.conf. This will open the lilo configuration file for editing.
- Input the following lines at the end of the file, again replacing the variable VERSION with the kernel version, the variable y for the hard drive device location and the variable z for the Linux partition.
- image = /boot/bzImage-VERSION
- root = /dev/hdyz
- label = Linux-VERSION
- read-only
- Save the file and exit.
- Run the command
lilo -v
. This command (re)installed the lilo boot loader using the modified /etc/lilo.conf file. - Hit Alt-Ctrl-Del, or run the command
reboot
orinit 6
. This will switch to runlevel 6 and restart your computer.
Grub Configuration
- Edit /boot/grub/grub.conf OR /boot/grub/menu.lst
- Replace the variable VERSION with the kernel version
- Using grub a device such as /dev/hda1 is not used. Instead a zero indexed system is used (based on all drives grub can see at boot). /dev/hda1 would become (hd0,0), and /dev/hdb3 would become (hd1,2). Note that the root= line is passed to the kernel itself, and is not used by grub - therefore put in the devfs device (/dev/hda1 perhaps)
- First the relevant lines
- title Linux-VERSION
- root (hdx,x)
- kernel /boot/bzImage-VERSION root=/dev/hdxx
- Now a complete one for reference
- default 0
- timeout 30
- splashimage=(hdx,x)/grub/splash.xpm.gz
- title Linux-VERSION
- root (hdx,x)
- kernel /boot/bzImage-VERSION root=/dev/hdxx
- Hit Alt-Ctrl-Del, or run the command
reboot
orinit 6
. This will switch to runlevel 6 and restart your computer.
Post-Compilation
- When the machine reboots, choose the option 'Linux-2.4.x' or 'Linux-2.6.x', where x is your kernel minor version.
- Recompile any software that created a kernel module for your old kernel (nvidia, etc).
NOTES
- If the compilation failed at ANY step, you must run the command 'make clean' while in the directory of the extracted kernel source.
- If you try to boot up your new kernel, and you get errors, you can boot your old kernel using the old option in lilo.
- Make sure to compile in support for your filesystem!
- Historically, the kernel source is extracted to /usr/src/ and a
linux
symlink is made. So you have the following:- /usr/src/linux-2.6.16
- /usr/src/linux -> linux-2.6.16
- This allows you to symlink /boot/System.map and /boot/config right to /usr/src/linux/System.map and /usr/src/linux/.config - this way they are always pointing to the correct file and never have to be replaced. However, neither of these are necessary; a System.map-VERSION file in /boot will work just fine without a symlink to System.map (see http://www.dirac.org/linux/system.map/ for more information).
- Due to stupid users and old distributions replacing (symlinking) /usr/include, the merits of building a kernel in /usr/src are now under fire. It is (and always has been) safe to build a kernel as root in /usr/src, but you should NEVER replace /usr/include.