The Linux system to replace the new kernel (compile and install the replacement

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


One, introduction

The kernel, is the core of an operating system. It is responsible for the process management system, memory, device drivers, file and network system, determines the system performance and stability. Linux as a free software, the majority of fans support, kernel version update. The new kernel revised the old kernel bug, and added many new features. If users want to use these new features, or would like to according to their own system tailored to a more efficient, more stable core, will need to recompile the kernel.

This paper will take the kernel 3.12.5 version of the experiment, the operation platform for RedHat 6.2, but the kernel compilation and installation method is suitable for the majority of Linux system (including RedHat, Ubuntu, Debian etc.).

Two, download the latest kernel source code

The kernel download website: https://www.kernel.org/
Extracting kernel: #tar xvf linux-3.12.5.tar.xz /opt

Access to the kernel source directory: #cd /opt/linux-3.12.5


This extract to any directory is OK, I unpack it to the /opt directory. In the Internet to see a lot of friends decompression to the /usr/src directory, but this does not matter, because this method is not limited to speak to the machine is a new kernel, there may be a new kernel to other machines, even if is new the machine core that also never mind, because after the execution of #make install automatic will face the corresponding files are copied to the corresponding directory.

Note: the following all about color coded "3.12.5" are replaced with their actual kernel version number.

Three, replace the kernel

This paper introduces two kinds of method: replace the kernel compile kernel, kernel package replacement replacement (.Deb package).

(a) to replace the kernel compile

The compiler replaces the kernel for all Linux systems, is the most commonly used method.

1, Custom kernel

#make mrproper

Role is in each configuration and recompile the need to perform "make mrproper" command to clean up the source code tree kernel, including the kernel configuration file "once the configuration of the.Config" will be removed. The new compilation work will the old configuration files to delete, so as not to affect the new kernel compile.

The examination has all the correct.O file and dependency, if use just download the complete source code package is the first compilation, then this step can be omitted. If you have used these source code compile the kernel, it is best to run this command.

#make menuconfig

Note: the use of kernel configuration file make menuconfig generated, decided to each functional system kernel compiled into the kernel or compiled as a module or not compiled.

Here is not the kernel configuration specific operation, but suggest that even if not going to configure what is performing a make menuconfig this command, because if you do not perform this operation. In the back of make compile the kernel will prompt you to answer a lot of questions.

The kernel configuration can reference:

Make menuconfig configuration.:

Configure the kernel and other methods, the main differences are as follows:

#make menuconfig //The ncurse database interface based on graphic tools

#make config //The command line tools based on text, does not recommend the use of

#make xconfig //Graphic interface based on X11

#make gconfig //Based on the gtk+ graphical interface;

Here is a selection of configuring the kernel method is simple, namely make menuconfig. In the terminal input make menuconfig, wait a few seconds, the terminal into the kernel configuration graphical interface. Configuration options, most use the default value only a small part, need to choose according to different needs.

For each configuration options, users have three choices, they are the meanings of the following:

<*>Or X -- the function compiled into the kernel

[ ]-The function will not be compiled into the kernel

[M]-The function is compiled into when you need dynamic insertion into the kernel code

2, Compile and install the kernel and module

(1) Copy the.Confg file:

Implementation of #cp /boot/config-, and then press the Tab key, the system will automatically fill in the documents in accordance with the conditions of the directory name, and then continue to enter the.Config, the goal is to use the original configuration file in the boot directory.

Do not perform this step, back when make prompts the.Confg file not found.

If in the previous step configuration of the kernel words should be automatically generated.The config file, but here I just carried out a #make menuconfig command does not configure the kernel.

(2) Required to set up the compile time dependent files:

#make dep

According to the selection step options, set up File Dependencies.

(3) Clean the kernel compiled object file :

#make clean

Clean up some unnecessary files, if you are in the last compilation, delete some options, suggest you perform this procedure, otherwise, there is no necessary.

(4) Compile and install the kernel and module:

[This machine is replaced by kernel]

1)Compile the kernel and module:

#make –j4

Generation of kernel module and vmlinuz, initrd.img, Symtem.map file.

Note: #make is equivalent to #make bzImage and #make modules were performed, because this machine is replaced by kernel, so no need to separate the execution.

