How do I patch and then recompile, or rebuild, my linux kernel

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
UPDATE:

The solution THUS FAR (everything after a "#" is exactly what I typed into the command line, nothing more, nothing less):
? # yum install kernel-devel
I'm not sure yet if I need this step or not, at the least I think I need "yum install hardlink"

download Julian's patch to root's home directory
# cd ~
# wget http://www.ssi.bg/~ja/routes-2.6.13-12.diff

download the kernel source (kernel-2.6.13-1.1532_FC4.src.rpm)
# wget http://download.fedora.redhat.com/pub/f...SRPMS/kernel-2.6.13-1.1532_FC4.src.rpm

install with:
# rpm -ivh kernel-2.6.13-1.1532_FC4.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES

# mkdir /usr/src/redhat
# mkdir /usr/src/redhat/SOURCES

# rpm -ivh kernel-2.6.13-1.1532_FC4.src.rpm

# yum install rpm-build gcc redhat-rpm-config

# cd /usr/src/redhat/SPECS/

# rpmbuild -bp --target=i686 kernel-2.6.spec

# cd /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/

# cp configs/kernel-2.6.13-i686.config .config

have downloaded Julian's kernel patch to root's home directory
# patch -p1 < ~/routes-2.6.13-12.diff

# vi Makefile
changed "EXTRAVERSION = -prep" to "EXTRAVERSION = -DeadGatewayDetection"

# make oldconfig

