CentOS kernel Upgrade tutorial

Source: Internet
Author: User

CentOS kernel Upgrade tutorial

This article applies to CentOS 6.4 and CentOS 6.5, and is estimated to be applicable to other Linux distributions.

1. Prepare for checking the kernel and version information
[root@hostname ~]# uname -r2.6.32-220.el6.x86_64[root@hostname ~]# cat /etc/centos-release CentOS release 6.5 (Final)
Install software

Compile and install the new kernel, depending on the development environment and development library

# Yum grouplist // check the installed and uninstalled Software Package groups to determine whether the corresponding development environment and development library are installed; # yum groupinstall "Development Tools" // usually install these two software packages, this will determine that you have all the tools required for compilation # yum install ncurses-devel // You must so that the make * config command can be correctly executed # yum install qt-devel/ /If you do not have the X environment, this one does not need to # yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel // They are required when creating the CentOS-6 Kernel

If the Software workstation is selected, almost all the installation packages above are included.

2. Compile the kernel to obtain and decompress the kernel source code and configure the compilation items.

There are two Linux kernel versions: the stable version and the development version. The Linux kernel version consists of three numbers: r. x. y

  • R: Major version number
  • X: minor version number. an even number indicates a stable version. an odd number indicates a development version.
  • Y: version number, indicating the number of changes

Go to the http://www.kernel.org home page, you can see stable, longterm and other versions, longterm is a more stable version than stable, will be updated for a long time, so I choose 3.10.58.

 
[root@sean ~]#wget  https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.28.tar.xz

[root@sean ~]# tar -xf linux-3.10.58.tar.xz -C /usr/src/[root@sean ~]# cd /usr/src/linux-3.10.58/[root@sean linux-3.10.58]# cp /boot/config-2.6.32-220.el6.x86_64 .config

We create a new compilation option based on the original Kernel configuration file of the system, so copy it to the current directory and name it. config. Continue with the Configuration:

[root@sean linux-3.10.58]# sh -c 'yes "" | make oldconfig'  HOSTCC  scripts/basic/fixdep  HOSTCC  scripts/kconfig/conf.o  SHIPPED scripts/kconfig/zconf.tab.c  SHIPPED scripts/kconfig/zconf.lex.c  SHIPPED scripts/kconfig/zconf.hash.c  HOSTCC  scripts/kconfig/zconf.tab.o  HOSTLD  scripts/kconfig/confscripts/kconfig/conf --oldconfig Kconfig.config:555:warning: symbol value 'm' invalid for PCCARD_NONSTATIC.config:2567:warning: symbol value 'm' invalid for MFD_WM8400.config:2568:warning: symbol value 'm' invalid for MFD_WM831X.config:2569:warning: symbol value 'm' invalid for MFD_WM8350.config:2582:warning: symbol value 'm' invalid for MFD_WM8350_I2C.config:2584:warning: symbol value 'm' invalid for AB3100_CORE.config:3502:warning: symbol value 'm' invalid for MMC_RICOH_MMC** Restart config...*** General setup*... ...XZ decompressor tester (XZ_DEC_TEST) [N/m/y/?] (NEW) Averaging functions (AVERAGE) [Y/?] (NEW) yCORDIC algorithm (CORDIC) [N/m/y/?] (NEW) JEDEC DDR data (DDR) [N/y/?] (NEW) ## configuration written to .config

make oldconfigWill read.configFile, in.configIf the option is not found in the file, the system prompts the user to fill in and back up.configThe file is.config.oldAnd generate a new.configFile, reference http://stackoverflow.com/questions/4178526/what-does-make-oldconfig-do-exactly-linux-kernel-makefile

Some documents introduce the use of make memuconfig, Which is customized as needed, similar to the following interface: (not required here)

Start Compilation
[Root @ sean linux-3.10.58] # make-j4 bzImage // generate the Kernel File [root @ sean linux-3.10.58] # make-j4 modules // compile the module [root @ sean linux-3.10.58] # make- j4 modules_install // compile and install the module

-The number after j is the number of threads used to speed up compilation. Generally, the logic CPU is used to enter that number. For example, if there is 8 cores, it is-j8. (The module takes more than 30 minutes)

Install

