Debian Kernel Building Mini-HOWTO
Posted by hannibal on Fri 11 Feb 2005 at 18:04
This is intended to be a quick and dirty guide to building your own kernel packages for Debian. For more information, see the links at the end of the article.
1. Install the packages 'kernel-package' and 'fakeroot'.
2. Get a Linux kernel tarball, either from kernel.org or from a Debian package (kernel-source-x.x.xx).
3. Uncompress the tarball to a place of your choice (Debian kernel source packages end up in /usr/src)
4. cd into the kernel source directory
5. Configure your kernel (I prefer 'make menuconfig' - note that for menuconfig you will need libncurses5-dev)
6. Execute this command: fakeroot make-kpkg kernel_image
7. You will have a kernel deb in the parent directory of your kernel source now (e.g. /usr/src). Install it using dpkg (dpkg -i file.deb)
If you use grub, here is what you need to do to get your menu.lst automatically updated.
Create a file /etc/kernel-img.conf and add the following lines:
postinst_hook = /sbin/update-grub
postrm_hook = /sbin/update-grub
do_bootloader = no
This will ensure update-grub is ran upon installation of any kernel packages, self-created or Debian-created.
For many more details about building kernels and Debian, see the following sources:
/usr/share/doc/kernel-package/README.gz (very in depth HOWTO)
/usr/share/doc/grub/README.Debian.gz (covers the grub steps above)
[ Send Message | View Serge's Scratchpad | View Weblogs ]
vi /usr/src/Makefileedit string:time make-kpkg --append_to_version=01 -rev 1 kernel_image
EXTRAVERSION = -foobar
I fail to fully understand all of make-kpkg's options. Perhaps my most basic question would be: when do I have to put a separate option to make modules?
--
Serge van Ginderachter
[ Parent | Reply to this comment ]
[ Send Message | View Serge's Scratchpad | View Weblogs ]
I must say, I'm surprised to read what extra's one needs to do when using Grub. Seems one more reason to me to stick to Lilo :)
--
Serge van Ginderachter
[ Parent | Reply to this comment ]
Also, kernel_image does modules for you as well, and I note you use append_version and rev as well. I thought about covering these things but I thought it would best be left to a more involved discussion of kernel building under Debian (it is a quick and dirty howto you know)
[ Parent | Reply to this comment ]
buildpackage
This target runs the targets clean, and binary, and produces the
complete package using dpkg-buildpackage
binary
This target produces all four Debian kernel packages by running
the targets kernel_source, kernel_headers, kernel_doc and ker-
nel_image.
[ Parent | Reply to this comment ]
As you can see from from that, dpkg -i kernel_image_blahblah automatically updates grub if grub is installed. You don't have to do anything to grub.
2. Note this also: Be sure to ".. compile directly into the kernel (not as modules) support for your boot hardware and
root filesystem. If the hard drive you boot from is
IDE, compile IDE support into the kernel"
This last point means that CONFIG_BLK_DEV_IDEDISK=y in the .config file, which means you won't need an initrd.img. If you compiled without this, then never fear - you needn't rebuild the kernel
again. But instead you MUST make an initrd.img and
amend the grub conf file accordingly before you reboot
into your new kernel. Otherwise the boot will fail
because the root filesystem will not be found.
Do as root:
mkinitrd -o /boot/initrd.img-2.6.6 2.6.6
- where 2.6.6 is the version with possible appendix
eg. -k7
+ add corresponding line to
/boot/grub/menu.lst
___________________________________
title Debian GNU/Linux, kernel 2.6.6
root (hd0,0)
kernel /vmlinuz-2.6.6 root=/dev/hde3 ro
initrd /initrd.img-2.6.6
savedefault
boot
3. Unfortunately all these guides ignore the fact that the apt-getted debian kernel source tree is virgin and its makefile (EXTRAVERSION etc) ought to be configured for your architecture so that any modules etc you subsequently build end up in the right place. This really threw me for a long time and I'm really quite mad about it.
To do this, after apt-getting the debian official source, use module-assistant to prepare a source tree that closely resembles the original - including EXTRAVERSION etc.
Just do "m-a fakesource" and then build using the source tree in
/usr/src/kernel-source-$kvers-$debabi-$subarch
4. There is a serious problem with
rebuilding 2.6.x kernels leading to 'root filesystem not found'-type errors. It seems you must have:
'CONFIG_BLK_DEV_GENERIC=y' or a chipset specific IDE
driver such as for AMD-768 based motherboard
'CONFIG_BLK_DEV_AMD74XX=Y'.
CONFIG_PARTITION_ADVANCED=n
- and possibly other stuff as well.
See http://kerneltrap.org/node/970
[ Parent | Reply to this comment ]
How the heck are we supposed to do our job if you can't even document something as essential as a kernel update from sources for an otherwise stock debian system?
[ Parent | Reply to this comment ]
The lines:
postinst_hook = /sbin/update-grub
postrm_hook = /sbin/update-grub
should read:
postinst_hook = /usr/sbin/update-grub
postrm_hook = /usr/sbin/update-grub
Could you kindly update this article please as above?
This will save some persons upgrading considerable grief.
Thanks in advance,
GR
[ Parent | Reply to this comment ]