Professional Documents
Culture Documents
U Kbuild PDF
U Kbuild PDF
1. Introduction
While the thought of building your own custom kernel may seem daunting at first, the Debian tools
found in the kernel-package package make the procedure rather painless. Once you figure out the
system’s quirks, modifying your custom kernel becomes as natural as installing a package with apt-get.
If you have never built a kernel, or you have and would like to learn more about the Debian packaging
tools, this article is for you.
4. Prepare to Customize
Once you have unpacked the kernel source code, cd into the root of the source tree and run the following
commands:
1
Building Debian Kernel Packages
The first two commands remove obsolete files that could corrupt the build process. The third command
copies the configuration of your system’s working kernel to your new kernel’s configuration. This
provides a solid foundation for the customizations that we will be making.1
make menuconfig
Regardless of which method you choose, each method provides a graphical interface to all configurable
kernel options. These options are organized in a hierarchical structure that is rather intuitive. To add
support for a new file system, navigate to the File Systems section and activate the one you like. Need
support for a SCSI device? Poke around in the Device Drivers -> SCSI Devices section. You will
become comfortable with all of the options available just by browsing through the various categories.
To enable a feature, navigate to it using the arrow keys and press Y. This will build the feature directly
into the kernel. Certain options may be modularized and loaded after the system boots. These options,
designated by < >, may be modularized by pressing M.
Pay close attention to the processor type and device driver options. These options essentially determine
whether the kernel will actually boot. If you are unsure about which processor type to select and are
working on the workstation that you want to update, run uname -m to see what type your current kernel
uses. Consult your system’s documentation to determine what hardware the system has. If there are no
device drivers specific to your hardware, enable support for the corresponding generic driver.
To avoid corrupting our build, we need to remove stale files left over from the previous step:
2
Building Debian Kernel Packages
To build a kernel image with an initial ram disk (initrd), run the following command:
Replace -suffix with a string that will distinguish the kernel you are building from ones you may build
in the future. make-kpkg uses this suffix when naming the Debian package it creates. If you consistently
use the same suffix, you will overwrite previously generated packages each time you build a new image.
Note that the initial ram disk is not needed if you build hardware and file system support for your boot
device directly into the kernel. On my IBM ThinkPad, I boot from a generic IDE hard disk that contains
an ext3 root file system. By choosing to build support for these directly into the kernel, I no longer need
the initial ram disk. Leave off the --initrd option to remove the initial ram disk.
Regardless of which method you choose, make-kpkg will take some time to complete.
Your kernel will then be installed just like any other update issued from the Debian repositories.
9. Conclusion
Kernel packages created with make-kpkg drop your custom kernel, as well as its configuration, in
/boot/. When building future kernels, use the configuration of your current kernel as a starting point.
This can save you a lot of headaches when a wrong processor type or neglected device driver prevents
you from booting the new kernel. Also, be sure not to leave out any of the steps in this procedure
whenever you build a new kernel. Though you may be tempted to dismiss make clean and make
mrproper, for instance, doing so may corrupt your build.
3
Building Debian Kernel Packages
With your new kernel up and running, you should now be comfortable using the Debian packaging tools
to build future releases.
Notes
1. While make clean and make mrproper have no effect if you are starting with a newly unpacked
source tree, I have included them here just to provide a consistent procedure.