-1

I am reading "Linux kernel module programming" by Peter Jay Salzman, and in that book they say

sys_call_table is no longer exported in 2.6.x kernels. If you really want to try this DANGEROUS module you will have to apply the supplied patch against your current kernel and recompile it.

Can anybody explain the meaning of "patch" to me, and what it means to recompile the kernel.

  • Just source code patch, a set of file that records all the changes of the kernel source code. – 炸鱼薯条德里克 Mar 18 at 9:58
  • @炸鱼薯条德里克 can you please elaborate more. And why do we the patch ? – Sunny Khandare Mar 18 at 13:01
  • Because we want to change the sourse code? – 炸鱼薯条德里克 Mar 18 at 23:39
5

A "patch" is a file describing changes to another file (the file can be anything including source code). One of the simplest ways to create and use a patch is with diff and patch.

Let's say we have a simple hello world program in a file called hello1.c:

#include <stdio.h>

int main(void)
{
  printf("Hello world!\n");
  return 0;
}

Now let's change the string "Hello world!\n" to "Hi world!\n" and call the new program hello2.c:

#include <stdio.h>

int main(void)
{
  printf("Hi world!\n");
  return 0;
}

Now in a terminal run the following command:

diff -u hello1.c hello2.c > hello-patch

Outputting the content of the patch file with cat hello-patch shows this:

--- hello1.c    2019-03-18 13:29:35.897546888 -0500
+++ hello2.c    2019-03-18 13:30:02.866456737 -0500
@@ -2,6 +2,6 @@

 int main(void)
 {
-  printf("Hello world!\n");
+  printf("Hi world!\n");
   return 0;
 }

This file indicates changes between hello1.c and hello2.c.

Now let's say you've distributed the source code for hello1.c to your friends. This hello-patch patch file allows your friends to transform hello1.c into hello2.c with the patch command. If hello1.c and patch are in the same directory, this command:

patch < hello-patch

This will "apply the patch to hello1.c". When it's done, hello1.c will be updated and it is now identical to hello2.c.

So patches are just lists of changes to a file (or set of files), and these patches allow someone to selectively update a file by applying patches.

The diff and patch commands work well for small patches. Anything big and complicated will need an industrial strength tool. Linux uses git. The git help system is pretty good. For instance, git help -a lists all git help topics, and git help format-patch details how to "Prepare patches for e-mail submission".

Linux development is carried out via email, and you can view an archive of the emails sent by linux developers at lkml.org, and kernelnewbies.org is a great starting place for learning about Linux kernel development. Be warned, since it looks like the book you cite was published in 2009, some of the technical details it contains will be out of date.

"Recompiling" in this case just means compiling again after applying the patch to the source. It's like when you run something like gcc hello1.c -o hello to compile a source file into executable code. This guide describes building Linux. This one describes a build process with some steps that can be used on the Debian distribution.

This 2016 talk by Linux developer Greg Kroah-Hartman gives an overview of what Linux development is like

  • on what basis changes are decided ? – Sunny Khandare Mar 20 at 9:31
0

If you don't know what "recompile the kernel" and "apply a patch means", you should read other Linux/Unix-related books that covers more basic topics instead of taking your time trying to get knowledge from a book that is specific for Linux Kernel development like "Linux kernel module programming" by Peter Jay Salzman.

I suggest you the following books(sorry if it this post looks like an AD) to start your journey to aquire knowledge on how to operate a Unix-like OS:

  • UNIX and Linux System Administration Handbook, 4th Edition by Evi Nemeth (Author), Garth Snyder (Author), Trent R. Hein (Author), Ben Whaley (Author)
  • How Linux Works: What Every Superuser Should Know by Brian Ward
  • The Cathedral and the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary by Eric S. Raymond

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.