located in the kernel source directory for the kernel version you currently use. This script applies all necessary version patches to bring your kernel up to the latest version.

The format for using the patch-kernel script looks like this:

patch-kernel source_dir patch_dir stopversion

The source directory defaults to /usr/src/linux if none is given, and the patch_dir defaults to the current working directory if one is not supplied.

For example, assume that you have a 2.6.6 kernel code tree that needs to be patched to the 2.6.8 version. The 2.6.7 and 2.6.8 patch files have been downloaded from ftp.kernel.org and are placed in the /patch directory in the source tree. You issue the following command in the /usr/src/kernels/linux-2.6 directory:

# scripts/patch-kernel /usr/src/kernels/linux-2.6.15 /usr/src/kernels/linux- 2.6.15/patch

Each successive patch file is applied, eventually creating a 2.6.8 code tree. If any errors occur during this operation, files named xxx# or xxx.rej are created, where xxx is the version of patch that failed. You have to resolve these failed patches manually by examining the errors and looking at the source code and the patch. An inexperienced person will not have any success with this because you must understand C programming and kernel programming to know what is broken and how to fix it. Because this was a stock 2.6.6 code tree, the patches were all successfully applied without errors. If you are attempting to apply a nonstandard third-party patch, the patch is likely to fail.

When you have successfully patched the kernel, you are ready to begin compiling this code tree as if you started with a fresh, stock 2.6.8 kernel tree.

Using the patch Command

If you have a special, nonstandard patch to apply — such as a third-party patch for a commercial product, for example — you can use the patch command rather than the special patch-kernel script that is normally used for kernel source updates. Here are some quick steps and an alternative method of creating patched code and leaving the original code alone:

1. Create a directory in your home directory and name it something meaningful, like mylinux.

2. Copy the pristine Linux source code there with cp -ravd /usr/src/kernels/linux-2.6/* ~/mylinux.

3. Copy the patch file to that same directory with cp patch_filename -/mylinux.

4. Change to the ~/mylinux directory with cd ~/mylinux.

5. Apply the patch with patch -p1 < patch_filename > mypatch.log 2>&1. (This last bit of code saves the message output to a file so that you can look at it later.)

6. If the patch applies successfully, you are finished and have not endangered any of the pristine source code. In case the newly patched code does not work, you do not have to reinstall the original, pristine source code.

7. Copy your new code to /usr/src/kernels and make that special symbolic link described elsewhere in the chapter.

Compiling the Kernel

If you want to update the kernel from new source code you have downloaded or you have applied a patch to add new functionality or hardware support, you have to compile and install a new kernel to actually use that new functionality. Compiling the kernel involves translating the kernel's contents from human-readable code to binary form. Installing the kernel involves putting all the compiled files where they belong in /boot and /lib and making changes to the bootloader.

The process of compiling the kernel is almost completely automated by the make utility, as is the process of installing. By providing the necessary arguments and following the steps covered next, you can recompile and install a custom kernel for your use.

Here is a checklist of steps to compile and configure the kernel:

1 Verify a working bootdisk for the old kernel to be able to reboot your system in case something goes wrong with the new kernel.

CAUTION

Before making any changes to your current, working kernel, make sure that you have a backup copy on a floppy disk. This enables you to boot into your system with a known working kernel in case something goes wrong during configuration. The command to do this is as follows:

# mkbootdisk --device /dev/fd0 `uname -r`

This assumes that your floppy drive is /dev/fd0. (Here is a good shell script tip: The ` character tells the shell to execute what is within ` first and then returns that output as part of the input of the mkbootdisk command.) On this machine, the result is the following:

# mkbootdisk --device /dev/fd0 2.6.7-1

This command is not echoed to your screen, but it is what the system executes.

2. Apply all patches, if any, so that you have the features you want. See the previous section for details.

3. Back up the .config file, if it exists, so that you can recover from the inevitable mistake. Use the following cp command:

# cp .config .config.bak

NOTE

If you are recompiling the Fedora default kernel, the /usr/src/kernels/linux-2.6/configs directory contains several versions of configuration files for different purposes. Fedora provides a full set of .config files in the subdirectory configs, all named for the type of system for which they were compiled. For example, kernel-2.6.7-i686-smp.config is a configuration file for a multiprocessor Pentium-class computer. If you want to use one of these default configurations as the basis for a custom kernel, simply copy the appropriate file to /usr/src/kernels/linux-2.6 and rename it .config.

4. Run the make mrproper directive to prepare the kernel source tree, cleaning out any old files or binaries.

5. Restore the .config file that the command make mrproper deleted, and edit the Makefile to change the EXTRAVERSION number.

NOTE

If you want to keep any current version of the kernel that was compiled with the same code tree, manually edit the Makefile with your favorite text editor and add some unique string to the EXTRAVERSION variable. You can use any description you prefer.

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату