Linux kernel config file

Kernel/Traditional compilation

This article is an introduction to building custom kernels from kernel.org sources. This method of compiling kernels is the traditional method common to all distributions. It can be, depending on your background, more complicated than using the Kernels/Arch Build System. Consider the Arch Build System tools are developed and maintained to make repeatable compilation tasks efficient and safe.

Contents

Preparation

It is not necessary (or recommended) to use the root account or root privileges (i.e. via Sudo) for kernel preparation.

Install the core packages

Install the base-devel package group, which contains necessary packages such as make and gcc . It is also recommended to install the following packages, as listed in the default Arch kernel PKGBUILD: xmlto , kmod , inetutils , bc , libelf , git , cpio , perl , tar , xz .

Create a kernel compilation directory

It is recommended to create a separate build directory for your kernel(s). In this example, the directory kernelbuild will be created in the home directory:

Download the kernel source

Download the kernel source from https://www.kernel.org. This should be the tarball ( tar.xz ) file for your chosen kernel.

It can be downloaded by simply right-clicking the tar.xz link in your browser and selecting Save Link As. , or any other number of ways via alternative graphical or command-line tools that utilise HTTP, TFTP, Rsync, or Git.

In the following command-line example, wget has been installed and is used inside the

/kernelbuild directory to obtain kernel 4.8.6:

You should also verify the correctness of the download before trusting it. First grab the signature, then use that to grab the fingerprint of the signing key, then use the fingerprint to obtain the actual signing key:

Note the signature was generated for the tar archive (i.e. extension .tar ), not the compressed .tar.xz file that you have downloaded. You need to decompress the latter without untarring it. Verify that you have xz installed, then you can proceed like so:

Do not proceed if this does not result in output that includes the string «Good signature».

If wget was not used inside the build directory, it will be necessary to move the tarball into it, e.g.

Unpack the kernel source

Within the build directory, unpack the kernel tarball:

To finalise the preparation, ensure that the kernel tree is absolutely clean; do not rely on the source tree being clean after unpacking. To do so, first change into the new kernel source directory created, and then run the make mrproper command:

Kernel configuration

This is the most crucial step in customizing the default kernel to reflect your computer’s precise specifications. Kernel configuration is set in its .config file, which includes the use of Kernel modules. By setting the options in .config properly, your kernel and computer will function most efficiently.

You can do a mixture of two things:

  • Use the default Arch settings from an official kernel (recommended)
  • Manually configure the kernel options (optional, advanced and not recommended)

Default Arch configuration

This method will create a .config file for the custom kernel using the default Arch kernel settings. If a stock Arch kernel is running, you can use the following command inside the custom kernel source directory:

Otherwise, the default configuration can be found online in the official Arch Linux kernel package.

Advanced configuration

There are several tools available to fine-tune the kernel configuration, which provide an alternative to otherwise spending hours manually configuring each and every one of the options available during compilation.

Those tools are:

  • make menuconfig : Command-line ncurses interface superseded by nconfig
  • make nconfig : Newer ncurses interface for the command-line
  • make xconfig : User-friendly graphical interface that requires packagekit-qt5 to be installed as a dependency. This is the recommended method — especially for less experienced users — as it is easier to navigate, and information about each option is also displayed.
  • make gconfig : Graphical configuration similar to xconfig but using gtk. This requires gtk2 , glib2 and libgladeAUR .

The chosen method should be run inside the kernel source directory, and all will either create a new .config file, or overwrite an existing one where present. All optional configurations will be automatically enabled, although any newer configuration options (i.e. with an older kernel .config ) may not be automatically selected.

Once the changes have been made save the .config file. It is a good idea to make a backup copy outside the source directory. You may need to do this multiple times before you get all the options right.

Читайте также:  Putty astra linux ����������

If unsure, only change a few options between compilations. If you cannot boot your newly built kernel, see the list of necessary config items here.

