Copyright (C) 2001, 2002 M K Saravanan Revision History ================ 24th April 2002 - uploaded to my homepage http://www.comp.nus.edu.sg/~mksarav 12th May 2002 - grub configuration details added. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. You can download a copy of the license from http://www.gnu.org/copyleft/fdl.txt ============================================================================== During a chat session, once my friend asked me how to compile a new kernel in a GNU/Linux box for Intel x86 platform. I literally typed the commands needed to fetch the latest kernel from the ftp.kernel.org and install it in a GNU/Linux system. I thought this might be useful for others also and hence modified that slightly to produce this howto. NOTE: Please read this howto till the end before you make any attempt. Where to get the latest kernel? ------------------------------- You can download the latest linux kernel from ftp.kernel.org. Since this is a busy site, consider downloading the kernel from a mirror site nearest to you. Here we assume that you want to download the kernel 2.4.13 from ftp.kernel.org to your home directory (assume: prasanna) cd ~ ftp ftp.kernel.org ftp> cd pub/linux/kernel/v2.4 ftp> bin ftp> get ChangeLog-2.4.13 ftp> get linux-2.4.13.tar.gz ftp> quit Untar the kernel ---------------- Change to your home directory and then unzip the compressed kernel: more ChangeLog-2.4.16 (if you can understand :-) ) cd ~ gunzip linux-2.4.13.tar.gz Login as root (superuser): su - cd /usr/src Check whether linux is a symbolic link to a directory like linux-2.4.2 etc.., if you don't have any sources already in that directory then it will be fine. Else backup your previous linux source directory. pwd /usr/src/ tar xvf ~prasanna/linux-2.4.13.tar will extract into /usr/src/linux (linux will be created automatically) mv linux linux-2.4.13 ln -sf /usr/src/linux-2.4.13 /usr/src/linux i.e. you are creating a symlink to the actual linux-2.4.13 directory. remember now /usr/src/linux is just a symlink. traditionally /usr/include will have C generic header files. but linux compilation needs linux specific header file also so it has it own include directory: /usr/src/linux/include cd /usr/include mv linux linux-old mv asm asm-old mv scsi scsi-old ln -sf /usr/src/linux/include/linux /usr/include/linux ln -sf /usr/src/linux/include/asm-i386 /usr/include/asm ln -sf /usr/src/linux/include/scsi /usr/include/scsi i.e. we now created 3 new symlinks. remember /usr/include/[linux,asm,scsi] are just symlinks. cd /usr/src/linux make mrproper if mrproper fails don't worry go to the next step. make xconfig (make xconfig will need Tcl/Tk and XWindow -- If you want to install from text mode use make menuconfig) Now you have to select whatever options you want. First practice yourself till you are familiar with whatever options you want. Don't forget to read the help message for each of these options. After that save and exit. Now it must have created a file called /usr/src/linux/.config (see .config) now we have finished "make xconfig" step - is it o.k.? this step (xconfig) also create a proper Makefile for further compilation. make dep make clean make bzImage (see I is capital) make modules make modules_install pwd /usr/src/linux If you have a SCSI device, take a backup of old /boot/initrd* (if any). /sbin/mkinitrd /boot/initrd-2.4.13.img 2.4.13 cp arch/i386/boot/bzImage /boot/linux-2.4.13 ----------------------------------------------------------------------------- LILO Users =========== Edit your /etc/lilo.conf (or appropriate boot loader conf file if you are using other than LILO). Add a new entry for the new kernel so that if it fails you can always revert back to the orig. kernel. For e.g. in my lilo.conf, I have just added the following entries: image=/boot/linux-2.4.13 label=linux-2.4.13 read-only root=/dev/hda6 i.e. root= line is same as in your regular kernel option. Now run lilo. Even if you don't change the name of the kernel in your next attempt, you have to run lilo whenever you recompile the kernel. GRUB Users =========== Edit your /boot/grub/grub.conf (assuming grub is installed on /boot). Add a new entry for the new kernel so that if it fails you can always revert back to the orig. kernel. For e.g. in my grub.conf, I have just added the following entries: title linux-2.4.13 root (hd0,1) kernel /vmlinuz-2.4.13 ro root=/dev/hda6 initrd /initrd-2.4.13.img Here /dev/hda2 on the first hard disk (hd0, 1) contains my linux /boot partition (in grub no. starts with 0) and /dev/hda6 contains the root (/) partition. Now run: /sbin/grub-install /dev/hda ------------------------------------------------------------------------------ Reboot and smash your head on the monitor if your new kernel dont boot :-) If you are satisfied with your new kernel now do su - cd /boot mv System.map System.map.old cd /usr/src/linux cp System.map /boot/System.map Remember some modules will work fine only if you compile inside the kernel instead of compiling it as a module. Remember if you have any old .config file, then make mrproper step will delete that also. Incase if you again compile the kernel second time later, before the make mrproper step backup the original .config and after mrproper step, copy the .config again in the same place so that your make xconfig will retain all the old settings and you can change only whatever is new or change that you want. Also go to: http://www.xml.com/ldd/chapter/book/ and read the first 2 chapters compulsorily. I am talking about the latest editon - 2nd edition of the book "Linux Device Drivers by Alessandro Rubini" which contains 2.4.x kernel details. In Chapter-3 read "what is meant by device major number and minor number". Just do ls -l /dev you will see some numbers called major and minor. For creating device files you must know its exact meaning. Usually it will be taught in the UNIX class itself. In case if you don't know the meaning yet, please read that. Onething - don't forget to include proper menu in the make xconfig step to include your ethernet card (for Compex RL2000 - select PCI NE2000) and for 3COM all the menus will be there select whatever you want. Otherwise after reboot your network card won't work. And Finally don't forget to read the "The Linux Kernel HOWTO" at http://www.tldp.org. Feedback -------- Kindly send your feedback to improve this howto to mksarav@mitindia.edu. -------------------------------------------------------------------------------