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

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

  




 

 

Managing Your Patches With quilt

Kernel development using patch and diff generally works quite well. But after a while, most people grow tired of it and look for a different way to work that does not involve so much tedious patching and merging. Luckily, a few kernel developers came up with a program called quilt that handles the process of manipulating a number of patches made against an external source tree much easier.

The idea for quilt came from a set of scripts written by Andrew Morton that he used to first maintain the memory management subsystem, and then later the entire development kernel tree. His scripts were tied very tightly to his workflow, but the ideas behind them were very powerful. Andreas Gruenbacher took those ideas and created the quilt tool.

The basic idea behind quilt is that you work with a pristine source tree, and add a bunch of patches on top of it. You can push and pop different patches off of the source tree, and maintain this list of patches in a simple manner.

To get started, create a kernel source tree like always:

$ 
tar -zxf linux-2.6.19.tar.gz

$ 
ls

linux-2.6.19/

And go into that directory:

$ 
cd linux-2.6.19

To get started, create a directory called patches that will hold all of our kernel patches:

$ 
mkdir patches

Then tell quilt to create a new patch called patch1:

$ 
quilt new patch1

Patch patches/patch1 is now on top

quilt needs to be told about all of the different files that will be modifed by this new patch. To do this, use the add command:

$ 
quilt add Makefile

File Makefile added to patch patches/patch1

Edit the file Makefile, modify the EXTRAVERSION line, and save the change. After you finish, tell quilt to refresh the patch:

$ 
quilt refresh

Refreshed patch patches/patch1

The file patches/patch1 will contain a patch with the changes that you have just made:

$ 
cat patches/patch1

Index: linux-2.6.19/Makefile
===================================================================
--- linux-2.6.19.orig/Makefile
+++ linux-2.6.19/Makefile
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 19
-EXTRAVERSION =
+EXTRAVERSION = -dirty
 NAME=Crazed Snow-Weasel
 
 # *DOCUMENTATION*

You can continue on, working with this single patch, or create a new one to go on top of this patch. As an example, if three different patches had been created, patch1, patch2, and patch3, they will be applied one on top of one another.

To see the list of patches that are currently applied:

$ 
quilt series -v

+ patches/patch1
+ patches/patch2
= patches/patch3

This output shows that all three patches are applied, and that the current one is patch3.

If a new kernel version is released, and you wish to port your changes to the new version, quilt can handle this easily with the following steps:

  1. Pop off all of the patches that are currently on the tree:

    $ 
    quilt pop -a
    
    Removing patch patches/patch3
    Restoring drivers/usb/Makefile
    
    Removing patch patches/patch2
    Restoring drivers/Makefile
    
    Removing patch patches/patch1
    Restoring Makefile
    
    No patches applied
    

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

    $ 
    patch -p1 < ../patch-2.6.20
    
    $ 
    cd ..
    
    $ 
    mv linux-2.6.19 linux-2.6.20
    
    
  3. Now have quilt push all of the patches back on top of the new tree:

    $ 
    quilt push
    
    Applying patch patches/patch1
    patching file Makefile
    Hunk #1 FAILED at 1.
    1 out of 1 hunk FAILED -- rejects in file Makefile
    Patch patches/patch1 does not apply (enforce with -f)
    

  4. As the first patch doesn't apply cleanly, force the patch to be applied and then fix it up:

    $ 
    quilt push -f
    
    Applying patch patches/patch1
    patching file Makefile
    Hunk #1 FAILED at 1.
    1 out of 1 hunk FAILED -- saving rejects to file Makefile.rej
    Applied patch patches/patch1 (forced; needs refresh)
    $ 
    vim Makefile.rej Makefile
    
    

  5. After the patch is applied by hand, refresh the patch:

    $ 
    quilt refresh
    
    Refreshed patch patches/patch1
    

  6. And continue on pushing the other patches:

    $ 
    quilt push
    
    Applying patch patches/patch2
    patching file drivers/Makefile
    
    Now at patch patches/patch2
    $ 
    quilt push
    
    Applying patch patches/patch3
    patching file drivers/usb/Makefile
    
    Now at patch patches/patch3
    

quilt also has options that will automatically email out all of the patches in the series to a group of people or a mailing list, delete specific patches in the middle of the series, go up or down the series of patches until a specific patch is found, and many more powerful options.

If you want to do any kind of kernel development, quilt is strongly recommended, even for tracking a few patches, instead of using the more difficult diff and patch method. It is much simpler and will save you much time and effort.

On a personal note, I cannot recommend this tool enough, as I use it every day to manage hundreds of patches in different development trees. It is also used by numerous Linux distributions to maintain their kernel packages, and has an involved and responsive development community.


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