Latest linux kernel. Building the kernel in Ubuntu. Step-by-step instruction. Where to download the Linux kernel

I have long wanted to write an article on how to build the Linux kernel. And now this moment has come.

Actually, why build a kernel if the distribution provides a perfectly usable kernel?

For example, in order to use the latest drivers and solutions provided in the new kernel, when only the old branch is available from the distribution. Also, for example, to customize it for your hardware and speed up the work a little. I made 3.11 for myself, because it contains a set of patches that improve work with ATI video cards, and I am the owner of one of them.

A lot of articles have been written about assembling the kernel, so I will not go into details, but will only write how I assemble the kernel for myself.

First of all, you need to get the archive with the source codes of the desired version of the Linux kernel.

On the site https://www.kernel.org/ you can download the desired version. I will describe the build and installation process using version 3.11.0 as an example.

It is advisable to build the kernel in a directory specially created for this purpose under an unprivileged user. I compile in a folder ~src/linux/linux-version

Before compiling, you should make sure that all the dependencies necessary for building are installed and about 3GB of free space in the compilation directory.

Here is a list of packages to compile successfully (for Debian/Ubuntu):

gcc, make- Necessary assembly and linking tools. Preferably one of the latest gcc versions available.

libncurses5-dev- needed for menuconfig to work

ccache- allows you to speed up the reassembly

If you want to use the graphical kernel configurator, then you should also install packages for QT development, for example libqt4-dev, g++, pkg-config.

Lzop, lz4c- if you are interested in alternative kernel and initramfs compression mechanisms.

The current directory is assumed to be the directory of the unpacked kernel.

After the build environment is prepared, the kernel configuration needs to be generated. The current configuration can be viewed like this:

Cat /boot/config-`uname -r`

Zcat /proc/config.gz

In principle, you can use the current config by editing it in one of the configuration programs. Copy it to the directory where the archive with the kernel is unpacked and rename it as .config

cp /boot/config-`uname -r` .config

I like xconfig, I find it the most convenient.

Make xconfig

Previously copied is loaded automatically .config, which serves as our base for the configuration. There are a lot of tips for setting up the kernel, I only recommend choosing your version of the processor, disabling hardware drivers that are not there, you can also select additional modules, such as zram and the compression algorithm, I chose lz4 as the fastest.

After saving the configuration, you can start compiling.

If you are too lazy to configure the kernel manually, it is possible to auto-configure using information about loaded modules: make localmodconfig

Now the second main step is compiling the kernel and modules. Executed in one command:

Make -j4 CC="ccache gcc" bzImage modules

Where -j4 corresponds to the number of processor cores in your configuration.

Compilation will not take long if the hardware is powerful enough and the distribution kernel config is not used. On my laptop with an AMD Phenom P820 processor and six gigabytes of RAM, the compilation takes about half an hour.

The last step is to install the kernel and modules.

Sudo sed -i.bak "s/MODULES=most/MODULES=dep/" /etc/initramfs-tools/initramfs.conf

This is necessary in order to reduce the size of the initrd file by including only the modules necessary for loading.

The installation can also be done with one command:

sudo make modules_install install

Or install everything manually. Modules First

sudo make modules_install

Then the core

Version=`awk "NR<=3 {printf "%s.",$NF}" < Makefile | sed "s/\.$//"`

this is how we get the kernel version from the Makefile

sudo cp arch/`uname -m`/boot/bzImage /boot/vmlinuz-$version sudo cp .config /boot/config-$version sudo cp System.map /boot/System.map-$version sudo update-initramfs - c -k $version sudo update-grub

Finally, I am attaching a script to automate the process.

During the configuration of the config, he can ask a couple of questions, to answer by default, you just need to press Enter.

Happy compilation.

Why would someone want to compile a new kernel? It is often not necessary since the default kernel shipped with Debian handles most configurations. Also, Debian often offers several alternative kernels. So you may want to check first if there is an alternative kernel image package that better corresponds to your hardware. However, it can be useful to compile a new kernel in order to:

Don't be afraid to try compiling the kernel. It's fun and profitable.

To compile a kernel the Debian way, you need some packages: , and a few others which are probably already installed (see for the complete list).

This method will make a .deb of your kernel source, and, if you have non-standard modules, make a synchronized dependent .deb of those too. It's a better way to manage kernel images; will hold the kernel, the System.map, and a log of the active config file for the build.

Note that you don't have to compile your kernel the “Debian way”; but we find that using the packaging system to manage your kernel is actually safer and easier. In fact, you can get your kernel sources right from Linus instead of , yet still use the compilation method.

Note that you'll find complete documentation on using under . This section just contains a brief tutorial.

Hereafter, we'll assume you have free rein over your machine and will extract your kernel source to somewhere in your home directory. We'll also assume that your kernel version is 3.16. Make sure you are in the directory to where you want to unpack the kernel sources, extract them using and change to the directory that will have been created.

