yum和編譯兩種方式升級or降級Centos核心
今天探討用yum和編譯兩種方式升級或者降級核心版本:
升級:比如玩kvm,docker等虛擬化,centos核心則升級尤為重要(雖然核心通過載入模組也可以玩,但是效果不如)
降級:如果發現核心在危險漏洞列,降級核心則顯得尤為重要。當然如果有特殊需求,也可以降級核心。
1、yum方式升級核心版本
)檢視當前系統核心版本
[[email protected] ~]# cat /etc/redhat-release CentOS release (Final) [[email protected] ~]# uname -r -_64 [[email protected] ~]#
)準備yum源,並安裝
#/linux/kernel/el6/x86_64/RPMS/(網址) #匯入key如果已經修改了repo的gpgcheck=0也可以不匯入key rpm --import /RPM-GPG-KEY- #安裝elrepo的yum源 rpm -Uvh /elrepo-release-- #安裝kernel-lt(lt=long-term) yum --enablerepo=elrepo-kernelinstallkernel-lt -y 你也可以裝kernel-ml(ml=mainline) yum --enablerepo=elrepo-kernelinstallkernel-ml -y #ml(mainline)為最新版本的核心,lt為長期支援的核心。 [[email protected] ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y
檢視boot分割槽:
附加:檢視指定的核心版本:
[[email protected] ~]# yum --enablerepo=elrepo-kernel list |grep kernel* * elrepo-kernel: dracut- 004- @anaconda-CentOS-_64/ _64 - @anaconda-CentOS-_64/ kernel- - @anaconda-CentOS-_64/ kernel-_64 - @updates kernel-_64 - @elrepo-kernel abrt-addon-_64 - base dracut- 004-_ updates erlang-_64 R14B- epel _64 - updates kernel-abi- - updates kernel-_64 - updates kernel-debug- - updates kernel-debug-_64 - updates kernel-_64 - updates kernel- - updates kernel- - updates kernel-_64 - updates kernel-lt-_64 - elrepo-kernel kernel-lt- - elrepo-kernel kernel-lt- - elrepo-kernel kernel-lt-_64 - elrepo-kernel kernel-_64 - elrepo-kernel kernel-ml-_64 - elrepo-kernel kernel-ml- - elrepo-kernel kernel-ml- - elrepo-kernel kernel-ml-_64 - elrepo-kernel libreport-plugin-_64 - base _64 - elrepo-kernel php-symfony-http- - epel [[email protected] ~]#
)編輯檔案,修改Grub引導順序
[[email protected] ~]# cp /etc/ /etc/
注意:養成實時備份的習慣,技術修改有問題,也可以進去單使用者或者救援模式修復。
vim/etc/
設定default值(從0開始),一般新安裝的核心在第一個位置,所以設定default=0。
#default=1 default=0
)重啟使其生效:
[[email protected] ~]# shutdown -r now
)檢視檢測:
[[email protected] ~]# cat /etc/redhat-release CentOS release (Final) [[email protected] ~]# uname -r -_64 [[email protected] ~]#
評價:yum方式比較簡單並且快,但是如果想要自己定義其核心路徑,則顯得力不從心。
2、編譯升級核心(降級不測試)
eg:工作碰到需要修改核心配置,編譯驅動,調節相關引數等,則需要定製核心。
官網:/pub/linux/kernel/
)下載指定版本並安裝配置
[[email protected] ~]# wget --no-check-certificate /pub/linux/kernel/linux- [[email protected] ~]# du -sh linux- 95M linux- [[email protected] ~]# #yum -y install gcc ncurses-devel(依賴包) [[email protected] ~]# tar xf linux- [[email protected] ~]# ll 總用量 96336 drwxrwxr-x 23 root root 4096 2月 4 2012 linux- -rw-r--r-- 1 root root 98642809 2月 4 2012 linux- [[email protected] ~]# [[email protected] ~]# cd linux- #[[email protected] linux-]# make --help # make mrproper #清除環境變數,即清除配置檔案 # make menuconfig #在選單模式下選擇需要編譯的核心模組
make menuconfig(出現圖形)
大致意思:
箭頭鍵導航選單。<輸入>選擇子選單-
- >。高亮顯示的字母是熱鍵。按< Y >包括< N >│
│排除,< M >模組化特性。按退出< Esc > < Esc >,< ?>,< / >搜尋。傳說:[*]內建[]排除│
│< M > < >模組能力
make clean #確保所有東西均保持最新狀態. make bzImage #生成核心檔案 make modules #編譯模組 make modules_install #安裝模組 make install #安裝 #make all #make modules_install #安裝模組 #make install
)編輯檔案,修改Grub引導順序
vim/etc/
設定default值(從0開始),一般新安裝的核心在第一個位置,所以設定default=0。
#default=1 default=0
)重啟使其生效:
[[email protected] ~]# shutdown -r now
)檢視檢測:
[[email protected] ~]# cat /etc/redhat-release CentOS release (Final) [[email protected] ~]# uname -r [[email protected] ~]#
評價:慢!而且需要一定經驗,最好配置前檢視官方手冊。
3、yum方式降級核心版本
dracut- 004- @anaconda-CentOS-_64/ _64 - @anaconda-CentOS-_64/ kernel- - @anaconda-CentOS-_64/ kernel-_64 - @updates kernel-_64 - @elrepo-kernel abrt-addon-_64 - base dracut- 004-_ updates erlang-_64 R14B- epel _64 - updates kernel-abi- - updates kernel-_64 - updates kernel-debug- - updates kernel-debug-_64 - updates kernel-_64 - updates kernel- - updates kernel- - updates kernel-_64 - updates kernel-lt-_64 - elrepo-kernel kernel-lt- - elrepo-kernel kernel-lt- - elrepo-kernel kernel-lt-_64 - elrepo-kernel kernel-_64 - elrepo-kernel kernel-ml-_64 - elrepo-kernel kernel-ml- - elrepo-kernel kernel-ml- - elrepo-kernel kernel-ml-_64 - elrepo-kernel libreport-plugin-_64 - base _64 - elrepo-kernel php-symfony-http- - epel [[email protected] ~]#
eg:降級到指定版本(需要yum源支援指定版本的核心)
#yum install kernel--
)檢視
)截止目前有四個不同版本核心:
[[email protected] ~]# ll /boot/ 總用量 94418 -rw-r--r--. 1 root root 106308 10月 15 2014 config--_64 -rw-r--r-- 1 root root 108108 11月 19 03:30 config--_64 -rw-r--r-- 1 root root 142778 10月 21 22:56 config--_64 drwxr-xr-x. 3 root root 1024 2月 23 2016 efi drwxr-xr-x. 2 root root 1024 12月 14 13:55 grub -rw-------. 1 root root 16139633 2月 23 2016 initramfs--_ -rw------- 1 root root 21406778 12月 14 13:55 initramfs--_ -rw------- 1 root root 17744666 3月 25 2016 initramfs--_ -rw------- 1 root root 6086742 12月 14 13:05 initramfs- drwx------. 2 root root 12288 2月 23 2016 lost+found -rw-r--r--. 1 root root 200191 10月 15 2014 symvers--_ -rw-r--r-- 1 root root 215530 11月 19 03:30 symvers--_ -rw-r--r-- 1 root root 258396 10月 21 22:57 symvers--_ lrwxrwxrwx 1 root root 22 12月 14 13:04 -> /boot/- -rw-r--r--. 1 root root 2544748 10月 15 2014 --_64 -rw-r--r-- 1 root root 2618532 11月 19 03:30 --_64 -rw------- 1 root root 2928610 10月 21 22:56 --_64 -rw-r--r-- 1 root root 2407430 12月 14 13:04 - -rw-r--r-- 1 root root 2407430 12月 14 13:02 - lrwxrwxrwx 1 root root 19 12月 14 13:04 vmlinuz -> /boot/vmlinuz- -rwxr-xr-x. 1 root root 4152336 10月 15 2014 vmlinuz--_64 -rwxr-xr-x 1 root root 4269936 11月 19 03:30 vmlinuz--_64 -rwxr-xr-x 1 root root 4865424 10月 21 22:56 vmlinuz--_64 -rw-r--r-- 1 root root 4023040 12月 14 13:04 vmlinuz- -rw-r--r-- 1 root root 4023040 12月 14 13:02 vmlinuz- [[email protected] ~]# default=0 #default行,是指grub啟動時預設選單項。0表示第一項,如果是多系統可以修改此選項改變預設游標停留位置。 timeout=5 splashimage=(hd0,0)/grub/ hiddenmenu title CentOS (-_64) root (hd0,0) kernel /vmlinuz--_64 ro root=/dev/mapper/vg_node4-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_node4/lv_swap crashke rnel=auto LANG=zh_-8 rd_LVM_LV=vg_node4/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs--_ title CentOS () root (hd0,0) kernel /vmlinuz- ro root=/dev/mapper/vg_node4-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_node4/lv_swap crashkernel=auto LANG=zh_CN. UTF-8 rd_LVM_LV=vg_node4/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs- title CentOS (-_64) root (hd0,0) kernel /vmlinuz--_64 ro root=/dev/mapper/vg_node4-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_node4/lv_swap crash kernel=auto LANG=zh_-8 rd_LVM_LV=vg_node4/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs--_ title CentOS 6 (-_64) root (hd0,0)
)重啟使其生效:
[[email protected] ~]# shutdown -r now
[[email protected] ~]# cat /etc/redhat-release CentOS release (Final) [[email protected] ~]# uname -r -_64 [[email protected] ~]#
4、總結:
1、核心的升級和降級要有完整的流程,不可直接操作,注意升級或者降級中檔案的備份
2、yum和編譯升級和降級要根據環境具體而定,yum方便,編譯定製麻煩。
3、centos6和centos7是有區別的,比如grub的引導檔案,centos7(/boot/grub2)
如有不妥,可聯絡博主,歡迎指正!