This step required longer, In order to speed up compilation, We can add "-j" option, Followed by the number is jobsnum , The proposed set of CPU core number + 1, jobsnumvalueCan be obtained by the command "cat /proc/cpuinfo |sed -n'/^processor/p'|wc -l".

2)Install the module:

#makemodules_install

After the success of the compiler, the system will generate a 3.12.5 sub directory under the /lib/modules directory, which holds all the new kernel loadable module (to be compiled modules copied to the /lib/modules).

3)Install the kernel:

#makeinstall

The replication of.Config, vmlinuz, initrd.img, System.map file to the /boot directory, update grub. For the RedHat system below three grub files will be automatically updated, the default boot the new kernel.

/etc/grub.conf

/boot/grub/menu.lst

/boot/grub/grub.conf

Note: the first two configuration file is a soft connecting third.

Ubutun and Debian system is the /boot/grub/grub.conf file.

4)Reboot the system:

#reboot

[Non native replace kernel]

Here can also like the machine to replace a kernel as a direct implementation of #make, but this article will compile the kernel and compiler module separately to perform, but the principle and the result is the same.

1)Compile the kernel:

#make bzImage

The kernel is compiled successfully, it will create a new kernel source directory in the root directory of the linux-3.12.5/arch/x86_64/boot/ image file bzImage.

Note: for the big kernel (such as the need to support SCSI), make bzImage (recommended)

For small kernel, make zImage.

2)Compiler module:

#make modules

Compile loadable module (i.e. choosing kernel options for the M option), in order to use the insmod command to load. The number of compile time options related with M.

3)Install the module:

#make modules_install

The compiled modules copy to /lib/modules.

4)Install the kernel:

Not because of the machine to replace a kernel, so we need to copy the new generation core file to replace the kernel machine. To copy the kernel file as the main 4, respectively is:.Config, bzImage, System.map and /lib/modules/linux-3.12.5 directory.

The specific operation as follows:

(1)The generated linux-3.12.5/.config copy to replace the kernel system under /boot, and rename it to config-3.12.5

(2)The generated linux-3.12.5/arch/x86-64/boot/bzImage copy to replace the kernel system under /boot, and rename it to vmlinuz-3.12.5 (Note: here the need to pay particular attention to copy the file name to the vmlinuz-x.x.x).

(3)The generated linux-3.12.5/System.map copy to replace the kernel system under /boot, and rename it to System.map-3.12.5

(4)The directory /lib/modules/linux-3.12.5 make modules_install generated copy to replace the kernel system under /lib/modules.

(5)Execute the following command in the system to replace the new kernel /lib/modules directory:

#update-initramfs-c -k3.12.5, Generation/boot/initrd.img-3.12.5

#Update-grub (or #update-grub2), update start loading the file.

Note: the RedHat system in like there is no more than two update command, so the above update kernel method suitable for Ubuntu or Debian system.

The RedHat system how to update kernel?Recommend the use of a [the] method replace the kernel direct make install installation, use the machine to replace] [non kernel method is not convenient, but here also to do a presentation, we can be manually updated kernel boot file. (of course, you can also manually download a grub installation package is installed, then use update-grub).

The details are as follows (article (5) step replaced below operation):

There are three configuration files in RedHat system/etc/grub.conf, /boot/grub/menu.lst, /boot/grub/grub.conf

The first two are connected to the third, so we only need to modify the /boot/grub/grub.conf startup configuration file.

The contents are as follows:

The title display name on the start menu.

The root root file system mount partitions, according to its own system which can be modeled on the old version of the kernel, fill in.

Kernel compressed kernel file name

The initrd root file system file name

Such as:

titleMy new kernel

root (hd0,0)

kernel/boot/vmlinuz-x.y.z

initrd/boot/initrd-x.y.z.img

Modify the direct method of grub boot files I have no dear test in the red hat system, this part is the reference articlehttp://wenku.baidu.com/view/cb16a8fdc8d376eeaeaa3126.htmlWrite, can see the specific text.

The new kernel content of our system in /boot/grub/grub.conf is as follows:

title Red Hat Enterprise LinuxServer (3.12.5)

root (hd0,0)

kernel /vmlinuz-3.12.5 orroot=/dev/...

initrd /initramfs-3.12.5.img

And rebuild the RAM disk:

If your system does not use the /etc/lilo.conf RAM disk option initrd, skip

If your system using the /etc/lilo.conf RAM disk options initrd,

Use the version number of initrd- kernel mkinitrd kernel version command to generate the ram file, such as my Redhat 6.2:

mkinitrd initrd-3.12.5 3.12.5

After the /etc/lilo.conf in the initrd to point to the new generation of initrd-3.12.5 file:

initrd=/boot/initrd-3.12.5


The RAM disk can make the system performance as much as possible optimization, with specific reference to the /usr/src/linux/Documents/initrd.txt file

5)Reboot the system:

