Creating a Custom Kernel
The 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 Order
Cleaning 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 File
You 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 Configuration
The .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 File
Table 33.2 lists three commands that you can run in the /usr/src/linux-2.6.5-1.358 directory to update the .config file.
Table 33.2. Scripts for Modifying the .config FileCommand | Description |
|---|
make config | Text-based utility that prompts you line by line. This method can become laborious. | make menuconfig | Text-menu-based utility. | make gconfig | X-Windows-based utility. |
Each command prompts you in different ways for each kernel option, each of which generally provides you with the three choices shown in Table 33.3. A brief description of each kernel configuration option is given in Table 33.4.
Table 33.3. Kernel Option ChoicesKernel Option Choice | Description |
|---|
M | The kernel loads the drivers for this option on an as-needed basis. Only the code required to load the driver on demand is included in the kernel. | Y | Includes all the code for the drivers needed for this option into the kernel itself. This generally makes the kernel larger and slower but makes it more self-sufficient. The Y option is frequently used in cases in which a stripped down kernel is one of the only programs Linux runs, such as purpose built home firewall appliances you can buy in a store.
There is a limit to the overall size of a kernel. It fails to compile if you select parameters that make it too big.
| N | Don't make the kernel support this option at all. |
Table 33.4. Kernel Configuration OptionsOption | Description |
|---|
Code maturity level options | Determines whether Linux prompts you for certain types of development code or drivers. | Loadable module support | Support for loadable modules versus a monolithic kernel. Most of the remaining kernel options use loadable modules by default. It is best to leave this alone in most cases. | Processor type and features | SMP, Large memory, BIOS, and CPU type settings. | General setup | Support for power management, networking, and systems buses, such as PCI, PCMCIA, EISA, ISA. | Memory technology devices | Linux subsystem for memory devices, especially Flash devices. | Parallel port support | Self-explanatory. | Plug and Play configuration | Support of the automatic new hardware detection method called plug and play. | Block devices | Support for a number of parallel-port-based and ATAPI type devices. Support for your loopback interface and RAM disks can be found here too. | Multidevice support (RAID, LVM) | Support for RAID, 0, 1, and 5, as well as LVM. | Cryptography support (CryptoAPI) | Support for various types of encryption. | Networking options | TCP/IP, DECnet, Appletalk, IPX, ATM/LANE. | Telephony support | Support for voice to data I/O cards. | ATA/IDE/MFM/RLL support | Support for a variety of disk controller chipsets | SCSI support | Support for a variety of disk controller chipsets. Also sets limits on the maximum number of supported SCSI disks and CDROMs. | Fusion MPT support | High speed SCSI chipset support. | I2O device support | Support for specialized Intelligent I/O cards | Network device support | Support for Ethernet, Fibre Channel, FDDI, SLIP, PPP, ARCnet, Token Ring, ATM, PCMCIA networking, and specialized WAN cards. | Amateur Radio support | Support for packet radio. | IrDA subsystem support | Infrared wireless network support. | ISDN subsystem | Support for ISDN. | Old CD-ROM drivers (not SCSI, not IDE) | Support for non-SCSI, non-IDE, non-ATAPI CD-ROMs. | Input core support | Keyboard, mouse, and joystick support, in addition to the default VGA resolution. | Character devices | Support for virtual terminals and various serial cards for modems, joysticks, and basic parallel port printing. | Multimedia devices | Streaming video and radio I/O card support. | Crypto Hardware support | Web-based SSL hardware accelerator card support. | Console drivers | Support for various console video cards. | Filesystems | Support for all the various filesystems and strangely, the native languages supported by Linux. | Sound | Support for a variety of sound cards. | USB support | Support for a variety of USB devices. | Additional device driver support | Miscellaneous driver support. | Bluetooth support | Support for a variety of Bluetooth devices. | Kernel hacking device drivers | Support for detailed error messages for persons writing device drivers. |
Configure Dependencies
As 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 Name
Edit 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 Kernel
You 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 Modules
You 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 Modules
The 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 Partition
The 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]#
 |