Steps to Creating a Linux Kernel

 < Day Day Up > 

It is common to completely update your Linux kernel when a new version becomes available. There may be features introduced into the new kernel that you want, or you may just want to remain current. Another common reason to create a new kernel is for security patches. In the upcoming sections, you'll install a new kernel. Updating the kernel can result in an unsupported configuration, so always check on this before creating a new kernel. Figure 5-1 shows the steps you'll cover in the next few sections for obtaining and working with our new kernel.

Figure 5-1. Creating a Linux Kernel on Integrity Servers


make compressed would be replaced with make bzImage on an x86-based system at the time of this writing. In addition, the make xconfig command was not yet certified on Integrity, at the time of this writing, so you may have to use make oldconfig; however, as you'll see in an upcoming example, I did indeed use make xconfig on Integrity.

As you can see, there are many steps to updating or creating your new kernel. After you go through the procedure yourself, you'll see that the procedure is rewarding because it gives you complete control over how this critical part of your system operates. Please keep in mind that, in some cases, running a new kernel is unsupported.

Obtaining Linux Kernel Source Code

In the upcoming example, you're going to download the latest kernel source code available at the time of this writing for an IA-32 system. After you have the source, you are going to perform the entire process of building a new kernel. In the later examples, you will modify our 64-bit Advanced Server kernel on the Integrity server.

www.kernel.org has many versions of Linux kernel source code including the latest versions. You can also select one of the mirror sites from which you can download the source code.

Kernels with even numbers, such as 2.4 (full number is 2.4.18-3) on our system, are fully tested production kernels. Those with odd numbers, such as the 2.5.25 kernel we use in our upcoming example, are experimental. You should assume the odd number kernels are not stable and are therefore not suitable for your production systems.

Figure 5-2 shows the www.kernel.org Web site and the kernels available at the time of this writing.

Figure 5-2. Obtaining a Linux Kernel from www.kernel.org


You can see from Figure 5-2 that you have selected the very latest available kernel at the time of this writing, which is 2.5.25. This is, of course, an experimental kernel, but that is part of the fun of Linux. You can load and experiment with this kernel knowing that you can boot your current stable kernel and resume the uninterrupted operation anytime.

Selecting the F provides a full version, which means that you get all the kernel-related files to compile and work with this kernel.

The compressed file that you have chosen to download has a file name of linux-2.5.25.tar.gz, and you asked for it to be downloaded to /root. Because the file is relatively small, it did not take long to download (1.5 hours on a 56K modem). You'll work with it in the upcoming sections.

Setting Up Directories and Files for the Linux Kernel

The first few steps you must perform to work with the new kernel are related to creating a directory structure that will house the old and new kernel versions. That is, you may have kernel source code for an existing kernel that you need to save and the code for the new kernel you want to work with.

If you don't know if you have existing kernel code, check in /usr/src for a directory called linux. If the linux directory does not exist, you don't have to worry about saving the existing source tree. If it does exist, simply move it from linux to linux-releaseNumber, where releaseNumber is something like linux-2.4.18-3 (the kernel release on the IA-32 system). Once that is done, your existing release is saved. If you don't know what your existing kernel release is, try issuing the command uname -r. The following is what happens when you run uname -r on the Integrity Server running RHEL Advanced Server:

 # uname -r 2.4.18-e.12.smp # 

If you were to save the existing kernel code, you would move the current linux directory to linux-2.4.18-e.12.smp. Once you did that, you are ready to create the new kernel. The following example shows copying the newly compressed kernel to the /usr/src directory, changing directory to /usr/src, making a directory called linux-2.5.25 for our new kernel, and performing another long listing of /usr/src:

 # cp /root/linux-2.5.25.tar.gz /usr/src # # cd /usr/src # # ls -l total 34144 -rw-r--r--    1 root     root     34918191 Jul 13 12:21 linux-2.5.25.tar.gz drwxr-xr-x    7 root     root         4096 Jun 11 05:38 redhat # # mkdir linux-2.5.25 # # ls -l total 34148 drwxr-xr-x    2 root     root         4096 Jul 13 12:25 linux-2.5.25 -rw-r--r--    1 root     root     34918191 Jul 13 12:21 linux-2.5.25.tar.gz drwxr-xr-x    7 root     root         4096 Jun 11 05:38 redhat # 

