--------------------------------------------------------
Http://blog.chinaunix.net/uid-26000296-id-4208526.html
Linux kernel upgrade Guide 2014-04-14 12:05:44
I. Linux kernel overview
Linux is an integrated kernel (monolithic kernel) system.
The device driver has full access to the hardware.
Device drivers within Linux can be conveniently set up in a modular (modularize) format and can be mounted or unloaded directly while the system is running.
1. Linux kernel
The Linux operating system is a low-level support software used to deal with hardware and provide a limited set of services for user programs.
A computer system is a kind of hardware and software symbiosis, they depend on each other, inseparable.
A computer's hardware that contains peripherals, processors, memory, hard disks, and other electronic devices that compose a computer's engine.
But there is no software to operate and control it, itself is not working.
The software that completes this control is called the operating system, which is called the "kernel" in the terminology of Linux, and can also be called "core".
The main modules (or components) of the Linux kernel are divided into the following sections:
. Progress management (Process management)
. Timers (timer)
. Interrupt Management (Interrupt management)
. Memory Management (Management)
. Module management (Modules management)
. Virtual file System interface (VFS layer)
. FileSystem (File System)
. Device drivers (Devices driver)
. interprocess communication (inter-process communication)
. Network Management (Management
. Implementation of operating system functions such as System init.
2. Linux kernel version number
The Linux kernel uses three different version numbering methods.
. The first method is used before the 1.0 version (including 1.0).
The first version is 0.01, followed by 0.02, 0.03, 0.10, 0.11, 0.12, 0.95, 0.96, 0.97, 0.98, 0.99, and after 1.0.
. The second method is used after 1.0 to 2.6, the number consists of three parts "A.B.C", A represents the major version number, B represents the minor major version number, and C represents the minor last version number.
Only when the kernel has changed greatly (historically only two times, 1994 of 1.0, 1996 2.0), a has changed.
The number B can be used to determine whether Linux is stable, even b for the stable version, and the odd B for the development version. C represents some bug fixes, security updates, new features, and number of drives.
In version 2.4.0, for example, 2 represents the major version number, 4 represents the minor version number, and 0 represents a minor change in the last version number.
In the version number, the second digit of the ordinal is an even version indicating that this is a stable version that can be used, such as 2.2.5;
The second odd version of the ordinal is usually a few new things to join, it is not necessarily a stable test version, such as 2.3.1.
This stable version is derived from the previous beta upgrade version number, and a stable version is not developed until it is fully mature.
. The third way, starting with the 2.6.0 version of 2004, is to use a "time-based" approach.
Prior to version 3.0, it was a "a.b.c.d" format.
In seven years, the first two digits a.b namely "2.6" remain unchanged, c with the release of the new version of the increase, d for some bug fixes, security updates, add new features and the number of drivers.
After version 3.0 is the "A.B.C" format, B increases with the release of the new version, and C represents some bug fixes, security updates, new features, and number of drives.
The third method does not use even numbers for stable version, odd for the development version of the naming method.
For example: 3.7.0 is not a development version, but a stable version!
The Linux kernel upgrade time map is as follows:
The detailed table for the Linux kernel version is as follows (http://en.wikipedia.org/wiki/Linux_kernel#Version_numbering):
Longterm support: Provides long-term supported kernel versions
Stable: Stable version, not beta version
Relationship is: Stable version does not always provide long-term support, and provide long-term support must be stable version
3. Linux distributions
In the development of the Linux kernel, we also have to mention the role of various Linux distributions, because they drive the application of Linux,
It also allows more people to start focusing on Linux.
Some organizations or manufacturers, the Linux system's kernel and peripheral utilities (Utilities) software and documents wrapped up,
and provide some system installation interface and system configuration, settings and management tools, it constitutes a distribution version (distribution),
Linux distributions are actually a large package of Linux cores plus peripheral utilities.
Relative to the Linux operating system kernel version, the release version number varies with the publisher, and the version number of the Linux system kernel is relatively independent.
So it is not exact to say that SuSE, RedHat, Ubuntu, Slackware, etc. are directly Linux, they are the distributions of Linux,
Rather, it should be called "Linux-centric operating system software package".
According to the GPL, these distributions originate from one core and each have their own contributions, but none of them have their own copyrights.
Each release version of Linux (distribution) is the same Linux kernel developed and published using Linus, so there is no compatibility issue at the kernel level.
Each version is a different feeling, but only in the outermost layer of the release version is reflected, and not the Linux itself, especially the kernel is not uniform or incompatible.
When Linux began to appear in the early 90 's, it was only in the form of source code that users needed to compile under other operating systems to use. A number of official versions appeared later.
Some of the most popular official versions are: SUSE, RedHat, Fedora, Debian, Ubuntu, CentOS, Gentoo, and more.
Users can choose the right Linux distribution based on their experience and preferences.
Second, the kernel upgrade strategy
1. View the Linux kernel version:
# Uname-r
2.6.18-194.el5
2. Download the new kernel version:
Go to the official website to download the latest kernel version and corresponding patches:
https://www.kernel.org/
I chose 3.2.14.
#wget-C http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.14.tar.bz2
3. Unzip
Copy the required files to the/USR/SRC and unzip them.
(Note: If there is not enough space under the/USR/SRC, the source file will be the same in the other directory)
# CP linux-3.2.14.tar.gz/usr/src/
# cd/usr/src/
Unzip the file to/usr/src/kernels
# TAR-XVF Linux-3.2.14.tar.gz-c/usr/src/kernels
4. Clean up files
Erase some of the incorrect files left by the previous upgrade.
# cd/usr/src/kernels/linux-3.2.14
# yum Install Ncurses-devel #升级ncurses
# Make Mrporper
# cp/boot/config-' uname-r '/usr/src/kernels/linux3.2.14/.config #使用原来的配置文件
5. Configure the kernel via Menu mode
# cd/usr/src/kernels/linux-3.2.14
# Make Menuconfig
The Linux configuration menu looks like this:
Be sure to tick (enter Y to select, m to compile as module)
A, general setup→[*] enable deprecated SYSFS features to support old userspace tools
B, Processor type and features→highmemory support.
C. Locate the following check options and select:
Networking support→networking Options→network Packet filtering framework (NetFilter)
(1) Corenetfilter Configuration
. Tick "NetFilter Connection tracking support"-m state related module is dependent on it, not selected.
. The NetBIOS Name Service protocal support (new) is compiled into a module, otherwise an error occurs when the iptables is started after the upgrade
. Tick "NetFilter xtables support (required for ip_tables)"
(2) Ip:netfilter Configuration
. Compile "IPV4 connection tracking support (require for NAT)" into a module.
. Ching IP Tables Support (required for filtering/masq/nat).
. Compile "Masquerade target support" and "REDIRECT target" into modules under "full NAT"
6. Compiling and installing the kernel
# Make clean//clear the target file under kernel compilation
# make Bzimage//Generate kernel files
# make modules//encoding module
# make Modules_install//install module
# make install//install
7. Edit boot menu Options Grub file
Change Default=1 to Default=0
# vim/etc/grub.conf
# grub.conf generated by Anaconda
#
# Note that you don't have the to rerun grub after making changes to the This file
# notice:you does not have a/boot partition. This means
# all kernel and INITRD paths is relative to/, eg.
# root (hd0,0)
# kernel/boot/vmlinuz-version RO root=/dev/sda1
# initrd/boot/initrd-version.img
#boot =/DEV/SDA
Default=0
Timeout=5
Splashimage= (hd0,0)/boot/grub/splash.xpm.gz
Hiddenmenu
Title Red Hat Enterprise Linux Server (3.2.14)
Root (hd0,0)
kernel/boot/vmlinuz-3.2.14 ro root=label=/
Initrd/boot/initrd-3.2.14.img
Title Red Hat Enterprise Linux Server (2.6.18-274.EL5)
Root (hd0,0)
Kernel/boot/vmlinuz-2.6.18-274.el5 ro root=label=/
Initrd/boot/initrd-2.6.18-274.el5.img
"Save and Exit"
8. Restart
# shutdown-r "Now"
9. View Kernel Compilation results
# Uname-r
3.2.14-rt24
Iii. errors encountered in kernel compilation and solutions
Error one, error message at compile time
In file included From/usr/include/sys/time.h:31,
From/usr/include/linux/input.h:12,
From samples/hidraw/hid-example.c:14:
/usr/include/sys/select.h:78:error:conflicting types for ' fd_set '
/usr/include/linux/types.h:12:error:previous declaration of ' Fd_set ' is here
In file included From/usr/include/linux/input.h:14,
From samples/hidraw/hid-example.c:14:
/usr/include/sys/types.h:46:error:conflicting types for ' loff_t '
/usr/include/linux/types.h:30:error:previous declaration of ' loff_t ' is here
/usr/include/sys/types.h:62:error:conflicting types for ' dev_t '
/usr/include/linux/types.h:13:error:previous declaration of ' dev_t ' is here
In file included from/usr/include/sys/types.h:133,
From/usr/include/linux/input.h:14,
From samples/hidraw/hid-example.c:14:
/usr/include/time.h:105:error:conflicting types for ' timer_t '
/usr/include/linux/types.h:22:error:previous declaration of ' timer_t ' is here
In file included From/usr/include/linux/input.h:14,
From samples/hidraw/hid-example.c:14:
/usr/include/sys/types.h:198:error:conflicting types for ' int64_t '
/usr/include/linux/types.h:98:error:previous declaration of ' int64_t ' is here
/usr/include/sys/types.h:204:error:conflicting types for ' u_int64_t '
/usr/include/linux/types.h:97:error:previous declaration of ' u_int64_t ' is here
In file included From/usr/include/linux/input.h:14,
From samples/hidraw/hid-example.c:14:
/usr/include/sys/types.h:235:error:conflicting types for ' blkcnt_t '
/usr/include/linux/types.h:114:error:previous declaration of ' blkcnt_t ' is here
Samples/hidraw/hid-example.c:15:26:error:linux/hidraw.h:no such file or directory
samples/hidraw/hid-example.c:in function ' main ':
Samples/hidraw/hid-example.c:48:error:storage size of ' rpt_desc ' isn ' t known
Samples/hidraw/hid-example.c:49:error:storage size of ' info ' isn ' t known
Samples/hidraw/hid-example.c:65:error: ' Hidiocgrdescsize ' undeclared (first use of this function)
Samples/hidraw/hid-example.c:65:error: (Each undeclared identifier was reported only once
Samples/hidraw/hid-example.c:65:error:for each function it appears in.)
Samples/hidraw/hid-example.c:73:error: ' Hidiocgrdesc ' undeclared (first use of this function)
Samples/hidraw/hid-example.c:84:warning:implicit declaration of function ' Hidiocgrawname '
Samples/hidraw/hid-example.c:91:warning:implicit declaration of function ' Hidiocgrawphys '
Samples/hidraw/hid-example.c:98:error: ' Hidiocgrawinfo ' undeclared (first use of this function)
samples/hidraw/hid-example.c:49:warning:unused variable ' info '
samples/hidraw/hid-example.c:48:warning:unused variable ' rpt_desc '
samples/hidraw/hid-example.c:in function ' bus_str ':
Samples/hidraw/hid-example.c:171:error: ' Bus_virtual ' undeclared (first use of this function)
MAKE[2]: * * * [samples/hidraw/hid-example] Error 1
MAKE[1]: * * * [Samples/hidraw] Error 2
Make: * * * [vmlinux] Error 2
Solution:
# CP include/linux/hidraw.h/usr/include/linux/
# CP include/linux/hid.h/usr/include/linux/
# Vim SAMPLES/HIDRAW/HID-EXAMPLE.C
(under Linux, the compiler sometimes encounters this problem, which seems to be a legacy of Linux history:
Bring all of the # include <sys/xxx.h> to the front, put the inclusion of # include <linux/xxx.h> behind, and you can compile and pass,
The problem with polygons is that there are circular references. )
Move the following 3 lines of 13-15 rows to 33 rows later.
#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
"Save and Exit"
# vim/usr/include/linux/input.h
Line 647
#define BUS_PCI 0x01
#define BUS_ISAPNP 0x02
#define BUS_USB 0x03
#define Bus_hil 0x04
#define Bus_bluetooth 0x05
/* The following behavior is new */
#define Bus_virtual 0x06
#define BUS_ISA 0x10
#define BUS_I8042 0x11
#define BUS_XTKBD 0x12
#define BUS_RS232 0x13
#define Bus_gameport 0x14
#define Bus_parport 0x15
#define Bus_amiga 0x16
#define BUS_ADB 0x17
#define BUS_I2C 0x18
#define Bus_host 0x19
#define BUS_GSC 0x1A
/* The following two behaviors are added */
#define Bus_atari 0x1B
#define BUS_SPI 0x1C
"Save and Exit"
re-compile;
Error Two:
Error tip: Kernel Panic-not syncing:vfs:unable to mount Root fs on Unkown-block (0,0)
Error Analysis: The initrd-*.*.img file has a problem; the real root filesystem was not mounted successfully.
WORKAROUND: Please confirm that the make install command was executed and I wasted a week for not executing this command
Error Three:
Error prompt: Create root device mkrootdev:label/not found
Mountingrootfilesystem
Mount:error2 mounting EX T3
Mount:error 2mountingnone
Switch root mount failed:22
Umount/initrd/dev failed:2
Kernel panic-not s Ynicncing:attempted to kill Init.
(the error is not a bit long, seems to be a lot of errors, it may be a cause)
Error Analysis:
1, the root file system cannot find the mount point, modify the grub.conf file to root=/dev/*
2, hard drive failed to find, Please look at your machine's hard disk is all SATA disk, is the same congratulations you this article is helpful.
Error Resolution:
1., modify the grub.conf file to try, the specific modification point
root=/dev/*
* refers to the mount point of the original system/partition. After the modification, reboot into the new kernel system, it is estimated that the following error will be encountered in nine days:
Mounting root filesystem
MOUNT:ERROR6 mounting ext3
Mount:error 2 Mountingnone
Switchroot Mount Failed:22
Umount/initrd/dev Failed:2
Kernel panic-not synicncing:attempted Tokil linit.
If the misfortune is in my words, please look down.
2, hard drive failed to find, SCSI driver has a problem.
I encountered this problem in the kernel compilation upgrade, the kernel option is selected and selected, the method tried many kinds, the error is still.
Finally, I accidentally chose the correct option to successfully upgrade the kernel.
The specific options are:
Device Drivers--------SCSI
Device Support------SCSI
Low-level drivers----Serial ATA (SATA) support is selected as M,
Then select the appropriate sub-options, I selected the Intel Piix/ich SATA Support (new) after the machine started successfully.
Error Four:
Error TIP: Enforcing mode requested but no policy loaded. Halting now.
Kernel panic-not syncing:attenpted to kill init!
Error Analysis: SELinux is enabled in the original kernel, the new kernel does not have the option to select SELinux and does not start successfully.
Workaround: Modify the grub.conf file and add the enforcing=0 after root=label=/
Error Five:
After compiling the reboot, it appears:
Switchroot:mount failed:22
Umount/initrd/dev Failed:2
Kernel panic-not symcing:attempted to kill init!
The error,
Workaround:
Re-make Menuconfig so config_sysfs_deprecated_v2=y
You can also open the file. config for modification and validation;
Re-execution:
# Make Bzimage
# Make Modules
# Make Modules_install
# make Install
# shutdown-r "Now"
Iv. Linux kernel boot process
The computer starts with a power-up,
Then the hardware detects and boots the operating system initialization program,
Then the operating system's initialization process is responsible for reading into the system kernel and building the operating environment of the system.
This process is relatively complex and relevant to the CPU architecture, where we describe this process in more detail through Linux and with the i386 architecture.
1. Hardware Detection
. When the machine is power-up, it first executes the code in the BIOS (basic input and output system), the BIOS performs the power-on self-Test (POST) first, and the hardware is booted when the self-test passes through the process.
. The post program determines the presence of the hardware and can operate correctly by diagnosing the memory and other hardware's devices.
. The BIOS is a program that is cured on the chip, and it typically takes only a few seconds to perform this process.
. When the self-test is complete, the BIOS searches for a valid boot drive in the boot order set in the system COMs (here we take the hard drive as an example),
and read into the system boot sector and give the system control to the boot program.
2. Loading and executing the boot program
The system bootloader primarily loads the system kernel into memory, and the boot disk must contain a boot record on the first logical track.
This 512-byte sector is also referred to as the boot sector,
After the system completes the power-on self-test, the BIOS reads the boot sector into memory from the boot disk.
The boot record contains parameters for some of the physical properties of the disk.
After the boot sector is read into memory, the BIOS can read the physical parameters of the boot disk from here.
Once the boot record has been loaded, the BIOS will hand over the execution control of the system and jump to the boot program's head execution.
The boot record begins with an unconditional transfer instruction, which immediately jumps to the address 0x03e execution bootstrapper,
In the boot sector, this bootstrapper will read out several more complex programs from disk and load the system kernel with them.
The boot program for Linux is arch/i386/boot/bootsect by the assembly code file. S generation,
It takes advantage of a call to the BIOS function to be arch/i386/boot/under Setup. s file and kernel image loaded into memory.
I386 the architecture of the CPU sub-protection mode and real mode two, in real mode can only use low-end 640K memory.
The CPU is in real mode when the bootloader is loaded, and now the kernel image file generally exceeds the limit of 640K, even after the compressed kernel image,
This kernel image file is usually bzimage, and we usually use this file when compiling the kernel.
Since bzimage exceeds the 640K limit, Linux has designed a Bootsect_helper subroutine (defined in Arch/i386/boot/setup. s),
The boot program loops through the bootsect_helper to load the kernel image into memory, and when the kernel is loaded, the system jumps to setup. The start position of S begins to execute,
Setup. S is still running in real mode, the main function is to set the system parameters (such as: memory, disk, etc.),
and prepare for entry into protected mode, finally entering the protection mode and jumping to the head of the kernel image file to start executing the kernel.
Here's a boot program for Linux. Lilo and Grub,lilo and grub can boot multiple systems,
If you want to install multiple systems on the machine, they are usually used, and the bootloader is stored in the boot sector or in the Master Boot Record (MBR).
Both Lilo and Grub are Xu Yun to the user's own configuration, which establishes a comparison table of disk data blocks used by the system kernel when the system is installed.
When the user chooses to start the Linux system, it also jumps to setup. running on S.
3. Kernel initialization
When Setup. After s execution, the CPU performs a protected mode and starts executing the kernel,
. If the kernel is compressed, first execute the head in the arch/i386/boot/compressed directory. s build the stack and unzip the kernel image file,
Then go to head under Arch/i386/kernel. S
. If there is no compression, go directly to head under Arch/i386/kernel. s begins execution.
Arch/i386/kernel/head. The S program is responsible for initializing the data area (BBS), Interrupt description Table (IDT), Segment Description table (GDT), page table, and register.
Finally, enter the Start_kernel () module.
At this point the system runs under kernel mode (level 0) and is transferred to Start_kernel () in INIT/MAIN.C.
Start_kernel () continues with other aspects of initialization, primarily the initialization of the system's core data structures, mainly including:
Setup_arch (): Performs architecture-related settings.
Trap_init (): Sets various entry addresses.
INIT_IRQ (): Initializes the IRQ interrupt handling mechanism.
Sched_init (): Sets and starts the first process, Init_task ().
Softirq_init (): Initializes the soft interrupt subsystem.
Console_init (): Initializes the console, monitor.
Init_modules (): initializes the kernel_module.
Fork_init (): Defines the maximum number of processes for the system.
Finally enter the Rest_init () function and call Kernel_thread () to create the Init kernel thread for system configuration.
The init kernel thread occupies the first item of the Process description table, which is used by it to create other complete systems to initiate his process.
The init kernel thread first pins the kernel and then calls Do_basic_setup () to initialize the external device and load the driver.
The main initialization tasks include:
PCI bus initialization.
Network initialization.
File system initialization.
Load the file system.
After the Do_basic_setup () call is complete, init () releases the memory that the initialization function occupies,
and the/dev/console device redirection console is turned on, and the system calls Execve to perform the user-state program/sbin/init.
At this point, the kernel initialization of Linux is done.
4. The following work is done by the user-configured/sbin/init program.
The Init routine reads the/etc/inittab file to determine its specific work. A few of the more important in Inittab are:
Id:5:initdefault determines the default execution level at the start of the operating system (this is about the operating level of the system, which is different from the CPU level)
Si:sysinit:/etc/rc.d/rc.sysinit executes the/etc/rc.d/rc.sysinit script.
The main task of Rc.sysinit is to activate the swap partition, check the disk, and load the hardware module.
1:2345:respawn:/sbin/mingetty tty1 Display Login screen
At this point, the entire system's boot process is complete.
Kernel Upgrade 2.6.11-3.0.2