[Root@seanlinux-3.10.58] # make install
When this step is actually executedERROR: modinfo: could not find module vmware_balloonBut does not affect kernel installation. Because the modules required by vsphere are not compiled, to avoid this problem, you need to modify the. config file before make and add
HYPERVISOR_GUEST = yCONFIG_VMWARE_BALLOON = m
(This part is prone to problems. Refer to the exception section below)

Modify grub boot and restart

After the installation is complete, you need to modify the Grub boot sequence and use the newly installed kernel as the default kernel.
Edit the grub. conf file,

vi /etc/grub.conf#boot=/dev/sdadefault=0timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle CentOS (3.10.58)    root (hd0,0)...

Count the position of the newly installed kernel, starting from 0, and then set default to the number. Generally, the newly installed kernel is in the first position, so set default to 0.
Restartreboot:

Confirm the current kernel version
[root@sean ~]# uname -r3.10.58

Kernel upgraded!

3. Abnormal compilation failed (for example, the dependency package is missing)

You can clear it first and then re-compile it:

# Make mrproper # After the installation is completed or an error occurs during the installation process, you can clear the last compiled site # make clean
Compile on the vmwarevm and the following error occurs:
[root@sean linux-3.10.58]# make install sh /usr/src/linux-3.10.58/arch/x86/boot/install.sh 3.10.58 arch/x86/boot/bzImage \        System.map "/boot"ERROR: modinfo: could not find module vmware_balloon

You can ignore it. If you have obsessive-compulsive disorder, try the following methods:
To install VMWARE_BALLOON on vmware, you can directly modify the. config file.CONFIG_VMWARE_BALLOON=mStill ineffective, because it depends onHYPERVISOR_GUEST=y. If you do not know the dependencymake menuconfigAfter Device Drivers-> MISC devices, the VMware Balloon Driver cannot be found. (Manually modify HYPERVISOR_GUEST in vi. config, you can find this item). In addition, whether it is through make menuconfig or directly vi. config, runsh -c 'yes "" | make oldconfig'Get the final compilation configuration option at a time.
Then, considering that vmware_balloon may have changed its name to vmw_balloon in this version, use the following methods to ensure the safety:

# Cd/lib/modules/3.10.58/kernel/drivers/misc/# ln-s vmw_balloon.ko vmware_balloon.ko # create a soft connection

In fact, the best choice for installing the docker Kernel Compiling environment is to use sciurus to help us configure the. config file.
We recommend that youmake bzImagePreviously, run the script check-config.sh to check the module missing for the current kernel running docker.
If you are prompted that other modules are missing, such as NF_NAT_IPV4, you can also solve the problem by using the above method and re-compile it.

4. Several important Linux kernel files

In the network, many servers use Linux systems. To further improve the server performance, you may need to recompile the Linux kernel based on specific hardware and requirements. To compile the Linux kernel, you must follow the required steps. Several important files are involved in compiling the kernel. For example, for RedHat Linux, there are some Linux kernel-related files in the/boot directory and the/boot command is run: ls-l. People who have compiled the RedHat Linux kernel may be impressed with System. map, vmlinuz, and initrd-2.4.7-10.img, because operations such as file creation are involved during kernel compilation. How are these files generated? What role does it play?

(1) vmlinuz

Vmlinuz is a bootable and compressed kernel. "Vm" represents "Virtual Memory ". Linux supports Virtual Memory. Unlike earlier operating systems such as DOS, there is a limit of KB memory. Linux can use hard disk space as virtual memory, so it is named "vm ". Vmlinuz is an executable Linux kernel located in/boot/vmlinuz, which is generally a soft link.

There are two ways to establish vmlinuz.

One is to compile the kernel through "make zImage" to create, and then through: "cp/usr/src/linux-2.4/arch/i386/linux/boot/zImage/boot/vmlinuz" generated. ZImage is suitable for small kernels. It exists for backward compatibility.

The second is when the kernel is compiled by the command make bzImage to create, and then through: "cp/usr/src/linux-2.4/arch/i386/linux/boot/bzImage/boot/vmlinuz" generated.

BzImage is a compressed kernel image. It should be noted that bzImage is not compressed with bzip2, and bz in bzImage is easy to misunderstand. bz indicates "big zImage ". B In bzImage means "big.

Both zImage (vmlinuz) and bzImage (vmlinuz) are compressed using gzip. They are not only a compressed file, but are embedded with gzip decompression code at the beginning of the two files. Therefore, you cannot use gunzip or gzip-dc to unpackage vmlinuz.

