June 4, 2009, 4:52 p.m.
posted by whitehat
Creating a Custom KernelThe installation of the kernel sources creates a file called README in the /usr/src/linux-2.6.5-1.358 directory that briefly outlines the steps needed to create a new kernel. Take a look at a more detailed explanation of the required steps. Make Sure Your Source Files Are in OrderCleaning up the various source files is the first step. This isn't so important for a first time rebuild, but it is vital for subsequent attempts. You use the make mrproper command to do this; it must be executed in the Linux kernel version's subdirectory located under /usr/src. In this case, the subdirectory's name is /usr/src/linux-2.6.5-1.358:
[root@bigboy tmp]# cd /usr/src/linux-2.6.5-1.358/
[root@bigboy linux-2.6.5-1.358]# make mrproper
...
...
...
[root@bigboy linux-2.6.5-1.358]#
The .config FileYou next need to run scripts to create a kernel configuration file called /usr/src/linux-2.6.5-1.358/.config. This file lists all the kernel options you wish to use. Backup Your ConfigurationThe .config file won't exist if you've never created a custom kernel on your system before, but fortunately, Red Hat stores a number of default .config files in the /usr/src/linux-2.6.5-1.358/configs directory. You can automatically copy the .config file that matches your installed kernel by running the make oldconfig command in the /usr/src/linux-2.6.5-1.358 directory:
[root@bigboy tmp]# cd /usr/src/linux-2.6.5-1.358
[root@bigboy linux-2.6.5-1.358]# ls .config
ls: .config: No such file or directory
[root@bigboy linux-2.6.5-1.358]# make oldconfig
...
...
...
[root@bigboy linux-2.6.5-1.358]#
If you've created a custom kernel before, the .config file that the previous custom kernel build used will already exist. Copy it to a safe location before proceeding. Customizing the .config FileFigure lists three commands that you can run in the /usr/src/linux-2.6.5-1.358 directory to update the .config file.
Each command prompts you in different ways for each kernel option, each of which generally provides you with the three choices shown in Figure. A brief description of each kernel configuration option is given in Figure.
Configure DependenciesAs I mentioned before, the .config file you just created lists the options you'll need in your kernel. In version 2.4 of the kernel and older, the make dep command was needed at this step to prepare the needed source files for compiling. This step has been eliminated as of version 2.6 of the kernel. Edit the Makefile to Give the Kernel a Unique NameEdit the file Makefile, and change the line EXtrAVERSION [eq] to create a unique suffix at the end of the default name of the kernel. For example, if your current kernel version is 2.6.5-1.358, and your EXTRAVERSION is set to -6-new, your new additional kernel will have the name vmlinuz-2.6.5-6-new. Remember to change this for each new version of the kernel you create. Compile a New KernelYou can now use the make bzImage command to create a compressed version of your new kernel and its companion .img RAM disk file. This could take several hours on a 386 or 486 system. It will take about 20 minutes on a 400MHz Celeron.
[root@bigboy linux-2.6.5-1.358]# make bzImage
...
...
...
[root@bigboy linux-2.6.5-1.358]#
Build the Kernel's ModulesYou can now use the make modules command to create all the modules the kernel needs. This command compiles the modules, but locates them within the Linux kernel source directory tree under the directory /usr/src/. The next step relocates them to where they should finally reside under the /lib/modules/<kernel version> directory.
[root@bigboy linux-2.6.5-1.358]# make modules
...
...
...
[root@bigboy linux-2.6.5-1.358]#
Install the Kernel ModulesThe make modules_install command copies the newly created modules to the conventional module locations. This step allows you to test the module compilation process before placing them in directories that will make them immediately available to the kernel. The splitting of these two steps can make troubleshooting much easier.
[root@bigboy linux-2.6.5-1.358]# make modules_install
...
...
...
[root@bigboy linux-2.6.5-1.358]#
Copy the New Kernel to the /boot PartitionThe kernel and the .img you just created need to be copied to the /boot partition where all your systems active kernel files normally reside. This is done with the make install command. This partition has a default size of 100MB, which is enough to hold a number of kernels. You may have to delete some older kernels to create enough space.
[root@bigboy linux-2.6.5-1.358]# make install
...
...
...
[root@bigboy linux-2.6.5-1.358]#
Here you can see that the new kernel vmlinuz-2.6.5-1.358-new is installed in the /boot directory.
[root@bigboy linux-2.6.5-1.358]# ls -l /boot/vmlinuz*
lrwxrwxrwx 1 root root 22 Nov 28 01:20 /boot/vmlinuz -> vmlinuz-2.6.5-1.358-new
-rw-r--r-- 1 root root 1122363 Feb 27 2003 /boot/vmlinuz-2.6.5-1.358
-rw-r--r-- 1 root root 1122291 Nov 28 01:20 /boot/vmlinuz-2.6.5-1.358-new
[root@bigboy linux-2.6.5-1.358]#
|
- Comment