Kernel build command line reference: Chapter 10 - Linux Kernel in a Nutshell
by Greg Kroah-HartmanThis excerpt is from Linux Kernel in a Nutshell.
Linux Kernel in a Nutshell covers the entire range of kernel tasks, starting with downloading the source and making sure that the kernel is in sync with the versions of the tools you need. In addition to configuration and installation steps, the book offers reference material and discussions of related topics such as control of kernel options at runtime.
As discussed in Chapter 4, Configuring and Building, the tool that ties together kernel builds is the make program, to which you pass a target that specifies what you want to build. Chapter 4, Configuring and Building went over the basic targets needed to build the kernel properly, but the kernel build system also has a wide range of other targets. This chapter details these targets, and what they can be used for.
All of these targets are passed to the make program on the command line, and a number of them can be grouped together if desired. For example:
$ make mrproper xconfigThe targets are broken down into different types in the following sections.
You can get a summary of most of these targets by running, within the build directory:
$ make helpThis target prints out a lot of the common make targets that are described in the rest of this chapter.
These targets print the kernel version, based on a number of different options. They are commonly used by scripts to determine the version of the kernel being built.
Table 10.1. Informational targets
Target | Description |
|---|---|
| Displays the current kernel version, as determined by the build system. |
| Displays the current kernel version, as told by the
main Makefile. This differs from the |
These targets simply remove files from previous builds. Their use is highly recommended to make sure you don't contaminate new builds with files left over that may have been built with different options. They differ in how much they remove; sometimes you want to keep around files you've changed.
Table 10.2. Cleaning targets
Target | Description |
|---|---|
| Removes most of the files generated by the kernel build system, but keep the kernel configuration. |
| Removes all of the generated files by the kernel build system, including the configuration and some various backup files. |
| Does everything |
These targets allow the kernel to be configured in a wide range of different ways.
Table 10.3. Configuration targets
Target | Description |
|---|---|
| Updates the current kernel configuration by using a line-oriented program. |
| Updates the current kernel configuration by using a text based menu program. |
| Updates the current kernel configuration by using a QT-based graphical program. |
| Updates the current kernel configuration by using a GTK+-based graphical program. |
| Updates the current kernel configuration by using
the current |
| Just like |
| Generates a new kernel configuration with random answers to all of the different options. |
| Generates a new kernel configuration with the
default answer being used for all options. The default values
are taken from a file located in the |
| Generates a new kernel configuration in which modules are enabled whenever possible. |
| Generates a new kernel configuration with all
options set to |
| Generates a new kernel configuration with all
options set to |
Note that the allyesconfig,
allmodconfig, allnoconfig, and randconfig targets also take advantage of the
environment variable KCONFIG_ALLCONFIG. If that variable points to
a file, that file will be used as a list of configuration values that
you require to be set to a specific value. In other words, the file
overrides the normal behavior of the make targets.
For example, if the file ~/linux/must_be_set contains the following
variables:
$ cat ~/linux/must_be_set
CONFIG_SWAP=y
CONFIG_DEBUG_FS=y and you enter make
allnoconfig with the proper KCONFIG_ALLCONFIG environment variable in
effect:
$KCONFIG_ALLCONFIG=../must_be_set make allnoconfig$grep CONFIG_SWAP .configCONFIG_SWAP=y
then the results include:
$ grep CONFIG_DEBUG_FS .config
CONFIG_DEBUG_FS=y This variable would not have normally been set to
y otherwise.
If the KCONFIG_ALLCONFIG
variable is not set, the build system checks for files in the top-level
build directory named:
allmod.configallno.configallrandom.configallyes.config
If any of those files are present, the build uses them
as lists of configuration values that must be forced to the specified
values. If none of those files are found, the build system finally looks
for a file called all.config for a
list of forced configuration values.
You can use these different files to set up a known good base configuration that will always work. Then the other configuration options can be used to generate different testing configurations for the needed situation.
These targets build the kernel itself in a variety of ways.
Table 10.4. Build targets
Target | Description |
|---|---|
| Builds all of the different targets needed for this kernel to be able to be used. This includes both the modules and the static portion of the kernel. |
| Builds just the static portion of the kernel, not any loadable modules. |
| Builds all of the loadable kernel modules for this configuration. |
| Installs all of the modules into the specified
location. If no location is specified with the |
| Builds all of the files in the specified directory and in all subdirectories below it. |
| Builds only the specified file. |
| Builds all of the needed files and links them together to form the specified module. |
| Builds all of the needed tags that most common text editors can use while editing the source code. |
| Builds all of the needed tags that most common text editors can use while editing the source code. |
| Builds a cscope image, useful in source tree searches, of the source tree for the architecture specified by the configuration file (not all of the kernel source files). |
You can also pass a number of environment variables to make that will change the build. These can be specified for almost any target.
Table 10.5. Environment variables
Variable | Value | Description |
|---|---|---|
| | This tells the build system to run in a quiet manner, showing only the file that is currently being built, and not the entire command that is running in order to build that file. This is the default option for the build system. |
| | This tells the build system to operate in a verbose way, showing the full command that is being used to generate each of the specific files. |
| | This tells the build system to locate all output
files in the |
| | This checks all C files that are about to be built
with the |
| | This forces all C files to be checked with the
|
These targets package up a built kernel into a stand-alone package that can be installed on a wide range of different machines.
Table 10.6. Packaging targets
Target | Description |
|---|---|
| Builds the kernel first and then packages it up as a RPM package that can be installed. |
| Builds a source RPM package containing the base kernel. |
| Builds a RPM package that contains a compiled kernel and modules. |
| Builds a Debian package that contains the compiled kernel and modules. |
| Builds a tarball that contains the compiled kernel and modules. |
| Builds a gzip-compressed tarball that contains the compiled kernel and modules. |
| Builds a bzip2-compressed tarball that contains the compiled kernel and modules. |
These targets build the internal kernel documentation in a variety of different formats.
Table 10.7. Documentation targets
Target | Description |
|---|---|
| Builds the kernel documentation as XML DocBook files. |
| Builds the kernel documentation as PostScript files. |
| Builds the kernel documentation as PDF files. |
| Builds the kernel documentation as HTML files. |
| Builds the kernel documentation as a set of man pages, which can then be installed with the installmandocs target. |
Each kernel architecture has a set of specific targets unique to it. The 32-bit Intel architecture has the following targets available.
Table 10.8. 32-bit Intel Architecture-Specific Targets
Target | Description |
|---|---|
| Creates a compressed kernel image and places it in
the |
| Installs the kernel image using the
distribution-specific |
| Creates a boot floppy image and writes it to the
|
| Creates a boot floppy image and places it in the
file |
| Creates a CD-ROM boot image and places it in the
file |
These targets are good for trying to find problem code in the
kernel. It's a good idea to create a stack space list when creating new code to
determine that your changes are not taking up too much kernel stack
space. The namespacecheck target is
useful for determining whether your changes can safely add its symbols
to the kernel's global namespace.
Table 10.9. Analysis targets
Target | Description |
|---|---|
| Generate a list of the functions that use the most of the kernel stack space. |
| Generate a list of all of the kernel symbols and their namespaces. This will be a large list. |
If you enjoyed this excerpt, buy a copy of Linux Kernel in a Nutshell
