Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Appendix A.  Helpful Utilities

Retrieving, building, updating, and maintaining a Linux kernel source tree involves a lot of different steps, as this book has shown. Developers being naturally lazy creatures, they have created some programs to help with the various routine tasks. Here we describe a few of these useful tools and the basics on how to use them.

Linux kernel development differs in many ways from traditional software development. Some of the special demands on kernel programmers include:

  • Constantly applying your changes to the moving target of a fast-based kernel development release schedule.

  • Resolving any merge conflicts between changes you have made and changes made by other people.

  • Exporting your changes in a format that lets others incorporate and work with it easily.

patch and diff [16]

One of the most common methods of doing kernel work is to use the patch and diff programs. To use these tools, two different directory trees: a "clean" one and a "working" one must be used. The clean tree is a released kernel version, while the working one is based on the same version but contains your modifications. Then you can use patch and diff to extract your changes and port them forward to a new kernel release.

For an example, create two directories containing the latest kernel version as described in Chapter 4, Retrieving the kernel source :

$ 
tar -zxf linux-2.6.19.tar.gz

$ 
mv linux-2.6.19 linux-2.6.19-dirty

$ 
tar -zxf linux-2.6.19.tar.gz

$ 
ls

linux-2.6.19/
linux-2.6.19-dirty/

Now make all of the different changes you wish to do in the -dirty directory and leave the clean, original kernel directory alone. After finishing making changes, you should create a patch to send it to other people:

$ 
diff -Naur -X linux-2.6.19/Documentation/dontdiff linux-2.6.19/ linux-2.6.19-dirty/ > my_patch

This will create a file called my_patch that contains the difference between your work and a clean 2.6.19 kernel tree. This patch then can be sent to other people via e-mail.

New Kernel Versions

If a new kernel version is released, and you wish to port your changes to the new version, you need to try to apply your generated patch onto a clean kernel version. This can be done in the following steps:

  1. Generate your original patch, as in the previous example.

  2. Using the official patch from kernel.org , move the old kernel version forward one release:

    $ 
    cd linux-2.6.19
    
    $ 
    patch -p1 < ../patch-2.6.20
    
    $ 
    cd ..
    
    $ 
    mv linux-2.6.19 linux-2.6.20
    
    
  3. Move your working directory forward one release by removing your patch, then apply the new update:

    $ 
    cd linux-2.6.19-dirty
    
    $ 
    patch -p1 -R < ../my_patch
    
    $ 
    patch -p1 < ../patch-2.6.20
    
    $ 
    cd ..
    
    $ 
    mv linux-2.4.19-dirty linux-2.6.20-dirty
    
    

  4. Try to apply your patch on top of the new update:

    $ 
    cd linux-2.6.20-dirty
    
    $ 
    patch -p1 < ../my_patch
    
    

    If your patch does not apply cleanly, resolve all of the conflicts that are created (the patch command will tell you about these, leaving behind .rej and .orig files for you to compare and fix up manually using your favorite editor). This merge process can be the most difficult part if you have made changes to portions of the source tree that have been changed by other people.

If you use this development process, I highly recommend getting the excellent patchutils set of programs (found at https://cyberelk.net/tim/patchutils). These programs enable you to manipulate text patches easily in all sorts of useful ways, and have saved kernel developers many hours of tedious work.



[16] This section is based on an article originally published in Linux Journal.


 
 
  Published under the terms of the Creative Commons License Design by Interspire