CentOS_7升級系統內核


最近,在虛擬機中安裝docker成功之后,嘗試運行docker run hello-world時出現以下錯誤:

1 $ sudo docker run hello-world
2 Unable to find image 'hello-world:latest' locally
3 latest: Pulling from library/hello-world
4 1b930d010525: Pull complete 
5 Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
6 Status: Downloaded newer image for hello-world:latest
7 docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:293: copying bootstrap data to pipe caused \"write init-p: broken pipe\"": unknown.

查資料得知,這是CentOS內核系統與docker版本不匹配所導致的問題,下面介紹一下如何升級系統內核。

升級系統版本
首先,查看當前系統版本

1 $ uname -r
2 3.10.0-229.el7.x86_64

然后進行升級

 1 $ yum update
 2 # 之后重啟虛擬機
 3 $ reboot
 4 # 查看系統內核
 5 $ uname -r
 6 3.10.0-229.el7.x86_64
 7 # 內核並未升級,升級的其實是系統版本
 8 # 因為 CentOS 為了安全和穩定並不會把系統內核升級到最新的版本,所以 yum update 命令只會升級系統版本和更新軟件
 9 $ cat /etc/redhat-release
10 CentOS Linux release 7.6.1810 (Core) 

升級內核版本
升級內核

$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
$ rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

上述命令為啟用elrepo倉庫,我們可以使用以下命令列出可用的系統內核相關包:

1 $ yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

 

之后,就可以安裝最新的穩定內核:

1 $ yum --enablerepo=elrepo-kernel install kernel-ml

重啟機器,並選擇最新安裝的內核(第一個)

進入系統之后,查看內核版本uname -r

設置GRUB默認的內核版本
啟動系統時,系統默認選擇之前的版本,所以我們需要設置一下GRUB

1 $ vi /etc/default/grub
2 
3 GRUB_TIMEOUT=5
4 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
5 GRUB_DEFAULT=0
6 GRUB_DISABLE_SUBMENU=true
7 GRUB_TERMINAL_OUTPUT="console"
8 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
9 GRUB_DISABLE_RECOVERY="true"

重新創建內核配置

1 $ grub2-mkconfig -o /boot/grub2/grub.cfg
2 Generating grub configuration file ...
3 Found linux image: /boot/vmlinuz-5.0.0-2.el7.elrepo.x86_64
4 Found initrd image: /boot/initramfs-5.0.0-2.el7.elrepo.x86_64.img
5 Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
6 Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
7 Found linux image: /boot/vmlinuz-0-rescue-16053a12b3234d688858493442d3b11e
8 Found initrd image: /boot/initramfs-0-rescue-16053a12b3234d688858493442d3b11e.img
9 done

重啟,不進行選擇內核操作,驗證更新后的內核為默認內核

1 $ uname -r
2 5.0.0-2.el7.elrepo.x86_64

 


刪除舊版本內核(可選)
查看當前全部內核

1 $ rpm -qa | grep kernel
2 kernel-tools-3.10.0-957.el7.x86_64
3 kernel-ml-5.0.0-2.el7.elrepo.x86_64
4 kernel-tools-libs-3.10.0-957.el7.x86_64
5 kernel-3.10.0-957.el7.x86_64

使用yum remove刪除舊版本內核

1 yum remove kernel-tools-3.10.0-957.el7.x86_64 kernel-tools-libs-3.10.0-957.el7.x86_64 kernel-3.10.0-957.el7.x86_64


重啟之后,發現沒有其他內核可以選擇。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM