This article applies to CentOS 6.4, CentOS 6.5, and it is estimated that it is also applicable to other Linux distributions.
[ root@hostname ~]# uname -r2.6.32-220.el6.x86_64
[ root@hostname ~]# cat /etc/centos-release CentOS release 6.5(Final)
Compile and install the new kernel, depending on the development environment and development library
# yum grouplist //Check the installed and uninstalled package groups to determine whether we have installed the corresponding development environment and development libraries;# yum groupinstall "Development Tools" //Generally install these two package groups, doing so will make sure you have all the tools needed for compilation# yum install ncurses-devel //You have to do this to make make*The config command is executed correctly# yum install qt-devel //If you don’t have an X environment, this one can be omitted# yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel //Create CentOS-They are needed for 6 cores
If you chose Software workstation to install the system, almost all of the above installation packages are included.
There are two Linux kernel versions: stable and development versions. The Linux kernel version number consists of 3 numbers: rxy
Go to http://www.kernel.org homepage, you can see that there are stable, longterm and other versions. Longterm is a more stable version than stable and 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 a copy to the current directory and name it .config. Next continue to configure:
[ 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/conf
scripts/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 oldconfig
will read the .config
file in the current directory, and prompt the user to fill in the options that are not found in the .config
file, then back up the .config
file as .config.old
and generate a new one .config
file, refer to http://stackoverflow.com/questions/4178526/what-does-make-oldconfig-do-exactly-linux-kernel-makefile
Some documents introduce the use of make memuconfig, which is to customize modules according to needs. The similar interface is as follows: (not needed here)
[ root@sean linux-3.10.58]# make -j4 bzImage //Generate core files[root@sean linux-3.10.58]# make -j4 modules //Compile module[root@sean linux-3.10.58]# make -j4 modules_install //Compile and install modules
[ root@sean linux-3.10.58]# make install
When actually running to this step, ERROR: modinfo: could not find module vmware_balloon
appears, but it does not affect the kernel installation. The module required by vsphere is not compiled. To avoid this problem, you need to modify the .config file before make. Join
HYPERVISOR_GUEST=yCONFIG_VMWARE_BALLOON=m
(This part is more prone to problems, please refer to the abnormal part below)
After the installation is complete, you need to modify the Grub boot sequence to make the newly installed kernel as the default kernel.
Edit the grub.conf file,
vi /etc/grub.conf#boot=/dev/sdadefault=0timeout=5splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS(3.10.58)root(hd0,0)...
Count the location of the newly installed kernel, starting from 0, and then set default to that number. Generally, the newly installed kernel is in the first position, so set default=0.
Restart reboot
:
[ root@sean ~]# uname -r3.10.58
The kernel upgrade is successful!
You can clear it first, and then recompile:
# make mrproper #Finished or the installation process went wrong, you can clean up the last compiled site# make clean
[ 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:
To install VMWARE_BALLOON on vmware, you can directly modify the .config file, but if vi directly adds CONFIG_VMWARE_BALLOON=m
, it still has no effect, because it depends on HYPERVISOR_GUEST=y
. If you don't know this layer of dependencies, after passing make menuconfig
, VMware Balloon Driver cannot be found under Device Drivers -> MISC devices. (You can find this item after manually modifying HYPERVISOR_GUEST with vi .config). In addition, whether it is through make menuconfig or directly vi .config, you must run sh -c'yes "" | make oldconfig'
once to get the final Compiler configuration options.
Then, considering that vmware_balloon may have been renamed vmw_balloon in this version, use the following method to be safe:
# cd /lib/modules/3.10.58/kernel/drivers/misc/# ln -s vmw_balloon.ko vmware_balloon.ko #Establish soft connection
In fact, for the kernel compilation environment where Docker is installed, the most sensible choice is to use sciurus to help us configure the .config file.
It is also recommended to run the script check-config.sh before make bzImage
to check the missing modules of the current kernel running docker.
When it prompts that other modules are missing, such as NF_NAT_IPV4, it can also be solved by the above method, and then recompile.
In the network, many servers use Linux systems. In order to further improve the performance of the server, it may be necessary to recompile the Linux kernel according to specific hardware and requirements. Compiling the Linux kernel needs to follow the prescribed steps. Several important files are involved in the process of compiling the kernel. For example, for RedHat Linux, there are some files related to the Linux kernel in the /boot directory, enter /boot to execute: ls -l. Those who have compiled the RedHat Linux kernel may be more impressed with System.map, vmlinuz, and initrd-2.4.7-10.img, because the process of compiling the kernel involves operations such as the establishment of these files. So how are these files generated? What's the effect?
vmlinuz is a bootable, compressed kernel. "Vm" stands for "Virtual Memory". Linux supports virtual memory, unlike older operating systems such as DOS which has a 640KB memory limit. Linux can use hard disk space as virtual memory, hence the name "vm". vmlinuz is an executable Linux kernel, it is located in /boot/vmlinuz, and it is generally a soft link.
There are two ways to establish vmlinuz.
One is created by "make zImage" when compiling the kernel, and then generated by: "cp /usr/src/linux-2.4/arch/i386/linux/boot/zImage /boot/vmlinuz". zImage is suitable for small kernels, and it exists for backward compatibility.
The second is to create the kernel through the command make bzImage when compiling, and then through: "cp /usr/src/linux-2.4/arch/i386/linux/boot/bzImage /boot/vmlinuz".
bzImage is a compressed kernel image. It should be noted that bzImage is not compressed with bzip2. The bz in bzImage is easily misunderstood, and bz stands for "big zImage". The b in bzImage means "big".
Both zImage (vmlinuz) and bzImage (vmlinuz) are compressed with gzip. They are not only a compressed file, but the gzip decompression code is embedded in the beginning of the two files. So you cannot unpack vmlinuz with gunzip or gzip -dc.
The kernel file contains a tiny gzip to decompress the kernel and boot it. The difference between the two is that the old zImage decompresses the kernel to the low-end memory (the first 640K), and the bzImage decompresses the kernel to the high-end memory (above 1M). If the kernel is relatively small, one of zImage or bzImage can be used. The operating time of the system booted by the two methods is the same. The big kernel uses bzImage, but not zImage.
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 a state where the actual kernel vmlinuz can take over and continue booting. For example, if the scsi hard disk is used, and there is no driver for this scsi hardware in the kernel vmlinuz, the kernel cannot load the root file system before loading the scsi module, but the scsi module is stored under /lib/modules of the root file system. To solve this problem, you can boot an initrd kernel that can read the actual kernel and use initrd to correct the scsi boot problem. initrd-2.4.7-10.img is a file compressed with gzip, let's take a look at the content of this file.
Initrd realizes loading some modules and installing file system.
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, please see help: man mkinitrd
The following command creates the initrd image file:
(3) System.map
System.map is a kernel symbol table of a specific kernel. It is a link to the System.map of the kernel you are currently running.
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 in /usr/src/linux-2.4/System.map. Like the following:
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
During program design, some symbols such as variable names or function names are named. The Linux kernel is a very complex code block, with many global symbols.
The Linux kernel does not use symbolic names, but uses the address of the variable or function to identify the variable or function name. For example, instead of using symbols such as size_t BytesRead, you can refer to this variable like c0343f20.
For people who use computers, they prefer to use names like size_t BytesRead rather than names like c0343f20. The kernel is mainly written in C, so the compiler/linker allows us to use symbolic names when coding and addresses when the kernel is running.
However, in some cases, we need to know the address of the symbol, or need to know the symbol corresponding to the address. This is done by the symbol table, which is a list of all symbols together with their addresses. The Linux symbol table uses two files: /proc/ksyms and System.map.
/proc/ksyms is a "proc file", created when the kernel boots. In fact, it is not really a file, it is only 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 is the actual file that exists on your file system. When you compile a new kernel, the address of each symbol name will change, and your old System.map has wrong symbol information. A new System.map is generated every time the kernel is compiled, and you should replace the old System.map with the new System.map.
Although the kernel itself does not really use System.map, other programs such as klogd, lsof and ps need a correct System.map. If you use the wrong or no System.map, the output of klogd will be unreliable, which will bring difficulties to troubleshooting. Without System.map, you may face some annoying messages.
In addition, a few drivers require System.map to resolve symbols, and they will not work properly without a System.map created for the specific kernel you are currently running.
In order to perform name-address resolution, the Linux kernel log daemon klogd needs to use System.map. System.map should be placed where the software that uses it can find it. Execution: man klogd knows that if System.map is not given to klogd as a variable location, then it will look for System.map in three places in the following order:
/boot/System.map
/System.map
/usr/src/linux/System.map
System.map also has version information, and klogd can intelligently find the correct map file.
This article is reproduced from the Internet
Recommended Posts