CentOS 安装新版内核并删除老旧内核版本

Kevin 教程 2,028 次浏览 41条评论

安装使用新版内核

添加 ELRepo 软件仓库(一个由社区维护的企业级 Linux 软件仓库),依次运行下面命令。

# 导入 ELRepo 公钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

# 安装 ELRepo(适用 CentOS 7)
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

# 安装 ELRepo(适用 CentOS 6)
rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

编辑 ELRepo 配置文件,设置只用它的内核软件包(默认包含了其它类别软件)。

vi /etc/yum.repos.d/elrepo.repo

[elrepo]下的 enabled 改为 0,[elrepo-kernel] enabled 改为 1。保存后用yum repolist all检查软件仓库启用情况。

考虑之后安装&更新内核都通过 ELRepo 获取,为避免之后运行yum update影响默认内核版本设置。建议修改Base.repo配置文件,设置不通过 CentOS 自带源更新旧版内核。

vi /etc/yum.repos.d/CentOS-Base.repo

[updates]下添加如下一行,排除 kernel 开头的软件包更新。

exclude=kernel*

之后可用yum check-update kernel*检查设置前后的变化(假设Base.repo存在内核更新)。

从 ELRepo 安装新版内核。这里有两个选择,分别是 kernel-lt 长期支持版本和 kernel-ml 最新主线版本。前者版本较低(写本文时测试版本是 4.4.179-1.el7.elrepo),因此如果用 TCP BBR 才升级内核的,只能选择 kernel-ml。

# 安装 kernel-lt 版本
yum --enablerepo=elrepo-kernel install kernel-lt

# 安装 kernel-ml 版本
yum --enablerepo=elrepo-kernel install kernel-ml

列出系统上已安装的内核版本。

awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg

设置使用指定内核版本。内核名称用上个命令查询。

grub2-set-default "CentOS Linux (4.4.179-1.el7.elrepo.x86_64) 7 (Core)"

运行grub2-mkconfig -o /boot/grub2/grub.cfg命令重新生成启动文件,reboot重启生效。

确认当前使用的内核版本。

grub2-editenv list

注:该方式查询结果需取决/etc/default/grub文件里的GRUB_DEFAULT参数是默认saved值才准确。不然就用uname -r查询。

删除旧版内核和更新相关软件包

列出已安装的内核和相关软件包。

rpm -qa kernel\* | sort -V

这里用package-cleanup命令删除内核,需要先安装yum-utils软件包。

yum -y install yum-utils

删除内核旧版本(默认从最旧的开始删),修改其中数字以设置要保留几个旧内核版本。如果只有一个旧版内核,就不用操作了,建议保留以备不时之需。

package-cleanup --oldkernels --count=1

如果要限制内核或其它软件的版本并存数,修改/etc/yum.conf配置文件里的installonly_limit参数(默认为 5,最小只能设置 2,小于 2 将引发 yum 错误)。

删除旧版内核相关的软件包。

yum remove kernel-tools-libs kernel-tools

补安装新版内核相关软件包。其中kernel-*-headers是内核头文件,供 glibc 使用。有些软件需要用到,建议安装。

# 对应 kernel-lt 版本软件包
yum --enablerepo=elrepo-kernel install kernel-lt-tools kernel-lt-headers

# 对应 kernel-ml 版本软件包
yum --enablerepo=elrepo-kernel install kernel-ml-tools kernel-ml-headers

