• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Patching the Kernel

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Malakai

New Member
Joined
Dec 13, 2001
Location
Fl
I saw this in another thread when I searched for "patching kernel":
Code:
cat patchfile.patch | patch -p0

So, I wan't to patch the kernel with nforce2 agpgart support. The file is called linux-2.4.20-agpgart.diff.

So, after emerging the vanilla 2.4.21 kernel (going for stability), I copy linux-2.4.20-agpgart.diff to /usr/src and then
Code:
cat linux-2.4.20-agpgart.diff | patch -p0
? After that, I just need to specify that my drivers (ati-drivers) use the nvagp and not the kernel one right?


And also, for the nforce2 network driver, whether i build nvnet.o from nvidia's tarchive or emerge nforce-net, I then have to run
Code:
insmod nvnet.o
to make sure that the module loads on boot, correct?


This is all for gentoo if you can't tell btw
 
You should only use a patch on the kernel version it's written for (2.4.20, in this case). It might work anyway, but I wouldn't recommend it. Once you've got it patched, you should see a new option in a relevant location when you do make menuconfig. Also, you may have to copy the diff file into the root of the kernel source (ie /usr/src/linux-2.4.20-vanilla) and do the patching from there.

Other than that, you look good to go. For modprobe, you only have to say modprobe nvnet, not nvnet.o. Even better, if you add a line with nvnet to /etc/modules.conf (It might be /etc/modules.autoload, I can't quite remember. Look for a list of modules.), it will be loaded automagically at boot time.
 
Christoph said:
You should only use a patch on the kernel version it's written for (2.4.20, in this case). It might work anyway, but I wouldn't recommend it.

This patch is verified to work with 2.4.21 by everyone at the gentoo.org forums.

Once you've got it patched, you should see a new option in a relevant location when you do make menuconfig. Also, you may have to copy the diff file into the root of the kernel source (ie /usr/src/linux-2.4.20-vanilla) and do the patching from there.

I'll do that, thanks.

Other than that, you look good to go. For modprobe, you only have to say modprobe nvnet, not nvnet.o. Even better, if you add a line with nvnet to /etc/modules.conf (It might be /etc/modules.autoload, I can't quite remember. Look for a list of modules.), it will be loaded automagically at boot time. [/B]

I thought the insmod command added the line following the command to the /etc/modules.autoload (yes that is the correct path) file. I can manually edit the file if needed, thats no big deal.

I would like to ask, what is cat needed for? Wouldn't just typing
Code:
patch linux-2.4.20-agpgart.diff -[I]options[/I]
work just as well?
I will drop the .o extention, thanks for that tidbit of info as well.

One last question, seeing as how I'm eternally curious (and not in linux atm to man patch right now), what does the -p0 switch do? I have also seen -p1 recommended as the patch switch.
 
Malakai said:


This patch is verified to work with 2.4.21 by everyone at the gentoo.org forums.

Who am I to disagree. I wouldn't do this in general, but if people confirm that it works, charge on ahead.


I thought the insmod command added the line following the command to the /etc/modules.autoload (yes that is the correct path) file. I can manually edit the file if needed, thats no big deal.

insmod and modprobe basically do the same thing, which is look for a module and insert it. modprobe is fancier and will load any modules that your module depends on, while insmod will just give you an error. Unless there's been a big change recently, neither of them do anything to /etc/modules.autoload.



I would like to ask, what is cat needed for? Wouldn't just typing
Code:
patch linux-2.4.20-agpgart.diff -[I]options[/I]
work just as well?
I will drop the .o extention, thanks for that tidbit of info as well.

The way that patch accepts input is through the standard input. What the command does is print the diff file to the standard output, which is usually your terminal. The | tells your shell not to print the output from whatever comes before the |, but to send it to the command you typed after the | (patch, in this case). My best guess is that this is a holdover from the days of line editors, but I don't have any idea why patch won't accept a filename instead of its contents.


One last question, seeing as how I'm eternally curious (and not in linux atm to man patch right now), what does the -p0 switch do? I have also seen -p1 recommended as the patch switch.

Check the man page for patch. Man pages really help curiousity.
 
Christoph said:


Who am I to disagree. I wouldn't do this in general, but if people confirm that it works, charge on ahead.



insmod and modprobe basically do the same thing, which is look for a module and insert it. modprobe is fancier and will load any modules that your module depends on, while insmod will just give you an error. Unless there's been a big change recently, neither of them do anything to /etc/modules.autoload.




The way that patch accepts input is through the standard input. What the command does is print the diff file to the standard output, which is usually your terminal. The | tells your shell not to print the output from whatever comes before the |, but to send it to the command you typed after the | (patch, in this case). My best guess is that this is a holdover from the days of line editors, but I don't have any idea why patch won't accept a filename instead of its contents.




Check the man page for patch. Man pages really help curiousity.


I know I know. I need sleep first before I boot back over there though ;) You know how it goes

Thanks again.
 
YUOR WLECOM!!!1!!!!1 FOR ME HLEPIGN YUO WHIT LUNIX!!!1!!!11

Hmmmm. Apparently I need to sleep too.

Edit: I just realized that it's 1:45 AM. This sort of thing would never happen if I could only stick with my "no posting after 12:45" rule.
 
Malakai said:

One last question, seeing as how I'm eternally curious (and not in linux atm to man patch right now), what does the -p0 switch do? I have also seen -p1 recommended as the patch switch.

I'm in a copy and paste mode right now, so here's the relevant section of the patch man page:

-pnum or --strip=num
Strip the smallest prefix containing num leading slashes from each
file name found in the patch file. A sequence of one or more adja-
cent slashes is counted as a single slash. This controls how file
names found in the patch file are treated, in case you keep your
files in a different directory than the person who sent out the
patch. For example, supposing the file name in the patch file was

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and not specifying -p at all just gives you blurfl.c. Whatever you
end up with is looked for either in the current directory, or the
directory specified by the -d option.

edit:
BTW, if you ever happen to find yourself at a computer not running *nix ( :eek: ) and you need a man page, a lot of them are available on the Internet. I just typed 'man patch' into google, and it gave me this:
http://www.hmug.org/man/1/patch.html

(That particular page happens to be intended for Mac OS X, but it seems to use GNU patch).
 
Last edited:
Back