打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

Linux内核升级

为了方便起见,可以通过yum的方式进行升级

具体方法参见:http://elrepo.org/

1、rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 

2、rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

3、yum --enablerepo=elrepo-kernel  install kernel-lt

4、编辑开机菜单选项grub文件,需要修改Grub引导顺序,让新安装的内核作为默认内核。

将 default=1 改为 default=0

然后重启机器后,验证是否升级成功中。

----------------------------------------------------------------------------------------------------

一、Linux内核概览
Linux是一个一体化内核(monolithic kernel)系统。
设备驱动程序可以完全访问硬件。
Linux内的设备驱动程序可以方便地以模块化(modularize)的形式设置,并在系统运行期间可直接装载或卸载。

1. linux内核
linux操作系统是一个用来和硬件打交道并为用户程序提供一个有限服务集的低级支撑软件。
一个计算机系统是一个硬件和软件的共生体,它们互相依赖,不可分割。
计算机的硬件,含有外围设备、处理器、内存、硬盘和其他的电子设备组成计算机的发动机。
但是没有软件来操作和控制它,自身是不能工作的。
完成这个控制工作的软件就称为操作系统,在Linux的术语中被称为“内核”,也可以称为“核心”。

Linux内核的主要模块(或组件)分以下几个部分:
. 进程管理(process management) 
. 定时器(timer)
. 中断管理(interrupt management)
. 内存管理(memory management)
. 模块管理(module management)
. 虚拟文件系统接口(VFS layer)
. 文件系统(file system)
. 设备驱动程序(device driver)
. 进程间通信(inter-process communication)
. 网络管理(network management
. 系统启动(system init)等操作系统功能的实现。

2. linux内核版本号
Linux内核使用三种不同的版本编号方式。
. 第一种方式用于1.0版本之前(包括1.0)。
  第一个版本是0.01,紧接着是0.02、0.03、0.10、0.11、0.12、0.95、0.96、0.97、0.98、0.99和之后的1.0。
. 第二种方式用于1.0之后到2.6,数字由三部分“A.B.C”,A代表主版本号,B代表次主版本号,C代表较小的末版本号
  只有在内核发生很大变化时(历史上只发生过两次,1994年的1.0,1996年的2.0),A才变化。
  可以通过数字B来判断Linux是否稳定,偶数的B代表稳定版,奇数的B代表开发版。C代表一些bug修复,安全更新,新特性和驱动的次数
  以版本2.4.0为例,2代表主版本号,4代表次版本号,0代表改动较小的末版本号。
  在版本号中,序号的第二位为偶数的版本表明这是一个可以使用的稳定版本,如2.2.5;
  而序号的第二位为奇数的版本一般有一些新的东西加入,是个不一定很稳定的测试版本,如2.3.1。
  这样稳定版本来源于上一个测试版升级版本号,而一个稳定版本发展到完全成熟后就不再发展。
. 第三种方式从2004年2.6.0版本开始,使用一种“time-based”的方式。
  3.0版本之前,是一种“A.B.C.D”的格式。
  七年里,前两个数字A.B即“2.6”保持不变,C随着新版本的发布而增加,D代表一些bug修复,安全更新,添加新特性和驱动的次数。
  3.0版本之后是“A.B.C”格式,B随着新版本的发布而增加,C代表一些bug修复,安全更新,新特性和驱动的次数。
  第三种方式中不使用偶数代表稳定版,奇数代表开发版这样的命名方式。
  举个例子:3.7.0代表的不是开发版,而是稳定版!


二、内核升级攻略
1. 查看linux内核版本:
# uname -r
2.6.18-194.el5

2. 下载新的内核版本:
去官网上下载最新的内核版本和对应的补丁:
https://www.kernel.org/
我选的是linux-3.10.99.tar.xz
wget -c  https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.10.99.tar.xz

3. 解压
将所需文件复制到 /usr/src 下并解压。
(注:如果/usr/src下的空间不够,将源文件放在别的目录下也是一样的)

将文件解压到 /usr/src/kernels
# tar -xvf linux-3.10.99.tar.gz -C /usr/src/kernels

4.升级ncurses

yum install -y ncurses-devel   

# yum install -y bc

5. 通过菜单方式配置内核

# cd /usr/src/kernels/linux-3.10.99

# make menuconfig     (生成 .config 文件)

一定要勾选(输入y选中,M编译为模块)
a、General setup→[*] Enable deprecated sysfs features to support old userspace tools
b、找到以下选中选项并选中:
Networking support → Networking options → Network packet filtering framework(Netfilter)下的
(1) Core Netfilter Configuration
. 勾中"Netfilter connection tracking support" -m state相关模块是依赖它的,不选则没有。
. 将NetBIOS name service protocal support(new) 编译成模块,不然后面升级iptables后启动时会出错
. 勾中"Netfilter Xtables support (required for ip_tables)"

(2) IP: Netfilter Configuration   该项下面的全选即可,否则iptables使用时有问题,尤其使用NAT表时
. 将 "IPv4 connection tracking support (require for NAT)" 编译成模块。
. 勾中IP tables support (required for filtering/masq/NAT) 。
. 将 "IPv4 NAT" 下的 "MASQUERADE target support" 和 "REDIRECT target support" 编译成模块

6. 编译并安装内核
# make clean                // 清除下内核编译的目标文件
# make bzImage           // 生成内核文件
# make modules           // 编码模块
# make modules_install // 安装模块
# make install              // 安装

7. 编辑开机菜单选项grub文件,需要修改Grub引导顺序,让新安装的内核作为默认内核。

将 default=1 改为 default=0

然后重启机器后,验证是否升级成功中。

 

 三、内核编译中遇到的错误及解决办法
错误一、 编译时出现错误提示
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' was 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' was 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' was 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' was 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' was 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' was 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' was 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 in this function)
samples/hidraw/hid-example.c:65: error: (Each undeclared identifier is 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 in 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 in 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 in this function)
make[2]: *** [samples/hidraw/hid-example] Error 1
make[1]: *** [samples/hidraw] Error 2
make: *** [vmlinux] Error 2

解决方案:
# cp include/linux/hidraw.h /usr/include/linux/
# cp include/linux/hid.h /usr/include/linux/
# vim samples/hidraw/hid-example.c
(在Linux下编译程序有时会遇到这种问题,这貌似是一个Linux历史遗留问题: 
把所有#include <sys/xxx.h>都提到最前面,把#include <linux/xxx.h>的包含放在其后,就可以编译通过了,
之所以出现面的问题是存在循环引用所致。)
将13-15行的如下3行移动到33行以后。     
13 #include <linux/types.h>     
14 #include <linux/input.h>     
15 #include <linux/hidraw.h>     
29 #include <sys/ioctl.h>     
30 #include <sys/types.h>     
31 #include <sys/stat.h>     
32 #include <fcntl.h>     
33 #include <unistd.h>
【保存并退出】

# 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
/*以下一行为新增*/
#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

/*以下两行为新增*/
#define BUS_ATARI               0x1B
#define BUS_SPI                 0x1C 
【保存并退出】
再重新编译;

错误二:
错误提示:Kernel panic—not syncing :vfs:unable to mount root fs on unkown—block (0,0)
错误分析:initrd-*.*.img文件有问题;未能成功挂载真正的根文件系统。
解决方法:请你确认执行了make install 命令,我就因为没有执行这条命令而浪费了一周时间

错误三:
错误提示:Create root device  mkrootdev: label / not found 
                     Mountingrootfilesystem 
                     mount :error2 mounting ext3
                     mount :error 2mountingnone 
                     switch root mount failed:22
                     umount  /initrd/dev failed :2
                     kernel panic-not synicncing :Attempted to kill  init .
(错误提示是不是有点长,貌似错误很多哦,其实可能就一个原因导致)
错误分析:
1、根文件系统找不到挂载点 ,修改grub.conf文件为 root=/dev/ * 
2、硬盘驱动未能找到,请看看你机器的硬盘是都是 SATA盘,是的话同样恭喜你本文对你有帮助。

错误解决:
1.、修改grub.conf文件试试,具体修改点
root=/dev/*
* 指的是原系统中/分区的挂载点。修改后,重启进入新内核系统,估计十有八九又会遇到如下错误提示:
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 .
如果不幸被我言中,请接着往下看。
2、硬盘驱动未能成功找到,SCSI驱动有问题。
我在内核编译升级中遇到这个问题,对内核选项选了又选,方法试了很多种,错误依旧。
最终让我无意中选正确选项,成功升级内核。
具体选项是:
Device Drivers--------SCSI
device support------SCSI
low-level drivers----Serial ATA(SATA)support 选为 M,
然后再选择相应的子选项,我选择了Intel PIIX/ICH  SATA support (new)后机器就成功启动了。

错误四:
错误提示:Enforcing mode requested but no policy loaded. Halting now.
kernel panic - not syncing: Attenpted to kill init!
错误分析:原内核中启用了selinux,新内核未选择selinux的选项,不能成功启动。
解决方法:修改grub.conf文件,在root=LABEL=/ 后加入 enforcing=0 

错误五:
编译完重启后出现:
switchroot:   mount   failed:   22 
umount   /initrd/dev   failed:   2 
kernel   panic   -   not   symcing:   Attempted   to   kill   init! 
的错误,

解决办法:
重新make menuconfig, 使CONFIG_SYSFS_DEPRECATED_V2=y
也可以打开文件.config做修改和验证;
再执行:
# make bzImage
# make modules
# make modules_install
# make install
# shutdown -r "now"

posted on 2016-03-08 10:13  星辰大海ゞ  阅读(577)  评论(0编辑  收藏  举报