Running lspci -k # from liveCD lists names of kernel modules in use. Most importantly, you must maintain cgroups support. This is necessary for systemd. For more detailed information, see Gentoo:Kernel/Gentoo Kernel Configuration Guide and Gentoo:Intel#Kernel or Gentoo:Ryzen#Kernel for Intel or AMD Ryzen processors.

Compilation

Compilation time will vary from as little as fifteen minutes to over an hour, depending on your kernel configuration and processor capability. Once the .config file has been set for the custom kernel, within the source directory run the following command to compile:

Installation

Install the modules

Once the kernel has been compiled, the modules for it must follow. First build the modules:

Then install the modules. As root or with root privileges, run the following command to do so:

This will copy the compiled modules into /lib/modules/ — . For example, for kernel version 4.8 installed above, they would be copied to /lib/modules/4.8.6-ARCH . This keeps the modules for individual kernels used separated.

Copy the kernel to /boot directory

The kernel compilation process will generate a compressed bzImage (big zImage) of that kernel, which must be copied to the /boot directory and renamed in the process. Provided the name is prefixed with vmlinuz- , you may name the kernel as you wish. In the examples below, the installed and compiled 4.8 kernel has been copied over and renamed to vmlinuz-linux48 :

Make initial RAM disk

If you do not know what making an initial RAM disk is, see Initramfs on Wikipedia and mkinitcpio.

Automated preset method

An existing mkinitcpio preset can be copied and modified so that the custom kernel initramfs images can be generated in the same way as for an official kernel. This is useful where intending to recompile the kernel (e.g. where updated). In the example below, the preset file for the stock Arch kernel will be copied and modified for kernel 4.8, installed above.

First, copy the existing preset file, renaming it to match the name of the custom kernel specified as a suffix to /boot/vmlinuz- when copying the bzImage (in this case, linux48 ):

Second, edit the file and amend for the custom kernel. Note (again) that the ALL_kver= parameter also matches the name of the custom kernel specified when copying the bzImage :

Finally, generate the initramfs images for the custom kernel in the same way as for an official kernel:

Manual method

Rather than use a preset file, mkinitcpio can also be used to generate an initramfs file manually. The syntax of the command is:

  • -k ( —kernel ): Specifies the modules to use when generating the initramfs image. The name will be the same as the name of the custom kernel source directory (and the modules directory for it, located in /usr/lib/modules/ ).
  • -g ( —generate ): Specifies the name of the initramfs file to generate in the /boot directory. Again, using the naming convention mentioned above is recommended.

For example, the command for the 4.8 custom kernel installed above would be:

Copy System.map

The System.map file is not required for booting Linux. It is a type of «phone directory» list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses. This «symbol-name to address mapping» is used by:

  • Some processes like klogd, ksymoops, etc.
  • By OOPS handler when information has to be dumped to the screen during a kernel crash (i.e info like in which function it has crashed).

If your /boot is on a filesystem which supports symlinks (i.e., not FAT32), copy System.map to /boot , appending your kernel’s name to the destination file. Then create a symlink from /boot/System.map to point to /boot/System.map- :

After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot directory along with any other previously existing files:

  • Kernel: vmlinuz-
  • Initramfs: Initramfs- .img
  • System Map: System.map-
  • System Map kernel symlink

Bootloader configuration

Add an entry for your new kernel in your bootloader’s configuration file. See Arch boot process#Feature comparison for possible boot loaders, their wiki articles and other information.

Источник

Kconfig make configВ¶

This file contains some assistance for using make *config .

Use “make help” to list all of the possible configuration targets.

The xconfig (‘qconf’), menuconfig (‘mconf’), and nconfig (‘nconf’) programs also have embedded help text. Be sure to check that for navigation, search, and other general help text.

GeneralВ¶

New kernel releases often introduce new config symbols. Often more important, new kernel releases may rename config symbols. When this happens, using a previously working .config file and running “make oldconfig” won’t necessarily produce a working new kernel for you, so you may find that you need to see what NEW kernel symbols have been introduced.

Читайте также:  Файл системного лога windows

To see a list of new config symbols, use:

and the config program will list any new symbols, one per line.