The kernel file contains a micro gzip used to extract the kernel and boot it. The difference between the two is that the old zImage decompress the kernel to the low-end memory (the first 640 K), and The bzImage decompress the kernel to the high-end memory (more than 1 MB ). If the kernel is small, zImage or bzImage can be used. The two methods guide the same system runtime. BzImage is used for large kernels, and zImage cannot be used.

Vmlinux is an uncompressed kernel and vmlinuz is a compressed file of vmlinux.

(2) initrd-x.x.x.img

Initrd is short for "initial ramdisk. Initrd is generally used to temporarily boot the hardware to the State where the actual kernel vmlinuz can take over and continue to boot. For example, if a scsi hard disk is used, and the kernel vmlinuz does not have the scsi hardware driver, the kernel cannot load the root file system before the scsi module is loaded, however, the scsi module is stored in/lib/modules of the root file system. To solve this problem, we can guide an initrd kernel that can read the actual kernel and use initrd to correct the scsi Boot problem. The initrd-2.4.7-10.img is a file compressed with gzip. Let's take a look at the content of this file.

Initrd implements loading modules and installing file systems.

The initrd image file is created using mkinitrd. The mkinitrd utility can create an initrd image file. This command is proprietary to RedHat. Other Linux distributions may have corresponding commands. This is a very convenient utility. For details, see help: man mkinitrd

The following command creates an initrd image file:

(3) System. map

System. map is a kernel symbol table of a specific kernel. It is the link to the System. map of your currently running kernel.

How is the kernel symbol table created? System. map is generated by "nm vmlinux" and irrelevant symbols are filtered out. For the example in this article, when compiling the kernel, System. map is created at/usr/src/linux-2.4/System. map. As shown below:

Nm/boot/vmlinux-2.4.7-10> System. map

The following lines are from/usr/src/linux-2.4/Makefile:

Nm vmlinux | grep-v '(compiled) | (. o

) | ([AUw]) | (.. ng ) | (LASH [RL] DI) '| sort> System. map

Then copy to/boot:

Cp/usr/src/linux/System. map/boot/System. map-2.4.7-10

Some symbols such as variable names or function names are named during program design. Linux Kernel is a complex code block with many global symbols.

The Linux kernel uses a variable or function name instead of a symbolic name. For example, instead of using a symbol like size_t BytesRead, the variable is referenced like c0343f20.

For people who use computers, they prefer names like size_t BytesRead rather than c0343f20. The kernel is mainly written in c, so the compiler/connector allows us to use a symbolic name for encoding and an address for Kernel running.

However, in some cases, we need to know the address of the symbol or the symbol corresponding to the address. This is done by the symbol table, which is a list of all symbols along with their addresses. The Linux symbol table uses two files:/proc/ksyms and System. map.

/Proc/ksyms is a "proc file" created during kernel boot. In fact, it is not really a file. It is just a representation of kernel data, but it gives people the illusion of a disk file, which can be seen from its file size being 0. However, System. map exists in the actual file System. When you compile a new kernel, the address of each symbol name changes. Your old System. map has incorrect symbol information. Each time the kernel is compiled, a new System. map is generated. You should replace the old System. map with the new System. map.

Although the kernel itself does not actually use System. map, other programs such as klogd, lsof, and ps need a correct System. map. If you use incorrect or do not have System. map, the output of klogd will be unreliable, which will cause difficulties in troubleshooting the program. Without System. map, you may face annoying prompts.

In addition, a few drivers need System. map to parse the symbols. If System. map is not created for the specific kernel you are running, they cannot work normally.

For Linux kernel log daemon klogd to perform name-Address Resolution, klogd needs to use System. map. System. map should be placed where the software that uses it can find it. Run: man klogd. If System. map is not given to klogd as a variable, it searches for System. map in the following order:

/Boot/System. map

/System. map

/Usr/src/linux/System. map

System. map also has version information. klogd can intelligently find the correct map file.

5. References
  • CentOS 6.5 upgrade kernel to 3.10.28
  • Linux Kernel configuration
  • How to upgrade the kernel on CentOS
  • Upgrade CentOS 6.4 to 3.x Kernel
  • CentOS Linux kernel upgrade steps and methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.