#reboot

3, Several important Linux kernel file introduction

(1).config

The use of kernel configuration file make menuconfig generated, decided to each functional system kernel compiled into the kernel or compiled as a module or not compiled.

(2)Vmlinuz and vmlinux

Vmlinuz is bootable, compressed kernel, "VM" stands for "Virtual Memory". Linux supports virtual memory, unlike the old operating system such as DOS with 640KB of memory limit, Linux is able to use the hard disk space as virtual memory, hence the name"vm".

Vmlinuz is an executable Linux kernel, vmlinuz was established in two ways:

One is to create the kernel through the "make zImage", zImage is suitable for small kernel, it is for backward compatibility.,

The two is the kernel compile time by the command make bzImage to create, bzImage is compressed kernel image, note, bzImage is not compressed with bzip2, bzImage in the BZ is easy to cause the misunderstanding, BZ said "big zImage", bzImage B is "big". zImage(vmlinuz)And bzImage (vmlinuz) is compressed with gzip. They are not only a compressed file, and gzip decompression code inline in the beginning part of the two files, so you can't use gunzip or gzip – unpacking DC vmlinuz. Kernel file contains a micro gzip for decompress kernel and guide it. The difference is, the old zImage decompress kernel to low memory (the first 640K), unzip the bzImage kernel to high-end memory (above 1M). If the kernel is relatively small, so you can use one of the zImage or bzImage, system operation guide two ways is the same. Big kernel using bzImage, not by zImage. Vmlinux is not compressed kernel, vmlinuz is the vmlinux compressed files.

(3)initrd.img

Initrd is the "initial ramdisk" the abbreviation.

Initrd is commonly used for temporary guide the hardware to the actual kernel vmlinuz can take over and continue to guide state. For example, initrd- 2.4.7-10.img is mainly used for driving load ext3 file system and SCSI equipment. If you are using a SCSI hard disk, and vmlinuz kernel does not drive the SCSI hardware, so before loading the SCSI module, the kernel cannot load the root file system, but the SCSI module is stored in the root file system under /lib/modules. In order to solve this problem, can lead a to read the actual kernel initrd kernel and initrd modified SCSI guide, initrd-2.4.7-10.img gzip is used to compress the file. Initrd image file is created using mkinitrd, the mkinitrd utility to create a initrd image file, this command is exclusive to RedHat, other Linux distributions may have the corresponding command. This is a handy utility. Details please see help: man mkinitrd

(4)System.mapIs a kernel specific kernel symbol table, by the "nm vmlinux" and not related to the symbols are filtered out.
The following lines from/usr/src/linux-2.4/Makefile:

nm vmlinux | grep-v '(compiled)|(.o$$)|( [aUw] )|(..ng$$)|(LASH[RL]DI)' | sort >System.map

In the program design, will be named some variable or function name or symbol. The Linux kernel is a very complex code block, there are many global symbols, Linux kernel does not use the symbol name, but by a variable or function addresses to identify variable or function name, such as not using size_t BytesRead such symbols, but like c0343f20 for this variable. For the use of a computer person, more like to use names like size_t BytesRead, and doesn't like a name such as c0343f20. The kernel is written in C, so the compiler / linker allows us to use when encoding symbol names, addresses the use of kernel at run time. However, in some circumstances, we need to know the address of the symbol, or need to know the address of the corresponding symbol, the symbol table to complete, the symbol table is all symbols together with their address list.

