BACK

Kernel Compiling 2

Some time ago I wrote a page on compiling the Linux kernel, this is an update to that page and basically a replacement. The latest kernel at the time of this writing is 2.4.5 and can be obtained from kernel.org.

  1. Get the source and place it in a directory in your home directory.
  2. Verify the version of the kernel you have running.
       suse:~/kernel # /bin/uname -r
       2.4.3
    
  3. Decompress and untar the source
       suse:~/kernel # tar zxfv linux-2.4.5.tar.gz
    
  4. Change to the newly created linux directory.
       suse:~/kernel # cd linux
       suse:~/kernel/linux #
    
  5. Now read the Changes file under the Documentation folder in the kernel source to determine which other programs need to be updated to run the new kernel.
       suse:~/kernel/linux # less Documentation/Changes
    
  6. Next you'll have to run one of three setup programs, if you don't have X windows running you best option is to use make menuconfig as it is much more friendly than the prompts of make config.
    Command Environment
    make config Command line prompts
    make menuconfig Command line text menu
    make xconfig X Windows GUI
  7. Go through the menus and select the options you want in your kernel, and exit saving the changes to the config file when prompted.
  8. Next run make dep to find the dependencies.
       suse:~/kernel/linux # make dep
    
  9. After the dependencies are found run make bzImage (depending on your system speed and kernel options, this can take a long time) to make the new kernel, bzImage is for large kernels and the bz denotes that it is compressed, it gets decompressed automatically when the system boots. The kernel gets saved at {$KERNEL_SOURCE}/arch/i386/boot/bzImage.
       suse:~/kernel/linux # make bzImage
    
  10. When the kernel compilation is done it will tell you the size and location of the kernel.
                  [ Output clipped ]
       System is 804 kB
       make[1]: Leaving directory `/root/kernel/linux/arch/i386/boot'
       suse:~/kernel/linux # 
    
  11. Next run make modules and make modules_install to configure the kernel modules.
       suse:~/kernel/linux # make modules modules_install
    
  12. Next backup your old kernel in case you have a problem with the new one.
    1. Look at your lilo.conf file to see which kernel boots by default, ( as you can see I have four kernels referenced in lilo.conf ) the first in the file is booted by default if not specified in the global section.
         suse:~/kernel/linux # cat /etc/lilo.conf
         boot=/dev/hda
         vga=normal
         read-only
         prompt
         timeout=50
         # End LILO global Section
         #
         image = /boot/vmlinuz.new
           root= /dev/hda5
           label = new
      
         image = /boot/vmlinuz.old2
           root = /dev/hda5
           label = old2
      
         image = /boot/vmlinuz
           root = /dev/hda5
           label = linux
      
         image = /boot/vmlinuz.old
           root = /dev/hda5
           label = original
      
      
    2. Backup the old kernel; you need to be root to do this.
         suse:~/kernel/linux # cd /boot
         suse:/boot # cp vmlinuz.new vmlinuz.old2
      
    3. Copy the new kernel to the /boot directory and rename it to the first entry in lilo.conf (vmlinuz.new).
         suse:/boot # cd /root/kernel/linux/arch/i386/boot
         suse:~/kernel/linux/arch/i386/boot # cp bzImage /boot/vmlinuz.new
      
    4. If you modified lilo.conf, you need to run the lilo command to update it, the asterisk denotes the default kernel image to boot.
         suse:/boot # /sbin/lilo
         Added new *
         Added old2
         Added linux
         Added original
      
  13. Reboot the system.
       suse:/boot # /sbin/shutdown -r now
    
  14. At the LILO boot: prompt press [tab] to see all available kernel boot images. You can press enter to boot the first one (new) or the name of any of the other kernels (e.g. original)
       LILO boot: [tab]
       new       old2       linux         original
       boot:
    
  15. Next login and verify the kernel version, your login prompt might display it for you.
       Welcome to  (i386) - Kernel 2.4.5 (tty1).
    
       suse login: root
       Password:
       suse:~ # /bin/uname -r
       2.4.5
    

BACK