环境:rehl7.2 x64 3G内存 3核 40磁盘
//查看内核
[root@duwers~]# uname –r #查看内核 3.10.0-327.el7.x86_64
//加20G磁盘
[root@duwers ~]# mkdir /sdb1 [root@duwers ~]# fdisk /dev/sdb [root@duwers ~]# mkfs.xfs /dev/sdb1 [root@duwers ~]# mount /dev/sdb1 /sdb1 [root@duwers ~]# tail -1 /etc/fstab /dev/sdb1 /sdb1 xfs defaults 0 0 [root@duwers ~]#
1、 下载相应内核源码包4.4
[root@duwerssdb1]# ls linux-4.4.tar.xz [root@duwerssdb1]#
2、 确认系统具备编译软件的基本条件,即make、gcc、gcc-c++、ncurses-devel
[root@duwerssdb1]# cd [root@duwers~]# rpm -qa | grep make make-3.82-21.el7.x86_64 automake-1.13.4-3.el7.noarch [root@duwers~]# rpm -qa | grep gcc gcc-c++-4.8.5-4.el7.x86_64 libgcc-4.8.5-4.el7.x86_64 gcc-4.8.5-4.el7.x86_64 gcc-gfortran-4.8.5-4.el7.x86_64 [root@duwers~]# rpm -qa | grep gcc-c++ gcc-c++-4.8.5-4.el7.x86_64 [root@duwers~]# rpm -qa | grep ncurses-devle [root@duwers~]# [root@duwers~]# yum -y install ncurses-devel
3、 解压内核源码包
[root@duwers~]# cd /sdb1 [root@duwerssdb1]# ls linux-4.4.tar.xz [root@duwerssdb1]# xz -d linux-4.4.tar.xz [root@duwerssdb1]# ls linux-4.4.tar [root@duwerssdb1]# tar -xf linux-4.4.tar [root@duwerssdb1]# ls linux-4.4 linux-4.4.tar [root@duwerssdb1]# du -sh linux-4.4 702M linux-4.4 [root@duwerssdb1]#
//释放缓存
[root@duwerssdb1]# free -m total used free shared buff/cache available Mem: 2993 371 721 9 1901 2398 Swap: 2047 0 2047 [root@duwerssdb1]# echo 3 > /proc/sys/vm/drop_caches [root@duwerssdb1]# free -m total used free shared buff/cache available Mem: 2993 333 2512 9 148 2507 Swap: 2047 0 2047 [root@duwerssdb1]#
4、 配置内核编译参数【改成支持NTFS的,在make menuconfig后会弹出界面】
[[email protected]]# pwd /sdb1/linux-4.4 [root@duwers linux-4.4]# make menuconfig [root@duwers linux-4.4]# vim .config
//系统自带的是不支持的
[root@duwers linux-4.4]# vim /boot/config-3.10.0-327.el7.x86_64
//把系统自带的拷贝到新内核文件里面,,表述不清晰,大概意思哈,看操作:
[root@duwers linux-4.4]# [root@duwers linux-4.4]# cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.4/.config cp: overwrite ‘/sdb1/linux-4.4/.config’? y [root@duwers linux-4.4]# [root@duwers linux-4.4]# make menuconfig [root@duwers linux-4.4]# vim ./.config
拷贝好以后修改【改成支持NTFS的,在make menuconfig后会弹出界面】
效果如图
5、编译内核
//生成内核
[root@duwers linux-4.4]# make bzImage
//这里是会报错的喔!!报错如下(末尾的几行代码)
HOSTCC scripts/sortextable HOSTCC scripts/asn1_compiler HOSTCC scripts/sign-file scripts/sign-file.c:23:30:fatal error: openssl/opensslv.h: No such file or directory #include^ compilationterminated. make[1]:*** [scripts/sign-file] Error 1 make: ***[scripts] Error 2 [root@duwers linux-4.4]#
//解决
[root@duwers linux-4.4]# yum -y install openssl-devel
//重新生成内核,大概半小时吧,
[root@duwers linux-4.4]# make bzImage
//完成后就下图的样子(最后几行代码)
6、 生成新内核的驱动模块,就下面这个make 搞了我一个多小时,忘记-j 4了
[root@duwers linux-4.4]# make modules
// 忘记截图了,呵呵哒
//清空缓存
[root@duwers linux-4.4]# sync [root@duwers linux-4.4]# free –m
7、 安装编译好的内核与模块
1) 安装模块,这个快,几分钟的事情
[root@duwers linux-4.4]# make modules_install
2)
[root@duwers ~]# cd /sdb1/linux-4.4/ [root@duwers linux-4.4]# make install
8、 查看或修改GRUB菜单(为了确认是不是把内核安装好了)
[root@duwers ~]#vim /boot/grub2/grub.cfg
9、 重启系统,测试新内核工作情况
///重启要选择啊!重启要选择啊!重启要选择啊!【重要的事情说三遍】
查看新内核
//修改默认的启动选项,
[root@duwers linux-4.6.3]# cat /boot/grub2/grub.cfg |grep menuentry if [x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" exportmenuentry_id_option menuentry'Red Hat Enterprise Linux Server (4.4.0) 7.2 (Maipo)' --class red --classgnu-linux --class gnu --class os --unrestricted $menuentry_id_option'gnulinux-3.10.0-327.el7.x86_64-advanced-a91da850-a46f-4604-a494-54b56d1a2841'{ menuentry'Red Hat Enterprise Linux Server (3.10.0-327.el7.x86_64) 7.2 (Maipo)' --cla***ed --class gnu-linux --class gnu --class os --unrestricted$menuentry_id_option'gnulinux-3.10.0-327.el7.x86_64-advanced-a91da850-a46f-4604-a494-54b56d1a2841'{ menuentry'Red Hat Enterprise Linux Server (0-rescue-7dd2238acdc6468c9bfec97e0a5978fb)7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os--unrestricted $menuentry_id_option'gnulinux-0-rescue-7dd2238acdc6468c9bfec97e0a5978fb-advanced-a91da850-a46f-4604-a494-54b56d1a2841'{ [root@duwers linux-4.6.3]# grub2-set-default "Red Hat Enterprise Linux Server (4.4.0)7.2 (Maipo)" [root@duwers linux-4.6.3]# grub2-editenv list saved_entry=RedHat Enterprise Linux Server (4.4.0) 7.2 (Maipo) [root@duwers linux-4.6.3]#
The End!!