The long listings in the previous example indicate that we did not have an existing linux directory. Thus, we don't have to save it by renaming it linux-releaseNumber.

Next, create a symbolic link from the new kernel directory name to linux, unpack the gunziped tar file you downloaded into /usr/src/linux-2.5.25, change directories into /usr/src/linux and run make mrproper to clean up kernel configuration directories, as shown in the following example:

 # ln -s linux linux-2.5.25 linux # # ls -l total 34148 lrwxrwxrwx    1 root     root           12 Jul 13 12:26 linux -> linux-2.5.25 drwxr-xr-x    2 root     root         4096 Jul 13 12:26 linux-2.5.25 -rw-r--r--    1 root     root     34918191 Jul 13 12:21 linux-2.5.25.tar.gz drwxr-xr-x    7 root     root         4096 Jun 11 05:38 redhat # tar -xzf linux-2.5.25.tar.gz # # ls -l linux-2.5.25 total 268 drwxrwxr-x   19 1046     101          4096 Jul  5 19:42 arch -rw-r--r--    1 1046     101         18691 Jul  5 19:42 COPYING -rw-r--r--    1 1046     101         79460 Jul  5 19:42 CREDITS drwxrwxr-x   32 1046     101          4096 Jul  5 19:42 Documentation drwxrwxr-x   39 1046     101          4096 Jul  5 19:42 driver drwxrwxr-x   47 1046     101          4096 Jul  5 19:42 fs drwxrwxr-x   27 1046     101          4096 Jul  5 19:42 include drwxrwxr-x    2 1046     101          4096 Jul  5 19:42 init drwxrwxr-x    2 1046     101          4096 Jul  5 19:42 ipc drwxrwxr-x    2 1046     101          4096 Jul  5 19:42 kernel drwxrwxr-x    4 1046     101          4096 Jul  5 19:42 lib lrwxrwxrwx    1 root     root            5 Jul 13 12:26 linux -> linux -rw-r--r--    1 1046     101         41881 Jul  5 19:42 MAINTAINERS -rw-r--r--    1 1046     101         25218 Jul  5 19:42 Makefile drwxrwxr-x    2 1046     101          4096 Jul  5 19:42 mm drwxrwxr-x   29 1046     101          4096 Jul  5 19:42 net -rw-r--r--    1 1046     101         14402 Jul  5 19:42 README -rw-r--r--    1 1046     101          2815 Jul  5 19:42 REPORTING-BUGS -rw-r--r--    1 1046     101         18139 Jul  5 19:42 Rules.make drwxrwxr-x    4 1046     101          4096 Jul  5 19:42 scripts drwxrwxr-x   11 1046     101          4096 Jul  5 19:42 sound # # cd /usr/src/linux # make mrproper # 

Because of the symbolic link, the linux directory is actually the directory, linux-2.5.25. In the example, you used tar to unpack the downloaded file linux-2.5.25.tar.gz. This is not an RPM file like those you worked with earlier in this book. tar -x specifies that you'll extract the files from the archive, -f allows us to specify the file on which we'll work, and -z specifies that we'll use gzip to unzip it. After the files are extracted, ls -l shows us that we end up with the man files and directories under our new linux directory linux-2.5.25.

make xconfig

At the time of this writing, make xconfig hasn't yet been certified on Integrity servers; however, there are examples of make xconfig on Integrity in this section. The make oldconfig command is tested on Integrity. The make xconfig command uses the make utility to compile and invoke a kernel configuration tool. When make xconfig is run, the kernel configuration tool is X Windows-based. If you wanted to run the same tool in a character-based environment, run make menuconfig. I have used this command on both IA-32 and Integrity servers, but I have received reports that there are sometimes unusual results on Integrity servers, so please use it with caution.

After issuing the make xconfig command, a lot of gcc-related (compiler) messages appear and the top-level kernel configuration window opens. The top-level make xconfig window for our IA-32 system running Red Hat 8.x is shown in Figure 5-3.

Figure 5-3. Top-Level make xconfig for IA-32 System Running Red Hat 8.x


There are default settings for each of the buttons, shown in Figure 5-3. You can select any of the areas to see the default settings that apply in that area and change them.

