News Register Control Panel Private Messages Members List Team Search News Posts About Us
 

Kernel Compilation under Linux
  Author: Unknown
Added: 12/21/2002
Type: Tutorial
Viewed: 1384 time(s)
Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10Average visitor rating of 9.1/10
Configuration and Installation

   4.1 make commands: description and usage

- "make xconfig" starts a GUI interface and can only be used if you're running a X Window
- "make menuconfig" starts a console mode interface. It will ask you if you want to add in the new options from the kernel by selecting Y (yes), N (no), or M (module).
- "make oldconfig" generates the .config from your current working kernel.
- "make config" will make the configuration from the .config that you will have edited and configured by hand (if you want headache, go for it).

I suggest the sweety GUI interface as you may imagine. All this commands create or use the .config file at /usr/src/linux-2.4.19/.config. If a .config has already been copied in that directory (see below), "make xconfig" will read it.

$ make xconfig

Configure your kernel by selecting all the features you want to compile into it like networking, sound, SCSI... Save and exit. All the selected options are saved in /usr/src/linux-2.4.19/.config before being compiled. If you want to use your old kernel configuration, execute "make oldconfig" (it will generate the .config file of your old kernel) and copy .config in the new kernel directory:

$ make oldconfig
$ cp -p /usr/src/linux-2.4.x/.config /usr/src/linux-2.4.19/.config


I suggest you to backup the .config generated or modified by "make xconfig", "make menuconfig" or by yourself somewhere for future kernel upgrades.

$ cp -p /usr/src/linux-2.4.19/.config /root/config-2.4.19.txt

The -p is used to keep permissions on the copied file. "make mrproper" deletes all your kernel sources including your old .config file. This command isn't needed if you NEVER compiled a kernel before or if you want to keep your old configuration. If you recompile your kernel because of some errors you had in the first compilation don't forget "make mrproper".

$ make mrproper
$ make xconfig

   4.2 Build dependencies

$ make dep
$ make clean


   4.3 Build the kernel

If everything goes right, you can now compile your kernel. The operation will take about 5 minutes (depends your processor)

$ make bzImage

This will put the new kernel in /usr/src/linux-2.4.19/arch/i386/boot/bzImage. Instead of "make bzImage" you could also use "make bzdisk". It compiles the kernel and copies it on a floppy disk. This command is used to test a new kernel without rewriting lilo.conf or grub.conf. A "cp /usr/src/linux-2.4.19/arch/i386/boot/bzImage /dev/fd0" after a "make bzImage" would do the same. You could also execute "make zImage" if you don't want your kernel to be compressed. It was the command used to compile older kernels. The image would then be named "vmlinux". This make isn't used anymore as the produced kernel is generally too big to be started by lilo or grub.

   4.4 Build the modules

Modules are parts of the kernel that are loaded on the fly, as they are needed. Modules are generally stored in ".o" files.

$ make modules

   4.5 Make an initrd image

If you have a SCSI adapter and you made your SCSI driver modular, build a new initrd image. If you don't need it skip this part. Also, if you build your kernel with ext3 support as a module, you must create an initrd image. Use /sbin/mkinitrd to build an initrd image for your machine. To use this command, the loopback block device must be available.

$ mkinitrd /boot/initrd-2.4.19.img 2.4.19

initrd-2.4.19.img is the name of the image that you are creating. You can give the name you want to that file but you will have to specify the same name on lilo.conf or grub.conf (see below). 2.4.19 is the name of the kernel found from /lib/modules that you need to use to build the initrd image.

   4.6 backup and install the kernel

Now that you compiled your new kernel you have to install it on your system. Kernels are generally loaded in /boot so we have to copy our new kernel there. I suggest you to backup your old System.map. Also make sure you have a bootdisk (mkbootdisk --device /dev/fd0 2.4.x) of your old kernel. You could also do a "make install", it will automatically copy the kernel and System.map in /boot. Don't forget to backup System.map before doing it.

$ cd /boot
$ mv System.map System.map-old


Now copy your new kernel in /boot (or do a "make install"):

$ cp /usr/src/linux-2.4.19/System.map /boot/System.map
$ cp /usr/src/linux-2.4.19/arch/i386/boot/bzImage /boot/vmlinuz-2.4.19


   4.7 Install the modules

$ make modules_install

This will copy all the modules in /lib/modules/2.4.19/kernel/drivers even if you didn't build any.


Article Pages:  � Prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next �  


How would you rate this article:    Bad Good   Go � 


� Copyright Linux Advisory 2003. All rights reserved.
We are not responsible for the comment and story contributed by users.