Alternatively, you can use the brute force method:

Environment variables for *config

KCONFIG_CONFIGВ¶

This environment variable can be used to specify a default kernel config file name to override the default name of “.config”.

KCONFIG_DEFCONFIG_LISTВ¶

This environment variable specifies a list of config files which can be used as a base configuration in case the .config does not exist yet. Entries in the list are separated with whitespaces to each other, and the first one that exists is used.

KCONFIG_OVERWRITECONFIGВ¶

If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not break symlinks when .config is a symlink to somewhere else.

CONFIG_ В¶

If you set CONFIG_ in the environment, Kconfig will prefix all symbols with its value when saving the configuration, instead of using the default, CONFIG_ .

Environment variables for ‘config’

KCONFIG_ALLCONFIGВ¶

(partially based on lkml email from/by Rob Landley, re: miniconfig)

The allyesconfig/allmodconfig/allnoconfig/randconfig variants can also use the environment variable KCONFIG_ALLCONFIG as a flag or a filename that contains config symbols that the user requires to be set to a specific value. If KCONFIG_ALLCONFIG is used without a filename where KCONFIG_ALLCONFIG == “” or KCONFIG_ALLCONFIG == “1”, make *config checks for a file named “all.config” (corresponding to the *config command that was used) for symbol values that are to be forced. If this file is not found, it checks for a file named “all.config” to contain forced values.

This enables you to create “miniature” config (miniconfig) or custom config files containing just the config symbols that you are interested in. Then the kernel config system generates the full .config file, including symbols of your miniconfig file.

This ‘KCONFIG_ALLCONFIG’ file is a config file which contains (usually a subset of all) preset config symbols. These variable settings are still subject to normal dependency checks.

Источник

Kernel/Configuration

This article describes the manual configuration and setup of the Linux kernel. For a method that sets ‘safe defaults’ see the genkernel article.

Contents

The /usr/src/linux symlink should always point to the kernel sources that is currently being used. This can be done in one of three ways:

1. Install the kernel sources with the symlink USE flag active. This will make the /usr/src/linux point to the newly installed kernel sources. If necessary, it can still be modified later with the following two methods:

2. Setting the symlink with the eselect tool:

This outputs the available kernel sources. The asterisk indicates the chosen sources. To change the kernel sources, e.g. to the second entry, do:

3. Setting the symlink manually:

Configuration tools

The kernel offers several tools to configure itself.

Command Description
make config Text based configuration. The options are prompted one after another. All options need to be answered, and out-of-order access to former options is not possible.
make menuconfig An ncurses-based pseudo-graphical menu (only text input). Navigate through the menu to modify the desired options.
make defconfig Generates a new config with default from the ARCH supplied defconfig file. Use this option to get back the default configuration file that came with the sources.
make nconfig Pseudo-graphical menu based on ncurses. Requires sys-libs/ncurses to be installed.
make xconfig Graphical menu using Qt5. Requires dev-qt/qtgui to be installed.
make gconfig Graphical menu using GTK+. Requires x11-libs/gtk+, dev-libs/glib, and gnome-base/libglade to be installed.
make oldconfig Review changes between kernel versions and update to create a new .config for the kernel.
make olddefconfig Generates a new configuration with default values from the ARCH supplied defconfig file while, at the same time, maintaining all the previous options set in the .config file found at /usr/src/linux/.config . This is a fast and safe method for upgrading a config file that has all the configuration options it needs for hardware support while at the same time gaining bug fixes and security patches.
make allyesconfig Enables all configuration options in the kernel. It will set all kernel options to * . Make sure a backup of the current kernel configuration is acquired before using this option!

There are also several scripts to create miscellaneous default configurations. These can make deeper configuration more time efficient. Run the following command for a full list of make targets:

Configuration

This article describes the configuration using the make menuconfig tool, but the procedure is similar for the other menus.

Usage