The top level of make xconfig on Integrity running Advanced Server has different options, as shown in Figure 5-4.

Figure 5-4. Top-Level make xconfig for Integrity Server


In either case, from the top-level make xconfig window, you would typically select General setup to check the defaults. Figure 5-5 shows the General setup defaults for the IA-32 system running Red Hat 8.x.

Figure 5-5. General Setup in make xconfig for IA-32 Running Red Hat 8.x


The General Setup make xconfig window is a model for all the other windows. In the three left-most columns, you can select y for yes, m for module (although no m is present in the figure) or n for no. This means that you can select y to build functionality into the kernel or n to not build-in the functionality. If you select m for module, the functionality will be dynamically loaded into the kernel when it is needed, but won't be a permanent part of the kernel. This results in a smaller, more efficient kernel that won't take up as much memory. The bottom three buttons allow you to go back to the Main Menu, Next, or Previous area in the make xconfig interface.

An Integrity server running Advanced Server General setup has many additional selections, some of which are shown in Figure 5-6:

Figure 5-6. make xconfig General setup for an Integrity Server


In this figure, Itanium is the processor type. As you can see, General setup on Integrity servers has many additional selections, including /proc/efi/vars support. This parameter allows EFI variable information to be set in /proc/efi/vars. The following is a listing of /proc/efi/vars, which shows variable information. Among the variables shown are Boot-Order and Timeout. These are Itanium-specific variables:

 # cd /proc/efi/vars # ls Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c Boot0001-8be4df61-93ca-11d2-aa0d-00e098032b8c Boot0002-8be4df61-93ca-11d2-aa0d-00e098032b8c Boot0003-8be4df61-93ca-11d2-aa0d-00e098032b8c BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c CellularPlatform-8be4df61-93ca-11d2-aa0d-00e098032b8c ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c Driver0000-8be4df61-93ca-11d2-aa0d-00e098032b8c DriverOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c EDD30-964e5b21-6459-11d2-8e39-00a0c969723b ErrOut-8be4df61-93ca-11d2-aa0d-00e098032b8c ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c fibre_pri_path-8be4df61-93ca-11d2-aa0d-00e098032b8c Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c MTC-eb704011-1402-11d3-8e77-00a0c969723b Timeout-8be4df61-93ca-11d2-aa0d-00e098032b8c 

Moving back to the IA-32 system running Red Hat 8.x, Figure 5-7 shows make xconfig … File systems menu. Note that this menu displays several possible m selections.

Figure 5-7. Filesystems in make xconfig


The Filesystems menu window provides the option to select many common file systems, such as DOS FAT and JFS. You can work your way through all the areas of make xconfig to craft a kernel that meets your specific needs. You can select the functionality you want to be built directly into the kernel (y); the functionality you want selected as a module (used infrequently m); and the functionality you don't need at all can be excluded from the kernel altogether (n).

The ability to build a kernel to meet your specific needs is one of the most powerful and desirable features of working with Linux.

Compiling the New Kernel

After you configure the new kernel with make xconfig, you can begin the process of compiling or making it. In this section, you run a few make commands to perform a variety of tasks. Note that all these commands will be run in the directory where the new kernel will be built. In the following example, we'll change directory to /usr/src/linux before we begin. Remember that earlier, you linked (symbolic link) linux to linux-2.5.25, so all the work you perform the linux directory is actually done in linux-2.5.25. Also note that you are building an odd-number release. This means that it is an experimental kernel. Although that might be perfect for purposes here, I recommend using the fully tested even number kernel releases for production systems.

The make dep command is run first to make a dependency tree. This command checks for any dependencies of one module upon another module. The make clean command prepares a new directory tree for the kernel we are about to build. The make bzImage (replaced by make compressed on Integrity) command creates a compressed boot image of the kernel. This command takes a long time. The make install command installs the kernel files in the correct location:

 # cd /usr/src/linux # make dep; make clean; make bzImage; make install make[1]: Entering directory `/usr/src/linux-2.5.25' make[2]: Entering directory `/usr/src/linux-2.5.25/scripts'   gcc -Wp,-MD,./.split-include.d -Wall -Wstrict-prototypes -O2          -fomit-frame-pointer   -o split-include split-include.c make[2]: Leaving directory `/usr/src/linux-2.5.25/scripts'   Generating include/linux/version.h (updated)   Making asm->asm-i386 symlink   SPLIT  include/linux/autoconf.h -> include/config/*   Starting the build. KBUILD_BUILTIN=1 KBUILD_MODULES= make[2]: Entering directory `/usr/src/linux-2.5.25' make[3]: Entering directory `/usr/src/linux-2.5.25/init' make[3]: Leaving directory `/usr/src/linux-2.5.25/init' make[3]: Entering directory `/usr/src/linux-2.5.25/kernel'                    .                    .                    . 

