LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-01-2009, 03:15 AM   #1
titaniumdecoy
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Rep: Reputation: 0
Recompile and install only unmodified parts of kernel


I am using these instructions to make and install a vanilla kernel with make-kpkg and dpkg.

However, it takes a very long time to compile the kernel.

Since the purpose of compiling my own kernel is to modify it, how can I only make and install those parts of the kernel and/or modules that have changed? Is there an update option for dpkg? Also, do I need to recompile and reinstall kernel-headers after each modification or just kernel-image?

Thanks.

Last edited by titaniumdecoy; 01-01-2009 at 03:16 AM.
 
Old 01-01-2009, 12:39 PM   #2
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by titaniumdecoy View Post
I am using these instructions to make and install a vanilla kernel with make-kpkg and dpkg.

However, it takes a very long time to compile the kernel.
No it doesn't. If you have a quad-core processor, that is. Here is the script that I use to compile kernels. Note the CONCURRENCY_LEVEL line. Even if you only have a single core, you can probably get away with using 2.
Code:
#!/bin/sh
export CONCURRENCY_LEVEL=4
make-kpkg clean
fakeroot make-kpkg --append_to_version -k8 --revision=0.1 --initrd kernel_image
Code:
Since the purpose of compiling my own kernel is to modify it, how can I only make and install those parts of the kernel and/or modules that have changed?
It depends on what you're trying to do. If you are modifying the code in a loadable module, you can recompile just the directory holding that module, and thus that module, by using something like this. Say you're working on the sata_nv driver. Of course you wouldn't be able to do this if you were booted from sata_nv, but it shows the general idea.
Code:
make M=drivers/ata
rmmod sata_nv
insmod drivers/ata/sata_nv.ko
Added: However, it's not a good idea to leave it like this once you get it working properly. You should remake the kernel and reinstall it.

Quote:
Is there an update option for dpkg?
You can see all the options by typing "man dpkg", but I don't think there is an update. Make-kpkg does an awful lot to make the .deb file.

Quote:
Also, do I need to recompile and reinstall kernel-headers after each modification or just kernel-image?
You don't have to install any kernel-headers package. Your kernel source is, by definition, the kernel-headers.

To replace a kernel with a new one of the same version, we normally would change the revision in the make command, and move the /lib/modules for the old one. To do so, generally follow this:
Code:
<make the new kernel file>
mv /lib/modules/kernelnumber  /lib/modules/kernelnumber.bak  (this is the one already installed)
dpkg -i newkernel

Last edited by Quakeboy02; 01-01-2009 at 12:40 PM.
 
Old 01-02-2009, 04:45 PM   #3
titaniumdecoy
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks, Quakeboy02. I'm still a little confused, though. Let's say I wanted to leave all the modules and headers intact but only update the kernel itself. You wrote that I could do this:

Code:
<make the new kernel file>
mv /lib/modules/kernelnumber  /lib/modules/kernelnumber.bak  (this is the one already installed)
dpkg -i newkernel
What do I replace <make the new kernel file> with? Thanks.
 
Old 01-02-2009, 05:08 PM   #4
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by titaniumdecoy View Post
Thanks, Quakeboy02. I'm still a little confused, though. Let's say I wanted to leave all the modules and headers intact but only update the kernel itself. You wrote that I could do this:

Code:
<make the new kernel file>
mv /lib/modules/kernelnumber  /lib/modules/kernelnumber.bak  (this is the one already installed)
dpkg -i newkernel
What do I replace <make the new kernel file> with? Thanks.
OK, let's say that you have compiled kernel version 2.6.28 with the following commands:
Code:
export CONCURRENCY_LEVEL=2 (or whatever is appropriate for your system)
make-kpkg clean
fakeroot make-kpkg --append_to_version -k8 --revision=0.1 --initrd kernel_image
This gives you the output file: linux-image-2.6.28-k8_0.1_i386.deb (assuming x86_32) which you have installed with the following command, and subsequently booted:
Code:
sudo dpkg -i linux-image-2.6.28-k8_0.1_i386.deb
Now, you make some changes to the source and recompile it with this command:
Code:
export CONCURRENCY_LEVEL=4
make-kpkg clean   (I prefer to start from a cleaned source tree each time)
fakeroot make-kpkg --append_to_version -k8 --revision=0.2 --initrd kernel_image
Notice that I have changed the revision to 0.2 so that you have a new .deb file named: linux-image-2.6.28-k8_0.2_i386.deb. If you simply try to install this one over the running 2.6.28 (regardless of the revision number), the installer will complain that you may mess up some loadable modules. Instead, what you need to do is the following in this order:
Code:
sudo mv /lib/modules/2.6.28-k8   /lib/modules/2.6.28-k8.bak
sudo dpkg -i linux-image-2.6.28-k8_0.2_i386.deb
Then reboot. In practice, for a running kernel, I substitute `uname -r` for "2.6.28-k8" or whatever the kernel version to help avoid typos; i.e.
Code:
sudo mv /lib/modules/`uname -r` /lib/modules/`uname -r`.bak
It would appear that you have pulled the rug out from under yourself with the "mv" command and that this will kill your running kernel. But what actually happens is that the kernel is linked to the modules that are running, so it doesn't really matter whether you rename or even remove the subdirectory. What's important is that you get it out of the way so that dpkg can install the new subdirectory without any conflicts with modules.

Hope this helps.

Last edited by Quakeboy02; 01-02-2009 at 05:10 PM. Reason: missing code closer
 
Old 01-03-2009, 03:04 AM   #5
titaniumdecoy
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Recompiling all the modules each time takes forever. Is there any way to only remake only the kernel itself and leave /lib/modules/`uname -r` intact?

Last edited by titaniumdecoy; 01-03-2009 at 03:09 AM.
 
Old 01-03-2009, 12:41 PM   #6
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by titaniumdecoy View Post
Recompiling all the modules each time takes forever. Is there any way to only remake only the kernel itself and leave /lib/modules/`uname -r` intact?
See my second paragraph of post #2. And disable any modules you don't need.

Have you tried increasing your concurrency level? On my quad core machine, a level of 4 brought the total compile time down to under 12 minutes. You can often get away with not doing the "clean", as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile and install modules without kernel recompile. marquisdesade Linux - Kernel 9 02-20-2010 07:19 AM
LXer: Virtual Windows to Run Unmodified on Linux LXer Syndicated Linux News 0 02-12-2007 08:54 AM
How do I install a program from a shell, and how do I update parts of Linux? banjzooie Linux - Software 3 02-11-2006 09:48 AM
Adding parts to kernel without recompile scuzzman Linux - Newbie 3 01-14-2005 06:34 AM
Module Install without Kernel Recompile? bongski55 Linux - General 4 09-29-2003 12:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration