linux内核升级


实验背景:

与其他操作系统、应用软件类似,Linux内核也会存在一些漏洞,或者RHEL定制的内核不能满足企业实际的需要。这种情况下,管理员可以选择升级内核、重新定制内核。



实验思路:


1.为了节省时间,采用预制作的内核升级包kernel-2.6.32.61-5.x86_64.rpm ,通过第三方定制的内核RPM包升级RHEL5服务器的内核版本。


?与RHEL 5.9原内核相比,升级包移除了bluetooth模块、新编入ntfs模块。


2.根据实际应用的需要查看、添加、删除Linux内核模块。


实验实践:


1

#uname -r //查看当前内核版本

#cat /etc/redhat-release//查看系统版本


2 把内核rpm包复制到桌面,安装

#rpm -ivh kernel-2.6.32.61-5.x86_64.rpm

#ls /boot/*2.6.32.61* //确认安装内核相关文件

#ls /lib/modules/2.6.32.61///确认新安装的模块文件


3 为新内核创建initrd镜像文件

#mkinitrd /boot/initrd-2.6.32.61.img 2.6.32.61 //创建镜像

#ls -lh /boot/initrd-2.6.32.61.img


4 调整grub.conf引导参数,以启用新内核

#vim /boot/grub/grub.conf//修改grub配置文件

default=1                                 //修改此行,对应新内核title的顺序

timeout=5

splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.18-348.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-348.el5 ro root=LABEL=/ rhgb quiet

initrd /initrd-2.6.18-348.el5.img

title Red Hat Enterprise Linux Server (2.6.32.61)

root (hd0,0)

kernel /vmlinuz-2.6.32.61 ro root=LABEL=/ rhgb quiet

initrd /initrd-2.6.32.61.img

5 重启Linux系统,验证升级后的新内核

#reboot

#uname -r

  检查ntfs模块:

#lsmod | grep ntfs

# modprobe ntfs //手动加载

#lsmod | grep ntfs

  检查bluetooth模块:

# lsmod | grep bluetooth

# modprobe bluetooth//手动加载

# lsmod | grep bluetooth

6 内核模块的管理

1)列出已加载的所有模块

查看所有模块:

1.[root@svr5 ~]# lsmod

2.Module             Size    Used by

3.exportfs         3346    0

4.ntfs             209196    0

5.autofs4             21652    3

6.lockd             62703    0

7.sunrpc             192791    2 lockd

8.ipv6             241344     138

9.fuse             54304    0

10.acpiphp             16509     0

11.dm_mirror         10626    0

查看与ext文件系统相关的模块:

1.[root@svr5 ~]# lsmod | grep "ext"

2.ext3 113104 4

3.jbd 42943 1 ext3

2)查看模块ext4的信息

1.[root@svr5 ~]# modinfo ext4

2.filename: /lib/modules/2.6.32.61/kernel/fs/ext4/ext4.ko

3.license: GPL

4.description: Fourth Extended Filesystem

5.author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others

6.srcversion: FB699E3B9C282341EDD0BA6

7.depends: jbd2,crc16

8.vermagic: 2.6.32.61 SMP mod_unload modversions

3)智能检测并加载指定名称的模块

智能加载ext4模块:

1.[root@svr5 ~]# modprobe ext4                     //加载ext4模块

2.[root@svr5 ~]# lsmod | grep "ext4"             //确认加载结果

3.ext4 311400 0

4.jbd2 75758 1 ext4

5.crc16 1595 1 ext4

同时加载多个模块(ext4和xfs):

1.[root@svr5 ~]# modprobe xfs ext4                 //加载ext4、xfs模块

2.[root@svr5 ~]# lsmod | grep -E "^ext4|^xfs"     //确认加载结果

3.xfs 428143 0

4.ext4 311400 0

4)移除指定的内核模块

同时移除ext4、xfs内核模块:

1.[root@svr5 ~]# rmmod ext4 xfs

2.[root@svr5 ~]# lsmod | grep -E "^ext4|^xfs"

3.[root@svr5 ~]#

5)手动加载指定路径的内核模块

插入xfs.ko模块(适用于当前内核版本,成功):

1.[root@svr5 ~]# cd /lib/modules/2.6.32.61/kernel/fs/xfs/

2.[root@svr5 xfs]# insmod xfs.ko

3.[root@svr5 xfs]# lsmod | grep "^xfs"

4.xfs 428143 0

插入bluetooth.ko模块(与当前版本不匹配,失败):

1.[root@svr5 xfs]# cd /lib/modules/2.6.18-348.el5/kernel/net/bluetooth/

2.[root@svr5 bluetooth]# insmod bluetooth.ko

3.insmod: error inserting 'bluetooth.ko': -1 Invalid module format