The Linux symbol table to use up to 2 files: /proc/ksyms , System.map . /proc/Ksyms is a "proc file", created in the kernel boot. In fact, it doesn't really is a file, it is only the kernel data, but to the people is a disk file illusion, which from its file size is 0 can see. However, System.map is the actual file exists on your system. When you compile a new kernel, each symbol name address to change, your old System.map has is the symbol of wrong information, create a new System.map each kernel compile time, you should replace the old System.map with the new System.map.

Although the kernel itself is not actually used System.map, but other programs such as klogd, lsof and PS software requires a correct System.map. If you use the wrong or no System.map, klogd output is not reliable, the exclusion of program faults will bring difficulties. No System.map, you may face some disturbing message. In addition a few drivers need System.map to parse the symbol, not created for a specific kernel you are currently running System.map they cannot work normally. The kernel of Linux logging daemon klogd analysis in order to implement the name to address, klogd need to use System.map. The System.map should be placed on the use of the software to be able to find it. Execution: man klogd know, if you do not set the System.map as a variable to the location of klogd, then it will be in accordance with the following order, in three places to find System.map: /boot/System.map , /System.map, /usr/src/linux/System.map

System.map also has a version information, klogd can automatically find the right image (map) files.

(two) replace the kernel package

Packing to replace the new kernel is using the make-kpkg command, so this method is only suitable for system version supports the make-kpkg command, generally suitable for Ubuntu, Debian systems, are not suitable for RedHat system.

1, Custom kernel

#make mrprobe , Clean up the source code tree.

#make menuconfig , Configure the kernel.

2, Packaged kernel

(1)Copy the.Confg file:

Implementation of #cp /boot/config-, and then press the Tab key, the system will automatically fill in the documents in accordance with the conditions of the directory name, and then continue to enter the.Config, the goal is to use the original configuration file in the boot directory.

Do not perform this step, back when make prompts the.Confg file not found.

If in the previous step configuration of the kernel words should be automatically generated.The config file, but here I just carried out a #make menuconfig command does not configure the kernel.

(2)Compile the kernel package

#make-kpkg --initrd - -append-to-version=-pyh - -revision=zxxiong.0716 -j 4kernel_image kernel_headers

After the execution of the above command will be generated in a directory of two.Deb package:

The header file package: linux-headers-3.12.5-pyh_zxxiong.0716_amd64.deb

Kernel package: linux-image-3.12.5-pyh_zxxiong.0716_amd64.deb

[--initrd]Option will let make-kpkg automatically help us generate initramfs,

[--revision]Will give the version information to generate the DEB file to add the last. This parameter only affects the file name, if not specified, the default is"10.00.Custom",

[--append-to-version]Is also a version information, it not only appear in the DEB installation package file name, also will affect the kernel name, as in this case, the kernel update is completed, use "uname -r" observation will get"3.12.5-pyh",

[kernel_image]Generating kernel and default module installation package.

[kernel_headers]This make-kpkg will generate a kernel header files installation package.

If we use the ordinary users to perform make-kpkg, need to addfakerootFunction

#fakeroot make-kpkg --initrd - -append-to-version=-pyh - -revision=zxxiong.0716 -j 4 kernel_image kernel_headers

(Note: the need to set up a platform such as -amd64 in this configuration file has the default configuration, so here do not add, option kernel_image is to generate a kernel.Deb, choice kernel_headers is the header file.Deb package, these two options can only use one)

(3)Install the kernel

The above generated.Deb packets are copied to the need to replace a kernel machine, execute the following command:

#dpkg –I linux-headers-3.12.5-pyh_zxxiong.0716_amd64.deblinux-image-3.12.5-pyh_zxxiong.0716_amd64.deb (on line)

Or directly in the DEB package directory implementation: #dpkg –i ./*.deb

Execute command will automatically update the /boot files in a directory (i.e. automated the command: update-initramfs -c -k3.12.5 and ##update-grub2), Then reboot the system and load the kernel can be selected, You can also modify the /boot/grub/grub.cfg configuration file in set default= "0", the default is 0, After installation, check the file new loaded kernel is the first of several items set to a few (since 0), This is not needed at boot time choose to start the several.

(5) Reboot the system

#reboot

In this paper, reference:

1,

2,

Warning: the reprint please indicate the source

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Polly at December 19, 2013 - 3:34 PM