Now, you can configure your kernel. Run if X11 is installed, configured and being run; run otherwise (you'll need installed). Take the time to read the online help and choose carefully. When in doubt, it is typically better to include the device driver (the software which manages hardware peripherals, such as Ethernet cards, SCSI controllers, and so on) you are unsure about. Be careful: other options, not related to a specific hardware, should be left at the default value if you do not understand them. Do not forget to select "Kernel module loader" in "Loadable module support" (it is not selected by default). If not included, your Debian installation will experience problems.

Clean the source tree and reset the parameters. To do that, do.

Now, compile the kernel: . The version number of “1.0” can be changed at will; this is just a version number that you will use to track your kernel builds. Likewise, you can put any word you like in place of “custom” (e.g., a host name). Kernel compilation may take quite a while, depending on the power of your machine.

Once the compilation is complete, you can install your custom kernel like any package. As root, do . The part is an optional sub-architecture, depending on what kernel options you set. will install the kernel, along with some other nice supporting files. For instance, the will be properly installed (helpful for debugging kernel problems), and will be installed, containing your current configuration set. Your new kernel package is also clever enough to automatically update your boot loader to use the new kernel. If you have created a modules package, you'll need to install that package as well.

It is time to reboot the system: read carefully any warning that the above step may have produced, then .

For more information on Debian kernels and kernel compilation, see the Debian Linux Kernel Handbook. For more information on , read the fine documentation in .

If you remember, not so long ago we learned how to build the FreeBSD kernel from source. The question is, why not learn to do the same with the Linux kernel? The reasons for building the Linux kernel from source are, in general, the same - getting the latest version of the kernel, urgently applying security patches, optimizing for specific tasks and specific hardware, and also the desire to take part in kernel development, even in the role of QA.

Important! Following the instructions in this post may result in the loss of your data. Make backups and remember that you do everything at your own peril and risk. Everything described below has been tested on Ubuntu 14.04 LTS. But on other versions of Ubuntu, as well as other Linux distributions, the differences should be minimal.

Setting up the bootloader

Edit /etc/default/grub like this:

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=10
#GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i-s2>/dev/null ||echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

After editing we say:

sudo update-grub

As a result, before the system boots, you will be prompted for 10 seconds to select the kernel with which you want to boot. Very handy if you mess up your kernel configuration and want to boot with a previous version!

Install dependencies

We will need at least the following packages:

sudoapt-get installgitgccmakebc fakeroot dpkg-dev\
libncurses5-dev libssl-dev

On many systems, all of them, however, will already be present.

Getting the source

wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.6.4.tar.xz
tar-xz-xvf linux-4.6.4.tar.xz
cd linux-4.6.4

Or, if you want the very latest, you can grab the source directly from Git:

# Mirror: https://github.com/torvalds/linux
git clone'git://git.kernel.org/pub/scm/linux/kernel/git/'\
'torvalds/linux.git'
cd linux

Judging by the fact that I could not find the v4.6.4 tag in Git, Linux kernel releases are made exclusively in the form of compressed tar archives.

If, instead of a vanilla kernel, you would like to build a kernel with patches from Canonical:

git clone git://kernel.ubuntu.com/ubuntu/ubuntu-trusty.git
cd ubuntu-trusty
git tag|less
git checkout Ubuntu-lts-4.4.0-31.50_14.04.1

From my own experience, if you use Ubuntu, you can safely use the vanilla kernel. It is unlikely that you will have any problems with it.

Note: Interestingly, of the existing relatively popular Linux distributions, only Gentoo, Slackware, and Arch Linux seem to use a kernel without their own patches.

Anyway, now you have the source code.

Compiling and installing the kernel

Select the options with which the kernel will be built:

If necessary, change the settings, click Save, then Exit. As a result, a file containing the parameters we selected will be created.

At update kernel (are you already using some kind of kernel anyway?) it is convenient to take the config of the current kernel, and set the new options to their default values:

zcat/proc/config.gz > ./.config
make olddefconfig

Finally, we collect:

make-j4 bindeb-pkg LOCALVERSION=-custom

The core is assembled for quite a long time. On my laptop, the assembly took 1 hour and 15 minutes. However, from this time about The rest is spent building a giant kernel package with debug symbols.

Manual build and configuration of the Linux kernel

The assembly of this package can be disabled by commenting out the CONFIG_DEBUG_INFO parameter in the config. Just be aware that this package is required by SystemTap and other useful tools.

In addition to the kernel itself, you can also collect documentation:

# there is also `make pdfdocs` and others, see `make help`
make htmldocs
chromium-browser Documentation/DocBook/index.html

Upon completion of assembly subsidiary directory we see something like:

linux-firmware-image-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-headers-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-image-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-image-4.4.13-custom-dbg_4.4.13-custom-1_amd64.deb
linux-libc-dev_4.4.13-custom-1_amd64.deb

We put all deb-packages except for the dbg-version of the kernel with the usual ones and reboot. After rebooting, we look at the output of the command. We make sure that we really booted with the new kernel. If something is wrong with the new kernel, in the bootloader we simply select the one with which the system was booted before. After booting with the old kernel, we quickly remove the packages of the new kernel, and voila - the system returned to its previous state.

Additionally, after loading a new kernel, you can run tests on it:

sudomake kselftest
sudomake kselftest-clean

Congratulations, you now know how to build the Linux kernel!

Conclusion

Materials on the internals of the Linux kernel:

  • KernelNewbies.org, a site for newbies to the Linux kernel with its own mailing list, IRC channel, forum, wiki, and more;
  • LKML.org, a site for comfortable reading the mailing list of Linux kernel developers through a browser. Be careful, it often spoils the formatting of letters! In this sense, the mailing list archive at marc.info is much better;
  • Linux Cross Reference, a site for comfortable reading of Linux kernel code through a browser;
  • The book Linux Kernel Development, 3rd Edition is the most recent book on the Linux kernel in English (2010, kernel 2.6.x), there is a translation into Russian;
  • The book Linux-Treiber entwickeln, 4th Edition is more recent (2015, kernel 4.x), but is written in German and has no translation;
  • The free Linux Insides book by Alexander Kuleshov a.k.a @0xAX looks to be the most accessible and up-to-date, but is currently in the process of being written;
  • Sometimes you can find something useful in the Linux Kernel HTML Documentation, the official documentation from the Linux kernel sources;
  • Examples for the book Linux Device Drivers, 3rd Edition, which are trying to keep up to date, plus sources for the 4th edition, which is currently being written;

Do you build the kernel from source, and if so, why? 🙂

Addition: You may also be interested in the article The Scandalous Truth About Debugging Kernel Code on Linux.

Tags: Linux, Ring0.

Compiling the linux kernel


Many consider it a pointless waste of time in order to show oneself as a smart and advanced "Linuxoid". In fact, compiling the kernel is a very important thing. Let's say you bought a new laptop that doesn't have a working webcam. Your actions? You look into the search engine and look for a solution to the problem on this issue. Quite often it may turn out that your webcam is running on a newer version of the kernel than you have. If you don't know what version you have, type uname -r in the terminal, as a result you will get the kernel version (for example, linux-2.6.31-10). Also, kernel compilation is widely used to increase performance: the fact is that kernel distributions are compiled “for everyone” by default, because of this, it includes a huge number of drivers that you may not need. So if you know your hardware well, you can disable unnecessary drivers at the configuration stage. It is also possible to enable support for more than 4 gigabytes of RAM without changing the bit depth of the system.

How to build a linux kernel? Building the Linux Kernel

So, if you still need to have your own kernel, let's start compiling!


The first thing to do is get the source code for the desired kernel version. Usually you need to get the newest stable version. All official kernel versions are available at kernel.org.

If you already have an X server (home computer) installed, then you can go to the site in your favorite browser and download the desired version in a tar.gz archive (compressed gzip). If you are working in the console (for example, you have not yet installed the X server or are configuring the server), you can use a text browser (for example, elinks).

You can also use the standard wget download manager:


tar -zxvf path_to_archive

Kernel configuration.

Compilation.
make && make install
We wait from 20 minutes to several hours (depending on the power of the computer). The kernel is installed. To make it appear in the grub(2) list, type (as root)
update-grub


Article archive:
May 2017
March 2017
April 2016
March 2016
October 2013
September 2013
May, 2013
March 2013
November 2012
July 2012
June 2012
April 2012
March 2012
February 2012
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010

Random:

Stellarium virtual planetarium: an overview of new features

BOINC: computing for science

Gambas: Basic development on linux

SSH 2.0 Serial Diagrams

Linuxnow.ru: Plans for the future

Suddenly running out of free disk space? Perhaps the problem is in the logs.

Colleagues: all
Linux for everyone

Our banners:


Set banner

Linux kernel configuration

Checking source packages

Recompiling a kernel requires its sources.

Blog about system administration. Articles about Linux, Windows, NetApp storage and virtualization.

Red Hat places the kernel sources in a single rpm package, but is not installed by default. The name of this package:

kernel-source-2.4.2-2.1386.rpm

In addition to source code, to recompile the kernel, you need a compiler that consists of two components:

make utility;

the compiler of the C language itself is gcc or egcs.

Creating a backup copy of the current kernel is carried out in three stages:

1. Creation of a backup copy of the kernel sources, which allows you to restore it if the configuration is damaged.

2. Creating a backup copy of the kernel itself as a known working means of launching the system.

3. Creation of a new entry for the operating system loader, which can be used to boot from the kernel backup.

Creating a source backup is done by copying the kernel source directory to disk. Recovery is done by copying in the opposite direction.

When the kernel is recompiled, the old kernel is written to a file with the .old extension. However, this copy of the kernel cannot yet be used to boot the system. This explains the need to perform the above operations.

The LILO-type operating system loader, commonly used to boot Linux, is configured by linking to a kernel file in the root file system.

After backing up the kernel, you need to add another entry to the /etc/lilo.conf file to allow you to start Linux with the old kernel:

open file /etc/lilo. conf in a text editor

create a copy of the entire partition;

change two positions in the copy:

replace the kernel file name with the name of its backup copy (together with the extension);

replace partition label with something like linux. original (original Linux) or linux-previous (old Linux).

lines beginning with initrd should be replaced with appropriate fallbacks, such as initrd-2 .4.2-2. orig. img;

write changes to /etc/lilo. conf.

enter the command /sbin/lilo to enter a new entry in the bootloader. When you run the lilo command, the labels of the images entered into the operating system boot loader are displayed on the screen.

The next time the system is rebooted, the new kernel ID will be displayed in the LILO boot loader tooltip.

Configuring a New Kernel

Configuration decides which features to include in the kernel, which not to include, and so on. You can choose between configuring an old kernel and installing/configuring a new one. For example, using Red Hat Linux 7.1, you can reconfigure an existing 2.4.2 kernel with new options. You can also download and install the new 2.4.4 kernel. Although the configuration details are different in the two cases, the utilities used and the configuration methodology itself are the same.

Linux has three separate configuration utilities, each with its own characteristics.

A utility with a command line interface. The user consistently answers questions about the features that need to be included in the kernel. This utility is useful for those who know how to work with the kernel, and for those who have configuration scripts for this utility.

Utility with text mode menu. The multi-level menu of this utility allows you to set and reinstall kernel parameters in any order.

GUI utility. This is the most attractive utility, but it only runs on the graphical X Window System.

The listed utilities create the same configuration file used by the make utility when compiling full or partial kernels.

Kernel options

When reviewing settings in any configuration program (command line, text-based or GUI), you need to be clear about the impact these settings have on the operation of the kernel.

The identification of parameters in each program is different, but in all three the same set of them is presented. The parameters are divided into two main groups:

modular;

non-modular.

If the program block corresponding to this parameter is not loaded as a kernel module, it can be one of two things:

[*] an integral part of the kernel;

An integral part of the kernel.

The characters in square brackets (together with parentheses) correspond to option labels in the configuration programs menu (except for the command line utility).

For modular parameters, there are three options for setting (according to their representation in the configuration utilities menu):

<>is not included in the kernel and is not created as a module that can be loaded later:

<*>is included in the kernel, so there is no need to load it later as a module:

<М>Included as a module, but not as part of the kernel. A block can be installed or removed from the kernel at any time.

Sometimes the value of a parameter cannot be changed until another parameter is set. For example, you can install support for a specific SCSI device only after enabling support for those devices in general.

When the necessary tools (the make utility and the gcc compiler) and source texts are installed on the system, you can run one of the configuration utilities and start configuring the kernel.

GUI Configurator

Launching the configuration utility with a graphical interface is performed in the following sequence.

Launch an X Windows system (with any graphical environment and desktop).

Open a terminal emulator window (command line window).

As with the launch of the previous utility, several messages about the compilation of the utility will flash on the screen, and after a few minutes its main window will open.

Rice. 8. Kernel configuration utility with a graphical interface: menu-buttons for setting parameter values

The graphical utility is not too different from the menuconf ig utility. Here, the options are also categorized; clicking on a particular category opens a dialog box with a list of options, each of which can be set to a value that determines whether the corresponding tool should be used as part of the kernel, as a loadable module, or not at all.

Such a dialog box is shown in Fig.

Rice. 9. Dialog boxes like this set kernel configuration options

The 2.4.2 kernel in Red Hat Linux supports the symmetrical multiprocessor architecture by default. You must set the corresponding option to n if your computer has only one processor.

To the right of each option is a Help button.

A big advantage of the graphical configuration utility (especially for first-time kernel configurators) is that the menu displays dependencies between different options. For example, in the Block Devices section, you cannot install RAID support built into the kernel until the Multiple Device Driver Support option is enabled.

If in the menuconfig utility the dependence of parameters on each other is shown by the indentation of parameter names in the menu, then in the graphical utility it is simply impossible to set unallowed combinations of parameters. Working with the graphical utility helps to understand the dependencies between different modules.

At the end of the main menu of the graphical utility there are commands similar to the corresponding utility commands from the text mode menu.

Save and Exit (Exit with saving). Creating a kernel configuration file and shutting down the utility.

Quit Without Saving. Shutting down the utility without creating a kernel configuration file.

Without creating a kernel configuration file using one of the listed utilities, recompiling the kernel is not possible.

Load Configuration From File. Loading the configuration file created earlier.

Store Configuration To File. Writing configuration data to a file with the specified name (for further use or transfer to a colleague). This does not affect the need to execute the Save and Exit command, which creates a configuration file for recompiling the kernel.

Compiling and running a new kernel

After the configuration is complete, you need to check for a new configuration file (.config) located in the /usr/src/linux-2 .4.2 directory (depending on the version number). If the .config configuration file is in place, you can use the make command to recompile the kernel.

Typically, kernel recompilation takes from 15 minutes to several hours. It depends on the speed of the processor, the amount of RAM and a number of other factors, so it is convenient to combine all the commands entered during compilation into one, separated by a semicolon, so that they are executed sequentially.

Starting the recompilation process

The commands below are designed to create a new kernel by recompiling all its modules and writing them to the appropriate system directories. (There they will be available to kernel commands.)

To recompile the system, the following commands will be entered.

# make dep; make clean; make bzlmage; make modules; make modules_install

Each make command can be entered separately, after the previous one has completed.

After entering these commands, lines will flash on the screen describing the directories accessed by the make program, the launch of the gcc compiler. for compiling various source files and linking various blocks. Each of these commands will take several minutes to complete.

You can now create a boot disk for the new kernel with the command

Before executing this command, you must insert a formatted floppy disk into the drive. The finished boot disk must be tested. Restart your computer without removing the floppy from the drive.

After executing the kernel compilation commands and returning to the command line, a new kernel is created. To boot a system with a new kernel, it must be moved to the standard directory from which it will run. This is done by entering the command

# cf /usr/src/linux-2.4.2/arch/i386/boot/bzlmage /boot/vmlinuz-2.4.2-2

Finally, to update the boot map, run the lilo command:

You can specify a version number in the name of the kernel image to copy. It is important that the name of this file matches the name specified in the /etc/lilo.conf file.

Testing a new kernel

After moving the new kernel file to the default directory (specified in the lilo.conf file), the system can be rebooted with this kernel.

Immediately after the reboot, check the operation of the new tools for which the recompilation was started. You can do the following.

Comparison of the volumes of the old and new cores. You should check the amount of memory occupied by the operating system by issuing the free command.

Mounting a file system or attempting to access a device without loading a kernel module to support it (if support for that device is built into the kernel).

Using network resources (such as IP aliases) that were not present in the old kernel.

It may be necessary to check the timestamp of the current kernel file. To do this, enter the uname command. This allows you to make sure that the system is currently running with the recompiled kernel. The timestamp and date of the kernel must match the time it was recompiled.

If the response from the uname command indicates that the system was not booted with the new kernel, look into the LILO bootloader. Check if the name of the bootable kernel is correct in the /etc/lilo.conf file.

VIEW MORE:

Compiling and Installing the Linux Kernel from Source in Debian

Material from Bryansk Linux Users Group and www.rm.pp.ru

Each distribution has its own kernel build specifics, and this article focuses on exactly how to do this in Debian Etch. It also reveals the question of how to apply this or that patch to the kernel when it is necessary to support certain functionality or new hardware in your system. The article is intended primarily for more advanced users and there are no guarantees that this method will work as it should and all the described actions and responsibility fall on you.

  1. Note
  2. Method one. Building the kernel into .deb packages
  3. Applying patches
  4. Kernel Configuration
  5. Compiling the kernel
  6. Installing a new kernel
  7. Method two. "traditional" way
  8. Problems
  9. Links

Note

Two methods for building the kernel will be described. The build variant of the .deb packages that may be installed on your or another system will be described first.

The second method is the so-called "traditional" way.

Method one. Building the kernel into .deb packages

Installing the necessary packages for compiling the kernel

First, let's update the package lists:

# apt-get update

Install the packages we need:

# apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential

Downloading the kernel sources

Go to the /usr/src directory, go to www.kernel.org and select the desired kernel version. In this case, the version linux-2.6.23.1.tar.bz2 will be considered. Downloading:

# cd /usr/src # wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.1.tar.bz2

Unpack the sources and create a symbolic link:

# tar xjf linux-2.6.23.1.tar.bz2 # rm linux (remove previous symlink) # ln -s linux-2.6.23.1 linux # cd /usr/src/linux

Applying patches

Optional and unnecessarily do not do this!

Sometimes drivers or features are required that are not supported in the current kernel, such as virtualization technology or other specifics that are not in the current release. In any case, this is corrected by applying so-called patches (if any).

So let's say you've downloaded the required patch (let's call it patch.bz2 for example) to /usr/src. Apply the downloaded patch to our sources (You should still be in the /usr/src/linux directory):

# bzip2 -dc /usr/src/patch.bz2 | patch -p1 --dry-run # bzip2 -dc /usr/src/patch.bz2 | patch-p1

The first command is just a test and no changes will be applied to the sources. If no errors were returned after the first command, you can run the second command to apply the patch. In no case do not execute the second command if errors were issued after the first one!

This way you can apply patches to kernel sources. For example, there are some features that are only available in the 2.6.23.8 kernel, and the sources did not contain the necessary functionality, but patch-2.6.23.8.bz2 was released. You can apply this patch to 2.6.23 kernel sources, but not 2.6.23.1 or 2.6.23.3, etc. You can read more about this at:

Prefixes (prepatches) - equivalent to alpha releases; patches must be applied to sources of a full previous release with a 3-digit version (for example, patch 2.6.12-rc4 can be applied to sources of version 2.6.11, but not to version 2.6.11.10.)

This means that if we want to build the 2.6.23.8 kernel, we need to download the sources for version 2.6.23 (http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.tar.gz) applied in the second way "traditonal" way!

Apply patch-2.6.23.8.bz2 to kernel 2.6.23:

# cd /usr/src # wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.22.8.bz2 # cd /usr/src/linux # bzip2 -dc /usr/ src/patch-2.6.23.8.bz2 | patch -p1 --dry-run # bzip2 -dc /usr/src/patch-2.6.23.8.bz2 | patch-p1

Kernel Configuration

It's a good idea to use the existing configuration file of the running kernel for the new one as well. Therefore, we copy the existing configuration to /usr/src/linux:

# make clean && make mrproper # cp /boot/config-`uname -r` ./.config

# make menuconfig

after which the graphical kernel configuration menu will be loaded. Select "Load an Alternate Configuration File" in the configurator menu and click "OK". Then (if required) make the necessary changes to the kernel configuration by navigating through the menus (kernel configuration details can be found at www.google.com ). When you are done and press "Exit", the question "Do you wish to save your new kernel configuration?" will be asked, we answer in the affirmative "Yes".

Building the Linux Kernel

Compiling the kernel

Building the kernel is done in just two commands:

# make-kpkg clean # fakeroot make-kpkg --initrd --append-to-version=-cybermind kernel_image kernel_headers

After --append-to-version=, you can write whatever name you want, but it must start with a minus sign (-) and not have spaces.

The process of compiling and building .deb packages can take quite a long time. Everything will depend on the configuration of the kernel and the capabilities of your processor.

Solving the problem with creating initrd.img

Recently, a bug has appeared in Debian, consisting in the fact that after installing packages with kernels built in the way described here, the /boot/initrd.img file corresponding to them is not created. To fix an already installed kernel, you will have to create initrd.img manually:

update-initramfs -c -k<полная-версия-ядра>

To solve the problem "for the future" - comment out, as shown, the second of the lines quoted below in the /etc/kernel/postinst.d/initramfs-tools file:

# kernel-package passes an extra arg; hack to not run under kernel-package #[ -z "$2" ] || exit 0

Installing a new kernel

When the kernel build completes successfully, two .deb packages will be created in the /usr/src directory:

# cd /usr/src # ls -l

linux-image-2.6.23.1-cybermind_2.6.23.1-cybermind-10.00.Custom_i386.deb - actual kernel itself and linux-headers-2.6.23.1-cybermind_2.6.23.1-cybermind-10.00.Custom_i386.deb - headers kernels needed to build other modules (for example, when building nVidia driver modules). Installing them:

# dpkg -i linux-image-2.6.23.1-cybermind_2.6.23.1-cybermind-10.00.Custom_i386.deb # dpkg -i linux-headers-2.6.23.1-cybermind_2.6.23.1-cybermind-10.00.Custom_i386.deb

(These packages can now be installed on another system without the need to build them again.)

Everything, the installation is complete, the bootloader menu, the installation of a new RAM disk and the kernel will be done automatically. It remains only to reboot:

Method two. "traditional" way

We carry out all the points described above BEFORE the point "Compiling the kernel".

# make all # make modules_install # make install

As usual, the build can take a long time, depending on the kernel configuration and processor capabilities.

The main disadvantage of this method is that if you frequently update kernels, then after a while a large number of them will accumulate and you will want to remove unused ones. To make this easier, you can build the kernel and other files that are installed into the system using the "make modules_install" and "make install" commands into a deb package (or rather, two starting from kernel 2.6.27) like the first method, but we will use here with kernel scripts:

# make all # make deb-pkg

Two .deb files will appear in the directory one level above the source directory. I compiled the kernel in the /usr/src/linux-2.6.27.10 directory and I got files in the /usr/src/ directory

# linux-2.6.27.10_2.6.27.10-1_amd64.deb # linux-firmware-image_2.6.27.10-1_all.deb

The kernel is installed with the command

# dpkg -i linux-2.6.27.10_2.6.27.10-1_amd64.deb

Old kernels can be removed, for example, from synaptic

Next steps

The kernel is built and installed, but now you need to create a RAM disk (without which the kernel simply won't boot) and you need to update the GRUB bootloader. To do this, do the following:

# depmod 2.6.23.1 # apt-get install yaird

Install the RAM disk:

# mkinitrd.yaird -o /boot/initrd.img-2.6.23.1 2.6.23.1

Let's update the bootloader easily and painlessly:

Everything, the bootloader and the new kernel are ready, it remains only to reboot:

Problems

If after a reboot your chosen new kernel does not boot, reboot and select your previous kernel and you can try to go through the whole process again to build a working kernel. In this case, do not forget to delete the lines of the non-working kernel in /boot/grub/menu.lst.

Compiling the linux kernel

Why compile the kernel yourself at all?
Perhaps the main question that is asked about compiling the kernel is: “Why should I do this?”.
Many consider it a pointless waste of time in order to show oneself as a smart and advanced "Linuxoid". In fact, compiling the kernel is a very important thing. Let's say you bought a new laptop that doesn't have a working webcam. Your actions? You look into the search engine and look for a solution to the problem on this issue. Quite often it may turn out that your webcam is running on a newer version of the kernel than you have. If you don't know what version you have, type uname -r in the terminal, as a result you will get the kernel version (for example, linux-2.6.31-10). Also, kernel compilation is widely used to increase performance: the fact is that kernel distributions are compiled “for everyone” by default, because of this, it includes a huge number of drivers that you may not need. So if you know your hardware well, you can disable unnecessary drivers at the configuration stage.

It is also possible to enable support for more than 4 gigabytes of RAM without changing the bit depth of the system. So, if you still need to have your own kernel, let's start compiling!

Getting the kernel source code.
The first thing to do is get the source code for the desired kernel version. Usually you need to get the newest stable version. All official kernel versions are available at kernel.org. If you already have an X server (home computer) installed, then you can go to the site in your favorite browser and download the desired version in a tar.gz archive (compressed gzip). If you are working in the console (for example, you have not yet installed the X server or are configuring the server), you can use a text browser (for example, elinks). You can also use the standard wget download manager:
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.1.tar.gz
But note that you must know the exact version number you need.

Unpacking the source code archive.
After you have received the archive with the source code, you need to unpack the archive into a folder. This can be done from graphical file managers (dolphin, nautilus, etc.) or via mc. Or use the traditional tar command:
tar -zxvf path_to_archive
Now you have a source folder, navigate to it using cd kernel_source_code_dir (to list directories in a folder, use the ls command).

Kernel configuration.
Once you have changed to the kernel source directory, you need to do a "20 minute" kernel configuration. Its purpose is to leave only the necessary drivers and functions. All commands already need to be executed on behalf of the superuser.

make config - console mode of the configurator.

make menuconfig - console mode as a list.

make xconfig - graphical mode.

After making the necessary changes, save the settings and exit the configurator.

Compilation.
It's time for the final stage of the assembly - compilation. This is done with two commands:
make && make install
The first command will compile all the files to machine code, and the second will install the new kernel on your system.
We wait from 20 minutes to several hours (depending on the power of the computer).

Configuring and Compiling the Linux Kernel

The kernel is installed. To make it appear in the grub(2) list, type (as root)
update-grub
Now after reboot press "Escape" and you will see the new kernel in the list. If the kernel does not turn on, then just boot with the old kernel and configure more carefully.

KernelCheck - compilation of the kernel without entering the console.
KernelCheck allows you to build the kernel in a fully graphical mode for Debian and its based distributions. Upon launch, KernelCheck will offer the latest kernel versions and patches, and after your consent, download the source code, launch the graphical configurator. The program will build the kernel into .deb packages and install them. You just have to reboot.

Article archive:
May 2017
March 2017
April 2016
March 2016
October 2013
September 2013
May, 2013
March 2013
November 2012
July 2012
June 2012
April 2012
March 2012
February 2012
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010

Random:

Aurorae: window decoration engine for KDE

Sblog will be rewritten in .NET

Linuxnow.ru: Plans for the future

Bolgenos. Telecon's rebuttal

GRUB 2 Quick Recovery

Free Software Foundation and copyleft.

Colleagues: all
Linux for everyone

Our banners:


Set banner

The question is, why not learn to do the same with the Linux kernel? The reasons for building the Linux kernel from source are, in general, the same - getting the latest version of the kernel, urgently applying security patches, optimizing for specific tasks and specific hardware, and also the desire to take part in kernel development, even in the role of QA.

Important! Following the instructions in this post may result in the loss of your data. Make backups and remember that you do everything at your own peril and risk. Everything described below has been tested on Ubuntu 14.04 LTS. But on other versions of Ubuntu, as well as other Linux distributions, the differences should be minimal.

Setting up the bootloader

Edit /etc/default/grub like this:

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=10
#GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR =` lsb_release -i -s 2 > /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

After editing we say:

sudo update-grub

As a result, before the system boots, you will be prompted for 10 seconds to select the kernel with which you want to boot. Very handy if you mess up your kernel configuration and want to boot with a previous version!

Install dependencies

We will need at least the following packages:

sudo apt-get install git gcc make bc fakeroot dpkg-dev \
libncurses5-dev libssl-dev

On many systems, all of them, however, will already be present.

Getting the source

wget https:// www.kernel.org/ pub/ linux/ kernel/ v4.x/ linux-4.6.4.tar.xz
tar --xz -xvf linux-4.6.4.tar.xz
cd linux-4.6.4

Or, if you want the very latest, you can grab the source directly from Git :

# Mirror: https://github.com/torvalds/linux
git clone "git://git.kernel.org/pub/scm/linux/kernel/git/"\
"torvalds/linux.git"
cd linux

Judging by the fact that I could not find the v4.6.4 tag in Git, Linux kernel releases are made exclusively in the form of compressed tar archives.

If, instead of a vanilla kernel, you would like to build a kernel with patches from Canonical:

git clone git://kernel.ubuntu.com/ubuntu/ubuntu-trusty.git
cd ubuntu-trusty
git tag | less
git checkout Ubuntu-lts-4.4.0-31.50_14.04.1

From my own experience, if you use Ubuntu, you can safely use the vanilla kernel. It is unlikely that you will have any problems with it.

Note: Interestingly, of the existing relatively popular Linux distributions, only Gentoo, Slackware, and Arch Linux seem to use a kernel without their own patches.

Anyway, now you have the source code.

Compiling and installing the kernel

Select the options with which the kernel will be built:

make menuconfig

If necessary, change the settings, click Save, then Exit. This will create a .config file containing the options we selected.

At update kernel (are you already using some kind of kernel anyway?) it is convenient to take the config of the current kernel, and set the new options to their default values:

zcat /proc/config.gz > ./.config
make olddefconfig

Finally, we collect:

make -j4 bindeb-pkg LOCALVERSION=-custom

The core is assembled for quite a long time. On my laptop, the assembly took 1 hour and 15 minutes. However, from this time about The rest is spent building a giant kernel package with debug symbols. The assembly of this package can be disabled by commenting out the CONFIG_DEBUG_INFO parameter in the config. Just be aware that this package is required by SystemTap and other useful tools.

In addition to the kernel itself, you can also collect documentation:

# there is also `make pdfdocs` and others, see `make help`
make htmldocs
chromium-browser Documentation/ DocBook/ index.html

Upon completion of assembly subsidiary directory we see something like:

linux-firmware-image-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-headers-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-image-4.4.13-custom_4.4.13-custom-1_amd64.deb
linux-image-4.4.13-custom-dbg_4.4.13-custom-1_amd64.deb
linux-libc-dev_4.4.13-custom-1_amd64.deb

We put all deb-packages except the dbg-version of the kernel with the usual sudo dpkg -i and reboot. After reboot, look at the output of the command uname-a. We make sure that we really booted with the new kernel. If something is wrong with the new kernel, in the bootloader we simply select the one with which the system was booted before. After booting with the old kernel, we quickly remove the packages of the new kernel, and voila - the system returned to its previous state.

In the middle of March, after almost two months of development and seven release candidates, Linus Torvalds introduced a new version of the 4.5 kernel. In addition to fixes, there are really a lot of new things in the release. The changes affected all subsystems - disk, memory, system and network services, security, and, of course, drivers for new devices were added. Let's try to deal with some of the most interesting ones.

About the release

The 4.4 kernel release was released relatively recently, in early January 2016, but a large number of additions have accumulated in this short time. And although Linus called the new release "normal", you can see that compared to version 4.4, the size of the patch has grown by almost a third - 70 MB versus 49 MB. Approximately 1528 people participated in the development, who made about 13 thousand corrections. In more than 11 thousand files, 1,146,727 were added, 854,589 lines of code were removed. In 4.4 there were 714,106 and 471,010 lines, respectively. Almost half (45%) of all changes are related to device drivers, 17% affect the code of hardware architectures, 14% concern the network stack, 4% - file systems, and 3% affect internal kernel subsystems. Doug Ledford of Red Hat contributed the most lines, mostly cleaning up the code (7.7%), Tomi Valkeinen of Texas Instruments working on OMAP subarchitecture support (5.3%), three developers focused on AMD graphics drivers: Eric Huang - 3.3%, Alex Deucher - 2.4% and yanyang1 - 1.6%. Changeset leaders - Linus Walleij of Linaro, who implemented many low-level changes, including to the GPIO he supports (2.0%), Arnd Bergmann, who did a lot of work to support ARM (1.9% ), and Leo Kim, who worked on the wilc1000 driver (1.7%). As before, many corporations are interested in the development of the core. Work on version 4.5 was supported by more than 200 companies, including Red Hat, Intel, AMD, Texas Instruments, Linaro, Linux Foundation, Samsung, IBM, Google. Most of them develop support for their devices and related subsystems and tools, but, for example, Google traditionally makes a lot of changes to the Linux networking subsystem.

Kernel and Drivers

The porting of complex and poorly maintained code written in assembler (x86/asm) to C continued in 4.0. The kernel can now be built with the -fsanitize=undefined option. The parameter itself appeared two years ago in GCC 4.9+ and activates the UBSan (Undefined Behavior Sanitizer) debugging mode, which detects undefined behavior inherent in C and C ++ languages: the use of non-static variables before initialization, division by zero, integer overflow, and so on. The compiler usually assumes that such operations will never occur, and if they do, the result can be anything and depends on the compiler itself. Now the compiler detects such situations, issues a "runtime error:" (you can disable -fno-sanitize-recover) and continues execution. By default, in each OS assembly, all libraries are loaded to certain addresses, which makes it easy to implement an attack. To increase security, a number of technologies are used, one of them is a random offset when calling mmap (), implemented in the form of ASLR (Address Space Layout Randomization). ASLR technology first appeared in Linux in 2005 in the 2.6 kernel and gave out an 8-bit offset for 32-bit systems (that is, 256 address options, although actually less), and for x64 - the offset is already 28-bit. For x64, there are quite enough options, but for 32-bit systems, including Android, this is clearly not enough today. There are already known exploits that can pick up an address. As a result of the search for a solution to the problem, a patch has been written that allows you to set more randomness for ASLR, via /proc/sys/vm/mmap_rnd_bits and /proc/sys/vm/mmap_rnd_compat_bits (on x64 systems for x86 processes). For each architecture, the minimum and maximum values ​​are specified, taking into account the available address space. For x86, the value can range from 8 to 16 bits, or 28 to 32 (for the x64 version). Default options can be set when building the kernel.
Configuring ASLR in the new kernel Expanded capabilities of the DRM driver for NVIDIA (Nouveau) and Intel video cards (support for the future generation of Kaby Lake chips), added support for new sound cards, USB controllers, and crypto accelerators. Graphic card manufacturers Intel and NVIDIA have long abandoned the use of UMS (Userspace Mode Setting) in their open source drivers in favor of KMS (Kernel Mode Setting), now it's the turn of the ATI Radeon driver, which removed the UMS mode code. Since 3.9 it was possible to enable it with the DRM_RADEON_UMS parameter or by setting radeon.modeset=0 in GRUB. Now only KMS (Kernel Mode Setting) remains. This must be taken into account if you need to use older drivers or UMS mode (UMS sometimes shows better performance). Added experimental support for PowerPlay dynamic power management technology to the AMDGPU driver to improve GPU performance for Tonga and Fiji GPUs and integrated Carrizo and Stoney. In PowerPlay mode, the GPU starts in low power mode, but if the load on the graphics subsystem increases, it automatically increases the frequency. By default, PowerPlay is disabled; to enable it, pass the parameter amdgpu.powerplay=1 to the kernel. The new version of the Media controller API extends support for Video4Linux devices and allows you to use the multimedia controller functionality in other subsystems such as DVB, ALSA and IIO. KVM (Kernel-Based Virtual Machine) has done a lot to support the s390 architecture (it can now use up to 248 vCPUs), ARM/ARM64, and improve x86 performance in Hyper-V.

Installing Kernel 4.5 in Ubuntu

The easiest way to get familiar with the new kernel is to use the build from the Ubuntu Kernel Team. After extensive testing, the new kernel ends up in ppa:canonical-kernel-team/ppa , but this usually takes time. $ wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.5-wily/linux-headers-4.5.0-040500-generic_4.5.0-040500.201603140130_amd64.deb http://kernel .ubuntu.com/~kernel-ppa/mainline/v4.5-wily/linux-headers-4.5.0-040500_4.5.0-040500.201603140130_all.deb http://kernel.ubuntu.com/~kernel-ppa/mainline /v4.5-wily/linux-image-4.5.0-040500-generic_4.5.0-040500.201603140130_amd64.deb $ sudo dpkg -i linux*.deb We can work after reboot.

ARM support

ARM computers are used as mini-servers for certain tasks or as automation controllers, which makes them very popular and in demand. The Linux ARM community has become one of the most active over the past five years, doing a tremendous amount of work to support 32-bit ARM platforms, which occupy a significant market share, and this work was generally completed by the release of the 4.5 branch. Previously, each ARM device had to build its own kernel to support only certain devices. But the problem is that the devices became more complex, it became possible to change the configuration, and the users themselves on ARM devices wanted to use regular distributions without unnecessary gestures. But in the end, we had several hundred options for building the kernel, which makes it very difficult to use Linux. As a result of cleaning and refactoring a large amount of code, it became possible to include ARMv6 and ARMv7 support code in the kernel, that is, now we can build a universal kernel that can boot on both systems. Here, probably, we need to recall the recently promoted Device Tree specification, which arose as part of the development of Open Firmware. Device Tree allows you to configure hardware at boot time using special dts files stored in /boot/dtbs and change settings without rebuilding the kernel. The use of the Device Tree becomes mandatory for all new ARM developments and not just devices. All this together gives confidence that Linux distributions in the future can be safely run on any ARM device. In parallel, Greg Kroah-Hartman of the Linux Foundation released a patch that implements a similar feature for early versions of the kernel. In arch/arm64 we find the code that provides support for the new 64-bit ARM architecture (ARMv8). Added new features for all popular ARM architectures - Allwinner, Amlogic, Samsung, Qualcomm and support for new ARM boards from various developers.

System Services

To access UEFI (Unified Extensible Firmware Interface) firmware data in Linux, a special efivars pseudo-file system (configurable by EFIVAR_FS) is used, which is mounted in /sys/firmware/efi/efivars . In some implementations, when executing the rm -rf /* command, the contents of this directory were also deleted, which led to the destruction of the firmware. Companies - device developers do not consider this a serious drawback, because the situation, of course, is not the most common, and it is unlikely that any user would think to check this. Nevertheless, there is a problem, and virus writers can really take advantage of this opportunity. The 4.5 kernel now adds special protection to the /sys/firmware/efi/efivars directory to prevent deletion of files inside.

Continued available to members only

Option 1. Join the "site" community to read all the materials on the site

Membership in the community during the specified period will give you access to ALL Hacker materials, increase your personal cumulative discount and allow you to accumulate a professional Xakep Score rating!

Core(English) kernel) is what everything else is built around. That is what is called Linux. Now the word Linux in everyday life is called the operating system built on it, although in a good way it is called GNU / Linux (the Linux kernel and software from the GNU project, which has been in development for many decades).

Ubuntu uses a kernel with a large number of patches, some of which add unstable and experimental features.

Each release of Ubuntu has its own kernel version. LTS releases since 10.04 have been able to upgrade the kernel to versions included in newer releases.

Ubuntu VersionKernel version
4.10 2.6.9
5.04 2.6.11
5.10 2.6.13
6.06LTS 2.6.15
6.10 2.6.18
7.04 2.6.19
7.10 2.6.20
8.04LTS 2.6.24
8.10 2.6.27
9.04 2.6.28
9.10 2.6.31
10.04LTS 2.6.32
10.10 2.6.35
11.04 2.6.38
11.10 3.0.4
12.04LTS 3.2
12.10 3.5
13.04 3.8
13.10 3.11
14.04LTS 3.13
14.10 3.16
15.04 3.19

forks

The version numbering of the Ubuntu kernel and on the kernel.org website do not match, since the developers from Canonical add a micro version to indicate the added patches. For example, version 3.2.0-23 would mean that the kernel is based on the 3.2 branch, which has 23 patches.

The following types of kernels are supported in the Ubuntu repository:

generic-pae kernel allows a 32-bit system to use up to 64 GB of total RAM, allocating no more than 4 GB for the needs of a particular process, while a simple generic kernel works with no more than 4 GB of RAM.

The 64-bit kernel allows addressing up to 1TB of memory consumed by processes.

If you need to update the kernel to a newer major version (usually this is due to the fact that new versions add support for new hardware, eliminate regressions), you can use the officially supported archive http://kernel.ubuntu.com/~kernel-ppa/mainline/ .

Compiling the kernel

Building the kernel from source requires some skills and knowledge about how the OS works.

Before you start building the kernel, you need to install the following packages:

Build-essential fakeroot ncurses-dev libssl-dev

All further actions must be performed on behalf of the superuser:

sudo su

Getting the source code

The source code for the kernel used by Ubuntu can be obtained by installing the linux-source package:

apt-get install linux source

After installation in the directory /usr/src there will be an archive called linux-source-verify_kernels.tar.bz2.

You can also download the archive with the kernel source code from the site kernel.org.

When downloading the kernel from the kernel.org site, you will have to apply patches to it

Configuration

Unpack the resulting archive and, for convenience, create a symbolic link to the resulting directory:

cd / usr/ src tar xjf ./ linux-source-3.2.0.tar.bz2 ln -s ./ linux-source-3.2.0 ./ linux cd ./ linux

To simplify the kernel configuration process, you can copy the settings of the current one.

Have questions?

Report a typo

Text to be sent to our editors: