How do I compile my own kernel into a deb?
From CLUG Wiki
This is a new page, and might contain technically incorrect information. Please use at your own risk. If you are able to correct any errors or expand this document, please do so.
Contents |
Why
Well, if you don't compile your own kernels, this probably won't interest you. However, if you do, you'll know what a pain it is
maintaining them by hand. Debian, however, gives you a great tool to do it all automatically - make-kpkg.
Prerequsites
apt-get install kernel-package libncurses-dev fakeroot
libncurses-dev is needed for menuconfig If you want to use xconfig or gconfig you will
need QT development libraries or GTK development libraries, respectivly.
fakeroot allows you to do everything (bar installing the kernel) as a non-priviledged user (although being in the
src group might help you to use /usr/src)
Vanilla Kernels or Debian Source
A matter of preference. Personally, I use vanilla kernels (linus's tree) because I like to be able to download patches between versions rather than 30MB tarballs. Debian does patch some stuff quite nicely, but I've never actually managed to find out what patches go in...
If you use vanilla source, hop over to kernel.org and pick up the latest copy (or patch against your previous copy).
If you use debian source,
apt-get install kernel-source-insert your version here
If (for some strange reason) you want to use an initrd and an old kernel source, you will probably want the Debian Source (man make-kpkg for details).
Untar
If you used a deian source, it will be sitting in /usr/src. Go there and tar -xjf it.
If you used vanilla source, find it, untar it (and or patch it).
Configure
Just like any old kernel, you need to configure it.
If you have already compiled your own kernel and are simply updating to a newer version, copy in your .config file
(if you've lost it, you should find a copy in /boot or possibly even /proc/config.gz)
make oldconfig
If you are starting from scatch, run
make menuconfig
make-kpkg
Now comes the debian magic.
make-kpkg --append-to-version '-hostname' --revision '1.00' --rootcmd=fakeroot kernel_image
Now go and make a cup of coffee.
Extra make-kpkg options
Environment variables:
-
CONCURRENCY_LEVEL - If you have lots of processors (or a distcc farm), set this to the relevent number (plus a couple). Actually, it often helps to improve it on uniprocessor machines.
-
MAKEFLAGS - Use this to set make variables (i.e.
CC=gcc-2.95)
Options:
-
--added-patches - Can anyone explain this? I've never used it
-
--arch - Compiling for another architecture, set it here
-
--initrd - If (for some strange reason) you want an initrd with a custom kernel, set this.
-
--targets - Want to find out what other things make-kpkg can build for you, try this.
Install
OK, now scp the kernel over to the machine that will run it (from your uber-fast compiling monster) and dpkg -i it.
Alternatively, if you run your own local Debian repository, use that. You know how ;-)
Does the compile take too long?
Well, why not set up ccache and/or distcc. Get all the computers on your network helping, and cache those compiles.
Gcc 2 is also significantly faster than 3.
Compiling module packages
OK, so you have your fancy new kernel, but you want to use (say) the nVidia proprietory drivers. Well the nice debian team have packaged them for you, so:
# apt-get install nvidia-kernel-source nvidia-kernel-common $ cd /usr/src $ tar -xvzf nvidia-kernel-source.tar.gz $ cd linux $ make-kpkg --append-to-version '-hostname' --revision '1.00' --rootcmd=fakeroot --added-modules nvidia-kernel modules_image # dpkg -i /usr/src/nvidia-kernel-etc # apt-get install nvidia-glx
Done!
Maintaing this page
It can probably be used as the seed for a Compiling your own kernel page, but I can't be bothered to do that - the Debian way is much easier ;-). This page is a horrible mixture of assuming that users know how to compile a kernel and assuming that they are clueless. Go wild! Bridge the divide!