You can see that I removed the vast majority of output from commands. The make bzImage produces a ton of output that I couldn't include in this book. There were, however, no errors from having run these commands. Note that I usually use output redirection with the make command to store standard output and standard error in files for later review.

In the next listing, you'll run make modules to compile the loadable modules in the kernel. Then you'll run make modules_install to install the modules into the correct directory for the new kernel:

 # make modules make[1]: Entering directory `/usr/src/linux-2.5.25/scripts' make[1]: Leaving directory `/usr/src/linux-2.5.25/scripts'   Starting the build. KBUILD_BUILTIN= KBUILD_MODULES=1 make[1]: Entering directory `/usr/src/linux-2.5.25/init' make[1]: Leaving directory `/usr/src/linux-2.5.25/init' make[1]: Entering directory `/usr/src/linux-2.5.25/kernel' make[1]: Leaving directory `/usr/src/linux-2.5.25/kernel' make[1]: Entering directory `/usr/src/linux-2.5.25/mm'                   .                   .                   . # # modules_install make[1]: Entering directory `/usr/src/linux-2.5.25/init' make[1]: Leaving directory `/usr/src/linux-2.5.25/init' make[1]: Entering directory `/usr/src/linux-2.5.25/kernel' make[1]: Leaving directory `/usr/src/linux-2.5.25/kernel' make[1]: Entering directory `/usr/src/linux-2.5.25/mm' make[1]: Leaving directory `/usr/src/linux-2.5.25/mm' make[1]: Entering directory `/usr/src/linux-2.5.25/fs' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/autofs4' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/autofs4' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/devpts' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/devpts' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/driverfs' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/driverfs' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/exportfs' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/exportfs' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/ext2' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/ext2' make[2]: Entering directory `/usr/src/linux-2.5.25/fs/fat' make[2]: Leaving directory `/usr/src/linux-2.5.25/fs/fat'                   .                   .                   . 

Now, the loadable modules have been compiled and installed in the correct directories. Loadable modules are included (by being linked) or removed from the kernel while it is running. This means that the kernel binary does not have to be changed to include or exclude the module. In addition, the kernel is smaller because the drivers are not loaded unless they're needed. Modules are loaded into the kernel with insmod and removed with rmmod.

Loadable kernel modules are usually located under /lib/modules/version. You can view the currently loaded modules on our IA-32 Red Hat 8.x system with the lsmod command, as shown in the following listing:

 # lsmod Module                  Size  Used by    Not tainted ad1848                 25696   0  (autoclean) (unused) sound                  72012   0  (autoclean) [ad1848] soundcore               6692   2  (autoclean) [sound] autofs                 12164   0  (autoclean) (unused) 3c59x                  28520   1 ide-cd                 30272   0  (autoclean) cdrom                  32192   0  (autoclean) [ide-cd] usb-uhci               24484   0  (unused) usbcore                73152   1  [usb-uhci] ext3                   67136   6 jbd                    49400   6  [ext3] 

This output shows that several modules are used on the system. Note that every kernel is different based on installed peripherals and programs, so your output could be slightly different.

The following listing shows the modules installed on the Integrity server running RHEL Advanced Server:

 # lsmod Module                  Size  Used by    Not tainted smbfs                 103080   0  (autoclean) ide-cd                 74600   0  (autoclean) soundcore              14368   0  (autoclean) iscsi                 208384   0 button                  8808   0  (unused) autofs                 31056   0  (autoclean) (unused) tulip                  96672   0  (unused) tg3                   105616   0  (unused) eepro100               53408   1 nls_iso8859-1           6048   1  (autoclean) nls_cp437               7728   1  (autoclean) vfat                   31096   1  (autoclean) fat                    88216   0  (autoclean) [vfat] mousedev               14544   1 keybdev                 6080   0  (unused) hid                    52888   0  (unused) input                  13648   0  [mousedev keybdev hid] usb-ohci               57712   0  (unused) usbcore               176472   1  [hid usb-ohci] ext3                  166536   1 jbd                   126016   1  [ext3] mptscsih               89760   3 mptbase                97944   3  [mptscsih] # 

Next, you'll update the boot file to allow you to boot either the new kernel or the existing stable kernel that you had been using.

Update Boot Program

Now that you have our new kernel in place, you want to be able to boot both the original rock-solid kernel and the new experimental one. I'll use the LILO boot loader. Many boot loaders exist, including GRUB (GRand Unified Bootloader), that work in a similar fashion. LILO is simple and easy to understand, so it will be ideal for this example.

Update the /etc/lilo.conf file to include the new kernel in addition to the existing kernel, and make the default the new experimental kernel, as shown in the following IA-32 system /etc/lilo.conf file:

 prompt timeout=50 default=linux-2.5.25 boot=/dev/hda map=/boot/map install=/boot/boot.b message=/boot/message linear image=/boot/vmlinuz-2.5.25               label=linux-2.5.25               initrd=/boot/initrd-2.5.25.img               read-only               root=/dev/hda5 image=/boot/vmlinuz-2.4.18-3               label=linux               initrd=/boot/initrd-2.4.18-3.img               read-only               root=/dev/hda5 

There are two kernel entries in this file, and you'd add one for each kernel you want to boot. The default simply specifies the default; however, all the kernels will be displayed for you when the system boots and you can select the one you want to boot.

You run the /sbin/lilo command to install the boot loader and activate the changes you made to the /etc/lilo.conf file. If you use the -v option, you get a lot of informative messages related to your update. The following listing shows running /sbin/lilo -v:

 # /sbin/lilo -v LILO version 21.4-4, Copyright (C) 1992-1998 Werner Almesberger 'lba32' extensions Copyright (C) 1999,2000 John Coffman Reading boot sector from /dev/hda Merging with /boot/boot.b Mapping message file /boot/message Boot image: /boot/vmlinuz-2.5.25 Mapping RAM disk /boot/initrd-2.5.25.img Added linux-2.5.25 * Boot image: /boot/vmlinuz-2.4.18-3 Mapping RAM disk /boot/initrd-2.4.18-3.img Added linux /boot/boot.0300 exists - no backup copy made. Writing boot sector. # 

You can see from this output that our new boot image of /boot/vmlinuz-2.5.25 exists and will be used as the default. The other boot image of /boot/vmlinuz-2.4.18-3 also exists and can be selected when the system boots.

You went through all the steps required to download and create a new kernel. Keep in mind that you may perform additional steps when creating your kernel, including working with new drivers. You may install a driver in the /usr/src/linux directory and edit its source file before running make modules and make modules_install. Even though we didn't cover every possible type of change you'd make to the kernel, you now know the fundamental steps to kernel creation and can download and load a new kernel on your system.

On the Integrity server, the boot file is in /boot/efi/efi/redhat/elilo.conf, which you can see here:

 prompt timeout=50 default=linux image=vmlinuz-2.4.18-e.12smp         label=linux         initrd=initrd-2.4.18-e.12smp.img         read-only         root=/dev/sda3 image=vmlinuz-2.4.18-e.12         label=linux-up         initrd=initrd-2.4.18-e.12.img         read-only         root=/dev/sda3 

The default image is specified early in the file. It is the one that you observed running the system when you checked earlier in this chapter using uname -r. Note that the location of the elio.conf file is different on Integrity servers. On IA-32 systems, it is located in /etc. On Advanced Server systems, it is located in /boot/efi/efi/redhat. Keep in mind that IA-32 uses lilo and Integrity servers uses elilo.

     < Day Day Up > 


    Linux on HP Integrity Servers. A System Administrator's Guide
    Linux on HP Integrity Servers: A System Administrators Guide
    ISBN: 0131400002
    EAN: 2147483647
    Year: 2004
    Pages: 100

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net