方式一:RPM方式升級(jí)
Centos7內(nèi)核下載地址:(下載較慢)
https://elrepo.org/linux/kernel/el7/x86_64/RPMS/
ELRepo 倉庫是基于社區(qū)的用于企業(yè)級(jí) Linux 倉庫,提供對 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 發(fā)行版(CentOS、Scientific、Fedora 等)的支持。
ELRepo 聚焦于和硬件相關(guān)的軟件包,包括文件系統(tǒng)驅(qū)動(dòng)、顯卡驅(qū)動(dòng)、網(wǎng)絡(luò)驅(qū)動(dòng)、聲卡驅(qū)動(dòng)和攝像頭驅(qū)動(dòng)等。
1)查看現(xiàn)在版本:
[root@bogon ~]# uname -a
Linux bogon 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
2)查看當(dāng)前內(nèi)核的啟動(dòng)順序
[root@bogon ~]# awk '$1=="menuentry" {print $2,$3,$4}' /etc/grub2.cfg
'CentOS Linux (3.10.0-1062.el7.x86_64)
'CentOS Linux (0-rescue-b7a3ea7d78bf4158a407212888569530)
3)下載對應(yīng)的內(nèi)核包:
[root@bogon ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-4.4.218-1.el7.elrepo.x86_64.rpm
4)安裝內(nèi)核:
[root@bogon ~]# yum install -y kernel-lt-4.4.218-1.el7.elrepo.x86_64.rpm
5)修改配置文件 設(shè)置默認(rèn)啟動(dòng)項(xiàng),0是按menuentry順序。比如要默認(rèn)從第四個(gè)菜單項(xiàng)啟動(dòng),數(shù)字改為3,若改為 saved,則默認(rèn)為上次啟動(dòng)項(xiàng)。
注意文件為:/etc/default/grub
[root@bogon ~]# sed -i "s/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/g" /etc/default/grub
6)重寫grub.cfg
[root@bogon ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
7)重啟
[root@bogon ~]# reboot
[root@bogon ~]# uname -a
Linux bogon 4.4.218-1.el7.elrepo.x86_64 #1 SMP Thu Apr 2 14:46:23 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux
8)再次查看內(nèi)核的啟動(dòng)順序:
[root@bogon ~]# awk '$1=="menuentry" {print $2,$3,$4}' /etc/grub2.cfg
'CentOS Linux (4.4.218-1.el7.elrepo.x86_64)
'CentOS Linux (3.10.0-1062.el7.x86_64)
'CentOS Linux (0-rescue-b7a3ea7d78bf4158a407212888569530)
方式二 源碼方式升級(jí)
內(nèi)核源碼下載地址:https://www.kernel.org/
名詞解釋:
stable(穩(wěn)定)
mainline(開發(fā))
longterm(歷史)
tarball:完整代碼
pgp:驗(yàn)證簽名
patch:補(bǔ)丁
1)準(zhǔn)備編譯環(huán)境:
[root@bogon ~]# yum -y groups install "Development Tools" # 無法下載則跳過
[root@bogon ~]# yum -y install ncurses-devel elfutils-libelf-devel bc openssl-devel.x86_64
[root@bogon ~]# tar -xf linux-4.4.219.tar.xz
[root@bogon ~]# cp /boot/config-3.10.0-1062.el7.x86_64 /root/linux-4.4.219
[root@bogon ~]# cd linux-4.4.219
[root@bogon linux-4.4.219]# make menuconfig # 如果報(bào)錯(cuò)則將終端放大
[root@bogon linux-4.4.219]# make
[root@bogon linux-4.4.219]# make modules_install
[root@bogon linux-4.4.219]# make install
[root@bogon linux-4.4.219]# sed -i "s/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/g" /etc/default/grub
# 重寫grub.cfg
[root@bogon linux-4.4.219]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@bogon linux-4.4.219]# reboot
[root@bogon ~]# uname -a
Linux bogon 4.4.219 #1 SMP Tue Apr 21 21:16:18 CST 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@bogon ~]# hostnamectl
Static hostname: localhost.localdomain
Transient hostname: bogon
Icon name: computer-vm
Chassis: vm
Machine ID: b7a3ea7d78bf4158a407212888569530
Boot ID: 1a89779890bf4bbab63f5e7f97f693ee
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 4.4.219
Architecture: x86-64
卸載內(nèi)核(危險(xiǎn))
[root@bogon ~]# cd /boot/
[root@bogon boot]# rm -rf *-4* # 謹(jǐn)慎,一般不進(jìn)行
[root@bogon boot]# vim /boot/grub2/grub.cfg
刪除之前添加內(nèi)核的部分
[root@bogon boot]# reboot
[root@bogon ~]# uname -r
3.10.0-1062.el7.x86_64