In the shown menu the blue bar indicates the position of the cursor. With the ↑ and ↓ arrow keys change the position of the cursor. The ← and → arrow keys traverse the menu bar in the bottom and define what happens when the Enter key is pressed. For the menu bar below, Select switches to a sub menu for the menu entries ending with —> while Exit exits a sub menu. As an alternative the Esc key can be pressed twice to exit the application.

Читайте также:  Как удалить все разделы с флешки linux

Pressing an associated letter key A — Z will move the position of the cursor lines that have characters in bold. The Y , M , N keys are excluded from navigation in this way; they are sanctified for other purposes. If a line begins with a Y, M, or N, the next character will be bold and capable of being jumped to. For example, relative to the cursor’s current position, if the next line reads «Network Device Support —>» pressing the E key will move the cursor to that line.

The following symbols can appear in front of the lines in the menus:

Symbol(s) Description
[ ], [*] Options in square brackets can be activated or deactivated. The asterisk marks the menu entry as activated. The value can be changed with the space key. It is also possible to press Y key (Yes) to activate or N key (No) to deactivate the selected entry.

If the option is activated, the selected feature/driver will be built into the kernel and will always be available at boot time.

, , Options in angle brackets can be activated or deactivated, but also activated as module (indicated by a M). The values can be modified by pressing Y / N keys as before or by pressing the M key to activate the feature/driver as a module.

See the Kernel Modules article for differentiation.

, Options in curly brackets can be activated or activated as module but not be deactivated. This happens because another feature/driver is dependent on this feature.
-M-, -*- Options between hyphens are activated in the shown way by another feature/driver. There is no choice.

Furthermore some menu entries have a tag at the end:

Tag Description
(NEW) This driver is new in the kernel and is maybe not stable enough.
(EXPERIMENTAL) This driver is experimental and most likely not stable enough.
(DEPRECATED) This driver is deprecated and not needed for most systems.
(OBSOLETE) This driver is obsolete and should not be activated.

Most options have a description, which see by pressing the H key or choosing Help in the menu bar.

Driver selection

See the hardware detection article and the articles in the Hardware category.

Search modules

Within menuconfig , use the / key to search modules by name.

As shown below, the search result will show numbers in front of the matches. Pressing 1 in the example below would make menuconfig jump straight to the option Bluetooth device drivers in the menu structure.

Enabling Gentoo Linux common settings

There is a kernel configuration option called CONFIG_GENTOO_LINUX only present in sys-kernel/gentoo-sources and other Kernel Project maintained kernels. It does nothing on its own, but sets various required configuration options for typical installations.

This setting automatically selects tmpfs and devtmpfs support, which are needed for handling /dev on Gentoo Linux, but might be expanded in the future to enable other mandatory settings for a Gentoo Linux system. For more information, read the help information available through the kernel configuration system as described earlier in this guide.

Build

After configuration has been accomplished successfully, compile the kernel:

For processors with multiple cores, make all the cores do the work. Add the option -j( + 1) . For example, a dual core processor contains two logical cores plus one (2 + 1):

A quad core system contains four logical cores plus one (4 + 1):

Setup

If drivers are activated as modules, they must be installed:

The modules will be copied to a sub directory of /lib/modules .

To install the actual kernel:

This command executes /sbin/installkernel , which is part of the sys-apps/debianutils package. The new kernel is installed into <>>. If a symbolic link /boot/vmlinuz already exists, it is refreshed by making a link from /boot/vmlinuz to the new kernel, and the previously installed kernel is available as /boot/vmlinuz.old . (installkernel man page). The same for config and System.map files. These symlinks are handy, because they always point to the newest kernel without changing the file path (e.g. they can be used in the bootloader configuration).

Bootloader

Change the system’s bootloader configuration to pick up at boot the new kernel.

Finally restart the system with the new kernel.

Comparing current kernel configuration with default configuration

Use the following procedure to get an overview of the kernel configuration settings that deviate from the default. Keep in mind that the modification of one configuration setting may alter additional configuration settings.

The search function in make menuconfig can be used to look up the symbols and their interpretations. When you’re done, clean up:

Источник

Оцените статью