# time make rpm
the "time" is to tell me how slow my system is ;)
This got me a src.rpm and a good rpm for i386 architecture, but I'm still trying to get a kernel optimized for the P4 (i686 architecture). When rebuilding the src.rpm, I get the following error:
+ cp /var/tmp/kernel-2.6.13dgd-root/boot/vmlinuz-2.6.13-dgd
cp: missing destination file
Try `cp --help' for more information.
???

----------------------------------------------------------------------------------------------

ORIGINAL POST:

I don't know what the deal is. I know this gets asked all the time (maybe not here but it does on linux forums), but everywhere I find answers or howto's on patching and compiling, they always make references to files that don't exist, or run commands that my machine doesn't recognize or some such nonsense. So here goes:

I have a Fedora Core 4 box, a minimal server install, updated with yum. I've installed the kernel source with:

# yum install kernel-devel

It looks like the source files are located in /usr/src/kernels/2.6.13-1.1532_FC4-i686/. Here is the contents of that directory:
[root@EMMRTR01 2.6.13-1.1532_FC4-i686]# ls -l
total 392
drwxr-xr-x 27 root root 4096 Oct 24 21:49 arch
drwxr-xr-x 4 root root 4096 Oct 24 21:49 crypto
drwxr-xr-x 51 root root 4096 Oct 24 21:49 drivers
drwxr-xr-x 55 root root 4096 Oct 24 21:49 fs
drwxr-xr-x 16 root root 4096 Oct 24 21:49 include
drwxr-xr-x 2 root root 4096 Oct 24 21:49 init
drwxr-xr-x 2 root root 4096 Oct 24 21:49 ipc
drwxr-xr-x 4 root root 4096 Oct 24 21:49 kernel
drwxr-xr-x 5 root root 4096 Oct 24 21:49 lib
-rw-r--r-- 1 root root 44488 Oct 20 00:46 Makefile
drwxr-xr-x 2 root root 4096 Oct 24 21:49 mm
-rw-r--r-- 1 root root 217435 Oct 20 00:47 Module.symvers
drwxr-xr-x 33 root root 4096 Oct 24 21:49 net
drwxr-xr-x 10 root root 4096 Oct 24 21:49 scripts
drwxr-xr-x 4 root root 4096 Oct 24 21:49 security
drwxr-xr-x 16 root root 4096 Oct 24 21:49 sound
drwxr-xr-x 2 root root 4096 Oct 24 21:49 usr
[root@EMMRTR01 2.6.13-1.1532_FC4-i686]#
I want to apply Julian Anastasov's kernel patches for advanced routing (routes-2.6.13-12.diff) to this kernel and then build an rpm of the kernel so I can install it on this machine or any other machine easily. Can somebody tell me what the command is I should run? By the way, I have already downloaded routes-2.6.13-12.diff to /root/.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
cd /usr/src/kernels
ln -s 2.6.13-1.1532_FC4-i686 linux
patch -p0 < ~/routes-2.4.29-9.diff
cd linux
make clean
make menuconfig
make dep
make zImage
make modules
blah blah blah


It's outlined in the documentation distributed with the sources.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Can't you just patch the module (*.o) that needs be patched and then insmod it? Depends what's built-in and what modular with your setup I suppose.

If you didn't need to apply a patch, there are RPM packages for updating the kernel that do everything for you with one command (rpm -Uvh xxxxxx-kernel.rpm). I tried this for my Fedora Core 4 and I didn't have to do a single thing. Additionally, everything worked fine afterwards, except for my graphics driver which just needed to be recompiled with the new kernel "in mind".
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: n0cmonkey
cd /usr/src/kernels
ln -s 2.6.13-1.1532_FC4-i686 linux
patch -p0 < ~/routes-2.4.29-9.diff
cd linux
make clean
make menuconfig
make dep
make zImage
make modules
blah blah blah


It's outlined in the documentation distributed with the sources.
Is this the steps to install the kernel or to create an rpm? And the line "patch -p0 < ~/routes-2.4.29-9.diff" do I type that in exactly, with the "~" or am I supposed to replace that with the path to the diff file? Do I need to run these form the directory the kernel sources (/usr/src/kernels/2.6.13-1.1532_FC4-i686/) or some other directory?
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Originally posted by: Brazen
Originally posted by: n0cmonkey
cd /usr/src/kernels
ln -s 2.6.13-1.1532_FC4-i686 linux
patch -p0 < ~/routes-2.4.29-9.diff
cd linux
make clean
make menuconfig
make dep
make zImage
make modules
blah blah blah


It's outlined in the documentation distributed with the sources.
Is this the steps to install the kernel or to create an rpm?

That will apply the patch then manually compile the kernel.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I want to apply Julian Anastasov's kernel patches for advanced routing (routes-2.4.29-9.diff)

First, you grabbed the wrong patch. Applying a 2.4 patch to a 2.6 kernel almost certainly won't work and even if it does apply, I wouldn't trust the kernel.

After you apply the patch you should be able to follow the directions like n0c mentioned. Some things like 'make dep' are not necessary with 2.6 kernels and you should use bzImage instead of zImage.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: xtknight
Can't you just patch the module (*.o) that needs be patched and then insmod it? Depends what's built-in and what modular with your setup I suppose.

If you didn't need to apply a patch, there are RPM packages for updating the kernel that do everything for you with one command (rpm -Uvh xxxxxx-kernel.rpm). I tried this for my Fedora Core 4 and I didn't have to do a single thing. Additionally, everything worked fine afterwards, except for my graphics driver which just needed to be recompiled with the new kernel "in mind".

I know there are rpm packages for updating and with Fedora just doing a yum update will update the kernel, but I need to apply Julian's patches to it. If I could apply the patches as a module (*.o) I think I would prefer that, but how could I do that with Julian's patches?
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: Nothinman
I want to apply Julian Anastasov's kernel patches for advanced routing (routes-2.4.29-9.diff)

First, you grabbed the wrong patch. Applying a 2.4 patch to a 2.6 kernel almost certainly won't work and even if it does apply, I wouldn't trust the kernel.

After you apply the patch you should be able to follow the directions like n0c mentioned. Some things like 'make dep' are not necessary with 2.6 kernels and you should use bzImage instead of zImage.

ooops, I did download the correct file to my linux box ( routes-2.6.13-12.diff) I just typed the wrong thing into my post.... I'll edit the post to correct it.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
hmmm, well someone on another forum told me that "yum install kernel-devel" does not install all the kernel source, just what is needed for compiling headers.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
I think you'd just apply the patch normally by n0c's command then:

I think the diff file modifies net.o.

Go to /usr/src/linux/linux/net
and "make" then somehow disable the currently loaded one and load the output file of that make as a module? I'm sure someone will have to correct me here, I'm just guessing. Maybe it's not that easy. :(
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Brazen
Originally posted by: n0cmonkey
cd /usr/src/kernels
ln -s 2.6.13-1.1532_FC4-i686 linux
patch -p0 < ~/routes-2.4.29-9.diff
cd linux
make clean
make menuconfig
make dep
make zImage
make modules
blah blah blah


It's outlined in the documentation distributed with the sources.
Is this the steps to install the kernel or to create an rpm? And the line "patch -p0 < ~/routes-2.4.29-9.diff" do I type that in exactly, with the "~" or am I supposed to replace that with the path to the diff file? Do I need to run these form the directory the kernel sources (/usr/src/kernels/2.6.13-1.1532_FC4-i686/) or some other directory?

~/ is your home directory. Replace it if you put the patch somewhere else.

You run it from where I put you in my instructions.

The instructions would create a kernel, not an RPM.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
I downloaded the kernel source (kernel-2.6.13-1.1532_FC4.src.rpm)

install with:
# rpm -ivh kernel-2.6.13-1.1532_FC4.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES

[root@EMMRTR01 root]# mkdir /usr/src/redhat
[root@EMMRTR01 root]# mkdir /usr/src/redhat/SOURCES

# rpm -ivh kernel-2.6.13-1.1532_FC4.src.rpm
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
ok, I removed kernel-devel, downloaded the SRPM for the latest kernel and installed it with
# rpm -ivh kernel-2.6.13-1.1532_FC4.src.rpm
and got the error:
error: cannot create %sourcedir /usr/src/redhat/SOURCES
So, I created the directories manually:
# mkdir /usr/src/redhat
# mkdir /usr/src/redhat/SOURCES
I then tried installing it again and it worked. It looks like I now have some junk under /usr/src/redhat/ in two folders: SPECS and SOURCES
A Howto said to change to a folder under your home directory and issue the rpmbuild command on the spec file, but there is nothing under my home directory so I changed to cd /usr/src/redhat/SPECS/ and ran the command and got the following error:
# rpmbuild -bp kernel-2.6.spec
-bash: rpmbuild: command not found
How do I get the rpmbuild command? (btw, thanks for the instructions for compiling and installing the kernel but I'd really like to create an rpm for it, although I would also like to learn to compile and install so I will go over those instructions also I think)
EDIT: I found how to get the rpmbuild command, and also realised I needed gcc and redhat-rpm-config. I installed them both with:
# yum -y install rpm-build gcc redhat-rpm-config
Now issuing the rpmbuild command says i386 arch is not included, but I don't want i386, I want i686 (I think), so I crossed my fingers and ran:
rpmbuild -bp --target=i686 kernel-2.6.spec
The program apparently ran successfully. There was a ton of output, but nothing that indicated an error.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I don't think I've ever compiled a kernel RPM, back when I used RedHat I was just compiled and installed them by hand. Now that I use Debian, virtually everything is taken care of by make-kpkg.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Now I just don't know how to add Julian's patch. Should I use the patch command, or should I use the rpmbuild command again?

btw: it looks like the previous rpmbuild command put files in /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/ and this is where the source files are that I want to work on now to add Julian's patches.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Thats what I do to. RPM is kinda difficult. i just leave the default kernel installed to fill any dependancies, but install by hand.

To install manually...

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.4.tar.gz
tar zxf linux-2.6.13.4.tar.gz
cd linux-2.6.13.4/
patch -p1 < ../thepatchyouneed (generally)
make clean
make menuconfig
make
make install && make modules modules_install

then edit the bootloader to use the new custom kernel, double check everything, then reboot.
There are variations and such, like if you need to make a initrd image. There are usually distro-specific scripts to help do that.

If you want to copy the default kernel as closely as possible you will have to figure out to make a initrd image and then locate a copy of the config file used for the defualt kernel. Usually there is one in /boot/

Then you go:
cd /usr/src/linux-whatever
cp /boot/config-whatever ./.config
make clean (if you used the sources already)
make oldconfig
then go on with make menuconfig and the rest of it.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: drag
Thats what I do to. RPM is kinda difficult. i just leave the default kernel installed to fill any dependancies, but install by hand.

To install manually...

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.4.tar.gz
tar zxf linux-2.6.13.4.tar.gz
cd linux-2.6.13.4/
patch -p1 < ../thepatchyouneed (generally)
make clean
make menuconfig
make
make install && make modules modules_install

then edit the bootloader to use the new custom kernel, double check everything, then reboot.
There are variations and such, like if you need to make a initrd image. There are usually distro-specific scripts to help do that.

If you want to copy the default kernel as closely as possible you will have to figure out to make a initrd image and then locate a copy of the config file used for the defualt kernel. Usually there is one in /boot/

Then you go:
cd /usr/src/linux-whatever
cp /boot/config-whatever ./.config
make clean (if you used the sources already)
make oldconfig
then go on with make menuconfig and the rest of it.

What is the differnce between -p0 and -p1 ? The --help page says "-p NUM --strip=NUM Strip NUM leading components from file names." What does that mean?
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Brazen
Originally posted by: drag
Thats what I do to. RPM is kinda difficult. i just leave the default kernel installed to fill any dependancies, but install by hand.

To install manually...

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.4.tar.gz
tar zxf linux-2.6.13.4.tar.gz
cd linux-2.6.13.4/
patch -p1 < ../thepatchyouneed (generally)
make clean
make menuconfig
make
make install && make modules modules_install

then edit the bootloader to use the new custom kernel, double check everything, then reboot.
There are variations and such, like if you need to make a initrd image. There are usually distro-specific scripts to help do that.

If you want to copy the default kernel as closely as possible you will have to figure out to make a initrd image and then locate a copy of the config file used for the defualt kernel. Usually there is one in /boot/

Then you go:
cd /usr/src/linux-whatever
cp /boot/config-whatever ./.config
make clean (if you used the sources already)
make oldconfig
then go on with make menuconfig and the rest of it.

What is the differnce between -p0 and -p1 ? The --help page says "-p NUM --strip=NUM Strip NUM leading components from file names." What does that mean?

If I understand it correctly: If you look at the top of the patch, you'll see a path that starts with linux/blah/blah/blah.c or something. The -p0 leaves it as is, the -p1 removes the initial linux/. drag put you in the linux directory, I kept you outside of it.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: n0cmonkey
Originally posted by: Brazen
Originally posted by: drag
Thats what I do to. RPM is kinda difficult. i just leave the default kernel installed to fill any dependancies, but install by hand.

To install manually...

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.4.tar.gz
tar zxf linux-2.6.13.4.tar.gz
cd linux-2.6.13.4/
patch -p1 < ../thepatchyouneed (generally)
make clean
make menuconfig
make
make install && make modules modules_install

then edit the bootloader to use the new custom kernel, double check everything, then reboot.
There are variations and such, like if you need to make a initrd image. There are usually distro-specific scripts to help do that.

If you want to copy the default kernel as closely as possible you will have to figure out to make a initrd image and then locate a copy of the config file used for the defualt kernel. Usually there is one in /boot/

Then you go:
cd /usr/src/linux-whatever
cp /boot/config-whatever ./.config
make clean (if you used the sources already)
make oldconfig
then go on with make menuconfig and the rest of it.

What is the differnce between -p0 and -p1 ? The --help page says "-p NUM --strip=NUM Strip NUM leading components from file names." What does that mean?

If I understand it correctly: If you look at the top of the patch, you'll see a path that starts with linux/blah/blah/blah.c or something. The -p0 leaves it as is, the -p1 removes the initial linux/. drag put you in the linux directory, I kept you outside of it.

Ok, so if I am in /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/ then I should use -p1? like this:
# cd /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/
# patch -p1 --verbose ~/routes-2.6.13-12.diff
I'm doing it now, but it is just sitting there, no output, no return to command line, not even harddrive activity. I guess I will let it set for a while.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Oops, I'm an idiot. I left out the "<" so it should be:
# cd /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/
# patch -p1 --verbose < ~/routes-2.6.13-12.diff
This time it ran through in a second, looks like no errors.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
next steps:
# vi Makefile
changed "EXTRAVERSION = -prep" to "EXTRAVERSION = -DeadGatewayDetection"

# make oldconfig

# time make rpm
It's making the rpm now. I guess when it's done I'll see how I did!
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: xtknight
Originally posted by: drag
make install && make modules modules_install

Shouldn't there be an && make between the modules and modules_install?

Yes. No. It's possible. :p

You can combine make statements: make install test is the same as running make install && make test.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Brazen
Oops, I'm an idiot. I left out the "<" so it should be:
# cd /usr/src/redhat/BUILD/kernel-2.6.13/linux-2.6.13/
# patch -p1 --verbose < ~/routes-2.6.13-12.diff
This time it ran through in a second, looks like no errors.

I do that all the time. :p
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
for the 2.6 kernal (tainted gentoo user here) it's make && make modules_install

then the bzimage file is in /usr/src/linux/arch/i386/image/bZimage (if I rember correctly)