运行grub2-mkconfig -o /boot/grub2/grub.cfg命令重新生成启动文件,reboot重启生效。

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    hydroxychloroquine covid france https://hydroxychloroquine.webbfenix.com/

  3. #3

    dapoxetine without a doctor dapoxetine generic https://salemeds24.wixsite.com/dapoxetine

  4. #4

    how does hydroxychloroquine work https://hhydroxychloroquine.com/

  5. #5

    ivermectin anti parasitic https://ivermectin.mlsmalta.com/

  6. #6

    european pharmacies online ordering https://buymeds.mlsmalta.com/

  7. #7

    european pharmacies online ordering https://medpills.bee-rich.com/

  8. #8

    vidalista pills at walmart https://vidalista40mg.mlsmalta.com/

  9. #9

    cialis vs viagra cost https://tadalafili.com/

  10. #10

    cialis low dose https://wisig.org/

  11. #11

    american made generic dapoxetine https://ddapoxetine.com/

  12. #12

    american doctors and hydroxychloroquine https://hydroxychloroquinee.com/

  13. #13

    cost of tadalafil 5 mg https://tadalafil.cleckleyfloors.com/

  14. #14

    lowest cost vidalista http://viidalista.co/

  15. #15

    cenforce and high blood pressure http://cavalrymenforromney.com/

  16. #16

    cialis half life https://cialzi.com/

  17. #17

    viagra online without prescription https://zsildenafil.com/

  18. #18

    ask a doctor free online https://medpills.bee-rich.com/

  19. #19

    ask a doctor free online https://edmeds.buszcentrum.com/

  20. #20

    https://pussy888vip.com/
    this is so nice. thank you for sharing

  21. #21

    this is so nice. thank you for sharing
    วิธีดูราคาบอล

  22. #22

    This design is steller! You definitely know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really enjoyed what you had to say, and more than that, how you presented it.
    Too cool! http://antiibioticsland.com/Erythromycin.htm

  23. #23

    viagra vs levitra vs cialis https://cialis.grassfed.us/

  24. #24

    viagra vs levitra vs cialis https://cialis.cleckleyfloors.com/

  25. #25

    Hi, yeah this paragraph is truly nice and I have learned lot of
    things from it on the topic of blogging. thanks. http://cleckleyfloors.com/viagra.pills

  26. #26

    Thanks for some other informative web site.
    Where else may I get that type of info written in such an ideal method?

    I’ve a mission that I’m simply now working on, and I’ve been at the glance out
    for such information. https://cialis360.jueriy.com/tadalafil

  27. #27

    bookmarked!!, I love your blog! https://hydroxychloroquinec.cleckleyfloors.com/

  28. #28

    I conceive this internet site contains some really excellent information for everyone :D. “A friend might well be reckoned the masterpiece of nature.” by Ralph Waldo Emerson.

    http://www.vreyrolinomit.com/

  29. #29

    40 mg tadalafil: http://tadalafilonline20.com/ tadalafil gel

  30. #30

    Ahaa, its nice conversation concerning this paragraph here at this weblog, I have read all that, so now me also commenting here. http://herreramedical.org/prednisone

  31. #31

    buy prescription drugs: https://genericwdp.com/ medications without a doctor’s prescription

  32. #32

    india pharmacy drugs: https://genericwdp.com/ best online international pharmacies india

  33. #33

    overseas pharmacies shipping to usa trusted india online pharmacies

  34. #34

    Hey! Quick question that’s entirely off topic. Do you know
    how to make your site mobile friendly? My weblog
    looks weird when browsing from my iphone4.
    I’m trying to find a theme or plugin that might be able to fix this problem.
    If you have any suggestions, please share. Cheers! http://www.deinformedvoters.org/dapoxetine-60mg

  35. #35

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  36. #36

    Whats up very nice website!! Guy .. Beautiful .. Wonderful .. I’ll bookmark your website and take the feeds additionally…I’m happy to seek out a lot of useful info here in the put up, we want work out extra techniques on this regard, thank you for sharing.

    http://www.zortilonrel.com/

  37. #37

    tadalafil vidalista 20mg price http://vidallista.com/

  38. #38

    hello!,I like your writing so much! share we communicate more about your article on AOL? I need an expert on this area to solve my problem. May be that’s you! Looking forward to see you.

    http://www.vreyrolinomit.com/

  39. #39

    Have you ever heard of second life (sl for short). It is essentially a game where you can do anything you want. Second life is literally my second life (pun intended lol). If you want to see more you can see these Second Life websites and blogs

    http://www.feedage.com/feeds/1772080/comments-for-angela-a-thomas

  40. #40

    alternative to prednisone https://bvsinfotech.com/

  41. #41

    Have you ever heard of second life (sl for short). It is basically a video game where you can do anything you want. sl is literally my second life (pun intended lol). If you would like to see more you can see these second life websites and blogs

    http://www.digitalchalkie.com/category/education/page/3/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。