The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Поиск:  Каталог документации

Next Previous Contents

2. Quick Steps - Kernel Compile

This section is written by Al Dev (alavoor[AT]yahoo.com) (The latest version of this document is at http://www.milkywaygalaxy.freeservers.com. You may want to check there for changes). Mirror sites are at - angelfire, geocities. These sites have lot of linux goodies and tips.

Kernel re-compile is required in order to make the kernel very lean and which will result in FASTER operating system . It is also required to support any new devices.

2.1 Precautionary Preparations

Before you build kernel, it is a good idea to do a backup of the system. If you had not backed up your system recently then you can do it now. You can use commercial backup tools like BRS Backup-Recovery-Software (also in this page you can find open-source/freeware backup tools listed under 'Backup and Restore Utility'). Backup is just a suggestion and it is not mandatory to do backup before building the Linux kernel.

2.2 Minor Upgrading of Kernel

If you had already built the kernel and you want to upgrade to next patch release, then you can simply copy the existing config file and reuse it. (For example you have built kernel 2.4.19 and want to upgrade to 2.4.20).

For minor upgrades : This step may save you time, if you want to reuse the old settings. Whenever you install the kernel, generally you put the config file in /boot. So, you can use the existing version of config file:


bash# mv /usr/src/linux/.config  /usr/src/linux/.config.save
bash# cp /boot/config-2.4.18-19.8.0  /usr/src/linux/.config

Or another method is - you can copy the .config file from your old linux kernel source tree to new kernel tree.
        bash# ls -l /usr/src/lin*  # You can see that /usr/src/linux is a soft link
        bash# cd /usr/src/linux 
        bash# cp ../linux-old-tree/.config .  # Example cp ../linux-2.4.19/.config .

or one other method is - you can use "make oldconfig" which default all questions based on the contents of your existing ./.config file.

NOTE: If you do not have lot of disk space in /usr/src then you can unpack the kernel source package on any partition where you have free disk space (like /home). Because kernel compile needs lot of disk space for object files like *.o. For this reason the /usr/src/linux MUST be a soft link pointing to your source directory.

After this, look in the next section to do make and install.

2.3 For the Impatient

  1. Unpack the sources
  2. Optional - Copy config file : You can copy the config file from your old linux kernel source tree to new kernel tree (may save time, if you want to reuse the old settings).
  3. make clean; make mrproper
  4. make xconfig
  5. make dep
  6. Give a unique name to your new Kernel - Edit /usr/src/linux/Makefile and change EXTRAVERSION
  7. nohup make bzImage
  8. 'make modules' and 'make modules_install'
  9. And you can go to lunch or go to bed (have nice Linux dreams in sleep) and when you come back the system is ready! And see the log with 'less nohup.out'.
  10. make install # But NOT recommended - use cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage.myker
  11. Configure GRUB or LILO.
  12. Reboot and check new kernel is booting
  13. Create emergency boot disk - bzdisk or mkbootdisk
  14. Optional - make rpm # To build rpm packages
  15. Optional - make clean (If you want to free up disk space)

See details of above steps in the following sections....

2.4 Building New Kernel - Explanation of Steps

Details of the steps mentioned in the previous section:

Note: Below 'bash#' denotes the bash prompt, you should type the commands that appear after the 'bash#' prompt. Below are commands tested on Redhat Linux Kernel 2.4.7-10, but it should work for other distributions with very minor changes. It should also work for older kernel versions like 2.2, 2.0 and 1.3. It should also work for future or newer versions of kernel (with little changes - let me know).

  1. Unpack the sources: Login in as 'root' throughout all these steps. Mount Redhat linux cdrom and install the linux kernel source rpm
    bash$ su - root
    bash# cd /mnt/cdrom/RedHat/RPMS 
    bash# rpm -i kernel-headers*.rpm 
    bash# rpm -i kernel-source*.rpm 
    bash# rpm -i dev86*.rpm   
    bash# rpm -i bin86*.rpm   
    

    (The bin86*.rpm and 'as86' is required only for OLDER Linux systems like Redhat 5.x. Get Intel assembler 'as86' command from dev86*.rpm on cdrom or from bin86-mandrake , bin86-kondara ). Also make sure that /usr/src/linux is soft link pointing to proper unpacked source.
    bash# cd /usr/src
    bash# ls -l    # You should see that /usr/src/linux is soft link pointing to source
    lrwxrwxrwx    1 root     root           19 Jan 26 11:01 linux -> linux-2.4.18-19.8.0
    drwxr-xr-x   17 root     root         4096 Jan 25 21:08 linux-2.4.18-14
    drwxr-xr-x   17 root     root         4096 Mar 26 12:50 linux-2.4.18-19.8.0
    drwxr-xr-x    7 root     root         4096 Jan 14 16:32 redhat
    

    If it is not a soft link then do rename /usr/src/linux to /usr/src/linux-2.4.yy and create a soft link.

    NOTE: If you do not have lot of disk space in /usr/src then you can unpack the kernel source package on any partition where you have free disk space (like /home). Because kernel compile needs lot of disk space for object files like *.o. For this reason the /usr/src/linux MUST be a soft link pointing to your source directory.

  2. Optional - Copy config file : This step may save you time, if you want to reuse the old settings. Whenever you install the kernel, generally you put the config file in /boot. So, you can use the existing version of config file:
    bash# mv /usr/src/linux/.config  /usr/src/linux/.config.save
    bash# cp /boot/config-2.4.18-19.8.0  /usr/src/linux/.config
    

    Or another method is - you can copy the .config file from your old linux kernel source tree to new kernel tree
            bash# ls -l /usr/src/lin*  # You can see that /usr/src/linux is a soft link
            bash# cd /usr/src/linux 
            bash# cp ../linux-old-tree/.config .  # Example cp ../linux-2.4.19/.config .
    

    or one other method is - you can use "make oldconfig" which default all questions based on the contents of your existing ./.config file.

  3. Clean : Before doing mrproper below, you may want to backup the .config file.
            bash# cd /usr/src/linux 
            bash# cp .config .config.save
            bash# make clean
            bash# make mrproper  # Must do this if want to start clean slate or if you face lot of problems
    

  4. Configure: The "make xconfig" or "make menuconfig" brings up a user friendly GUI interface. And "make config" brings up command-line console mode interface. You can load the configuration file from /usr/src/linux/.config (dot config file. Note the dot before config). Click on button "Load Configuration from File".

    Within 'make xconfig' you must do these (to avoid problems) -

    Save and Exit "make xconfig". All the options which you selected is now saved into configuration file at /usr/src/linux/.config (dot config file).

  5. Dep : And now, do -
    bash# make dep
    

  6. Give a unique name to your new Kernel: You can give a name to your kernel, so that it is unique and does not interfere with others.
    bash# cd /usr/src/linux
    bash# vi Makefile
    

    Here look for EXTRAVERSION = -19.8.0Blah_Blah_Blah and change to something like EXTRAVERSION = -19.8.0MyKernel.26Jan2003

  7. Do make: Read the following file (to gain some knowledge about kernel building. Tip: Use the color editor gvim for better readability.
    bash# gvim -R   /usr/src/linux/arch/i386/config.in 
    bash# man less 
    bash# less   /usr/src/linux/arch/i386/config.in 
    Type 'h' for help and to navigate press i, j, k, l, h or arrow, page up/down keys. 
    

    Now, give the make command -


            bash# cd /usr/src/linux
            bash# man nohup
            bash# nohup make bzImage &  
            bash# man tail
            bash# tail -f nohup.out     (.... to monitor the progress) 
    This will put the kernel in /usr/src/linux/arch/i386/boot/bzImage 
    

  8. LOADABLE MODULES: Now, while the 'make' is cranking along in the previous step "Do make", you should bring up another new xterm shell window and follow these steps: This step is required ONLY if you had enabled Loadable module support in step "Configure Step" above. Loadable module are located in /lib/modules. You MUST do this step if you enabled or disabled any modules, otherwise you will get 'unresolved symbols' errors during or after kernel boot.
    # Bring up a new Xterm shell window and ...
    bash# cd /usr/src/linux
    
    # Redirect outputs such that you do not overwrite the nohup.out which is still running...
    bash# nohup make modules 1> modules.out 2> modules.err  &
    
    bash# make modules_install   # Do this, only after the above make command is successful
    

    This will copy the modules to /lib/modules directory. See the Modules chapter at Loadable Modules.

  9. Now go to Lunch or Bed : Since both the make windows are cranking along, and now, you can go to lunch (chitchat, have nap) or go to bed (have nice Linux dreams in sleep) and when you wake up and come back the system is ready! You can check with command 'less nohup.out' to see the log of output.
    bash# cd /usr/src/linux
    bash# less nohup.out
    bash# less modules.err
    bash# less modules.out
    
    If no errors then do:
    bash# make modules_install  
    

  10. bzImage: After bzImage is successful, copy the kernel image to /boot directory. You must copy the new kernel image to /boot directory, otherwise the new kernel MAY NOT boot. You must also copy the config file to /boot area to reflect the kernel image, for documentation purpose.
    bash# cp /usr/src/linux/arch/i386/boot/bzImage     /boot/bzImage.myker.26mar2001
    
    # You MUST copy the config file to reflect the corresponding kernel image, for documentation purpose.
    bash# cp /usr/src/linux/.config /boot/config-<your_kernelversion_date>
    # Example: cp /usr/src/linux/.config /boot/config-2.4.18-19.8.0-26mar2001
    

    NOTE : If you are planning to use the initrd in LILO or GRUB then you may want to build initrd and place it in /boot/initrd*.img. See the Appendix A at Creating initrd.img file.

  11. Configure GRUB or LILO : There are two options for boot loading under Redhat Linux - GRUB and LILO.

    Configure GRUB: GRUB is recent and much better tool than LILO and it is my first preference to use GRUB. LILO is an older technology. GRUB differs from bootloaders such as LILO in that "it can lie to MS Windows and make MS Windows believe that it's installed on the first partition even if it's not!!". So you can keep your current Linux system where it is and install Windows on the side. See the Appendix C - GRUB details and sample grub.conf file.

    Configure LILO: LILO is older tool and see the Appendix B - Sample lilo.conf to configure LILO. (see also http://www.linuxdoc.org/HOWTO/LILO-crash-rescue-HOWTO.html)

  12. Reboot the machine and at lilo press tab key and type 'myker' If it boots then you did a good job! Otherwise at lilo select your old kernel, boot and re-try all over again. Your old kernel is still INTACT and SAFE at say /boot/vmlinuz-2.0.34-0.6

  13. If your new kernel 'myker' boots and works properly, you can create the boot disk. Insert a blank floppy into floppy drive and -
    bash# cd /usr/src/linux
    bash# make bzdisk
    
    See also mkbootdisk -
    bash# rpm -i mkbootdisk*.rpm
    bash# man mkbootdisk
    

  14. Build RPMs

    Optional - You can also build RPM packages of kernel, in case you want to install the new image on several machines.


    make rpm   # To build rpm packages
    

  15. Clean: Optional - make clean (If you want to free up disk space)

2.5 Troubleshooting

Having any problems? See the troubleshooting chapter.

2.6 Post Kernel Building

See the Appendix D - Post Kernel Building.


Next Previous Contents


Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру