目录

1、查看当前系统已安装的内核镜像

2、查询指定版本的linux镜像包

3、安装指定版本内核的linux系统头文件及镜像

4、查看当前系统中内核的启动顺序

5、修改内核启动顺序

6、生效grub配置

6、移除不用的内核

7、关闭内核或包的自动更新


本文以ubuntu 18.04.4系统为例,内核版本为4.15.0-101-generic,降级到内核版本为4.15.0-76-generic。

注:想通过编译内核源码升级内核版本可以参考这篇文章

当前系统版本信息:

root@zyg:~# uname -r
4.15.0-101-generic
root@zyg:~#
root@zyg:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

1、查看当前系统已安装的内核镜像

root@zyg:~# dpkg --get-selections |grep linux-image
linux-image-4.15.0-101-generic                  install
linux-image-generic                             install

2、查询指定版本的linux镜像包

这里以4.15.0-76版本内核为例:

root@zyg:~# apt-cache search linux| grep 4.15.0-76
linux-buildinfo-4.15.0-76-generic - Linux kernel buildinfo for version 4.15.0 on 64 bit x86 SMP
linux-buildinfo-4.15.0-76-lowlatency - Linux kernel buildinfo for version 4.15.0 on 64 bit x86 SMP
linux-cloud-tools-4.15.0-76 - Linux kernel version specific cloud tools for version 4.15.0-76
linux-cloud-tools-4.15.0-76-generic - Linux kernel version specific cloud tools for version 4.15.0-76
linux-cloud-tools-4.15.0-76-lowlatency - Linux kernel version specific cloud tools for version 4.15.0-76
linux-headers-4.15.0-76 - Header files related to Linux kernel version 4.15.0
linux-headers-4.15.0-76-generic - Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
linux-headers-4.15.0-76-lowlatency - Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
linux-image-4.15.0-76-generic - Signed kernel image generic
linux-image-4.15.0-76-lowlatency - Signed kernel image lowlatency
linux-image-unsigned-4.15.0-76-generic - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-image-unsigned-4.15.0-76-lowlatency - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-modules-4.15.0-76-generic - Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
linux-modules-4.15.0-76-lowlatency - Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
linux-modules-extra-4.15.0-76-generic - Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
linux-tools-4.15.0-76 - Linux kernel version specific tools for version 4.15.0-76
linux-tools-4.15.0-76-generic - Linux kernel version specific tools for version 4.15.0-76
linux-tools-4.15.0-76-lowlatency - Linux kernel version specific tools for version 4.15.0-76
linux-modules-nvidia-390-4.15.0-76-generic - Linux kernel nvidia modules for version 4.15.0-76
linux-modules-nvidia-390-4.15.0-76-lowlatency - Linux kernel nvidia modules for version 4.15.0-76

注意:

①、如果查询不到,可以在/etc/apt/sources.list配置中,加入源:deb http://security.ubuntu.com/ubuntu trusty-security main

②、也可以在Index of /~kernel-ppa/mainline网站中找到所需的deb包。

3、安装指定版本内核的linux系统头文件及镜像

安装上面apt-cache search查旬到的包即可:

root@zyg:~# apt-get install linux-headers-4.15.0-76-generic linux-image-4.15.0-76-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:linux-headers-4.15.0-76 linux-modules-4.15.0-76-generic
Suggested packages:fdutils linux-doc-4.15.0 | linux-source-4.15.0 linux-tools
The following NEW packages will be installed:linux-headers-4.15.0-76 linux-headers-4.15.0-76-generic linux-image-4.15.0-76-generic linux-modules-4.15.0-76-generic
0 upgraded, 4 newly installed, 0 to remove and 45 not upgraded.
Need to get 33.1 MB of archives.
After this operation, 163 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-headers-4.15.0-76 all 4.15.0-76.86 [10.9 MB]
Get:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-headers-4.15.0-76 all 4.15.0-76.86 [10.9 MB]
Get:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-headers-4.15.0-76-generic amd64 4.15.0-76.86 [1106 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-modules-4.15.0-76-generic amd64 4.15.0-76.86 [13.0 MB]
Get:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-image-4.15.0-76-generic amd64 4.15.0-76.86 [7993 kB]
Fetched 29.1 MB in 8min 56s (54.2 kB/s)
Selecting previously unselected package linux-headers-4.15.0-76.
(Reading database ... 71160 files and directories currently installed.)
Preparing to unpack .../linux-headers-4.15.0-76_4.15.0-76.86_all.deb ...
Unpacking linux-headers-4.15.0-76 (4.15.0-76.86) ...
Selecting previously unselected package linux-headers-4.15.0-76-generic.
Preparing to unpack .../linux-headers-4.15.0-76-generic_4.15.0-76.86_amd64.deb ...
Unpacking linux-headers-4.15.0-76-generic (4.15.0-76.86) ...
Selecting previously unselected package linux-modules-4.15.0-76-generic.
Preparing to unpack .../linux-modules-4.15.0-76-generic_4.15.0-76.86_amd64.deb ...
Unpacking linux-modules-4.15.0-76-generic (4.15.0-76.86) ...
Selecting previously unselected package linux-image-4.15.0-76-generic.
Preparing to unpack .../linux-image-4.15.0-76-generic_4.15.0-76.86_amd64.deb ...
Unpacking linux-image-4.15.0-76-generic (4.15.0-76.86) ...
Setting up linux-modules-4.15.0-76-generic (4.15.0-76.86) ...
Setting up linux-image-4.15.0-76-generic (4.15.0-76.86) ...
I: /vmlinuz is now a symlink to boot/vmlinuz-4.15.0-76-generic
I: /initrd.img is now a symlink to boot/initrd.img-4.15.0-76-generic
Setting up linux-headers-4.15.0-76 (4.15.0-76.86) ...
Setting up linux-headers-4.15.0-76-generic (4.15.0-76.86) ...
Processing triggers for linux-image-4.15.0-76-generic (4.15.0-76.86) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-76-generic
/etc/kernel/postinst.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.15.0-101-generic
Replacing config file /run/grub/menu.lst with new version
Found kernel: /boot/vmlinuz-4.15.0-101-generic
Found kernel: /boot/vmlinuz-4.15.0-76-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-101-generic
Found initrd image: /boot/initrd.img-4.15.0-101-generic
Found linux image: /boot/vmlinuz-4.15.0-76-generic
Found initrd image: /boot/initrd.img-4.15.0-76-generic
done

4、查看当前系统中内核的启动顺序

root@zyg:~# grep menuentry /boot/grub/grub.cfg
if [ x"${feature_menuentry_id}" = xy ]; thenmenuentry_id_option="--id"menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-b753ddfd-2731-4c32-aa02-9a654abc99c6' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-b753ddfd-2731-4c32-aa02-9a654abc99c6' {menuentry 'Ubuntu, with Linux 4.15.0-101-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-advanced-b753ddfd-2731-4c32-aa02-9a654abc99c6' {menuentry 'Ubuntu, with Linux 4.15.0-101-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-recovery-b753ddfd-2731-4c32-aa02-9a654abc99c6' {menuentry 'Ubuntu, with Linux 4.15.0-76-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-76-generic-advanced-b753ddfd-2731-4c32-aa02-9a654abc99c6' {menuentry 'Ubuntu, with Linux 4.15.0-76-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-76-generic-recovery-b753ddfd-2731-4c32-aa02-9a654abc99c6' {

5、修改内核启动顺序

如果你升级的版本比当前内核版本高的话,默认新安装的内核就是第一顺序启动的,只需重启系统就行了,否则,则需要修改配置文件,具体如下:

root@zyg:~# vi /etc/default/grub

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="debian-installer/custom-installation=/custom find_preseed=/preseed.cfg auto preseed/file=/floppy/preseed.cfg automatic-ubiquity noprompt priority=critical locale=en_US console-setup/modelcode=evdev"
GRUB_CMDLINE_LINUX=""# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

将GRUB_DEFAULT=0修改为GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.15.0-76-generic",保存退出。

注:ubuntu 的旧版本(好像是16.04之前),GRUB_DEFAULT是修改成对应序号即可,16.04之后则是要修改成:Advanced options for Ubuntu>Ubuntu, with Linux x.x.x-x-generic的形式(前面grep menuentry /boot/grub/grub.cfg获取到的submenu那行)。

6、生效grub配置

若上面修改了配置文件,则需执行update-grub命令,更新grub配置:

root@zyg:~# update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-101-generic
Found initrd image: /boot/initrd.img-4.15.0-101-generic
Found linux image: /boot/vmlinuz-4.15.0-76-generic
Found initrd image: /boot/initrd.img-4.15.0-76-generic
done

之后,reboot,验证是否生效。

可以看到,内核已经是4.15.0-76-generic的了。

6、移除不用的内核

查询不包括当前内核版本的其它所有内核版本:
dpkg -l | tail -n +6| grep -E 'linux-image-[0-9]+'| grep -Fv $(uname -r)

root@zyg:~# dpkg -l | tail -n +6| grep -E 'linux-image-[0-9]+'| grep -Fv $(uname -r)
ii  linux-image-4.15.0-101-generic         4.15.0-101.102                                  amd64        Signed kernel image generic

输出的内容中可能会包括内核映像的如下三种状态:
rc:表示已经被移除
ii:表示符合移除条件(可移除)
iU:已进入 apt 安装队列,但还未被安装(不可移除)。

我这里的4.15.0-101.102 内核为可移除状态,可以执行如下命令删除:

dpkg --purge linux-image-4.4.0-21-generic

7、关闭内核或包的自动更新

①、修改系统配置,在/etc/apt/apt.conf.d目录下
10periodic、20auto-upgrades配置中1改为0即可。

②、使用apt-mark的hold参数来禁止包更新
apt-mark hold linux-image-x.xx.x-xx-generic
apt-mark hold linux-image-extra-x.xx.x-xx-generic

解除上面设置执行,带unhold的参数即可:
sudo apt-mark unhold linux-image-x.xx.x-xx-generic
sudo apt-mark unhold linux-image-extra-x.xx.x-xx-generic

本文完。

欢迎大家关注我的微信公众号大胖聊编程,可以通过公众号联系到我,也可以加好友一起交流学习。

Ubuntu Linux内核版本升级或降级到指定版本(基于ubuntu 18.04示例)相关推荐

  1. 将Ubuntu Linux内核版本升级或降级到指定版本

    本文以ubuntu 18.4.1为例,内核版本为4.15.0-153-generic,降级到内核版本为4.15.0-122-generic. 1.查看当前系统版本信息 root @ubuntu18X4 ...

  2. (zz)编译Ubuntu Linux内核

    准备 先确认有基本的编译环境,否则执行: $ sudo apt-get install build-essential 注:此命令将会安装 glibc.glibc++等等相关的库及头文件. 环境说明 ...

  3. 升级 Ubuntu Linux 内核的几种不同方法 | Linux 中国

    转载自:升级 Ubuntu Linux 内核的几种不同方法 | Linux 中国 升级 Ubuntu Linux 内核的几种不同方法 | Linux 中国 译者/Ping Yang  Linux  2 ...

  4. ubuntu(Linux) 挂接小鹤音形 (基于IBus框架)

    ubuntu(Linux) 挂接小鹤音形 (基于IBus框架) (Fcitx框架可以查看我的其他博客)https://blog.csdn.net/weixin_41115751/article/det ...

  5. Linux内核由32位升到64,将Ubuntu从32位版本升级到64位版本

    问题描述 有没有办法将我的32位版本的Ubuntu升级到64位版本?我使用Ubuntu 9.10. 如果没有简单的方法,如果我仅将home和/etc目录复制到新的安装中,该怎么办? 最佳答案 不幸的是 ...

  6. Linux内核升级(降级)

    Linux升级内核的正确姿势 很多童鞋在玩耍linux发行版的时候,都会遇到各种各样的问题,比如:网卡不能使用,亮度不能调节,触摸板不能识别,蓝牙不能使用等等,这些关系都和linux的内核有关系. 查 ...

  7. ubuntu linux内核版本>5.15安装usb无线网卡驱动

    真没想到ubuntu 22.04上安装无线网卡驱动这么曲折! 系统:ubuntu 22.04 我的网卡芯片为:RTL8812AU 遇到的问题: 内核版本与大多现有驱动不兼容 比如我买的绿联网卡,芯片为 ...

  8. centos+7.2+linux版本,在Linux Centos 7.2 上安装指定版本Docker。

    相关资料链接: 先清空下"历史" yum remove docker \ docker-common \ docker-selinux \ docker-engine 安装必要的包 ...

  9. linux 内核 LINUX_VERSION_CODE 和 KERNEL_VERSION 宏定义 版本信息

    由于Linux版本的在不断更新,当设备驱动去兼容不同版本的内核时,需要知道当前使用的内核源码版本,以此来调用对应版本的内核API,这两个宏定义在文件 /usr/include/linux/versio ...

最新文章

  1. 人工智能学习框架TensorFlow必须掌握和了解的数学基础
  2. systypes的详解
  3. CSP认证201512-2 消除类游戏[C++题解]:模拟
  4. 【链表】链表变化时其中的节点变化情况
  5. python库(包)查找网站
  6. 构建LAMP平台(一)(软件版本:httpd-2.4.16,php-5.6.12,mysql-5.6.26)
  7. abap git - commnication failure错误消息的分析和定位
  8. 高帮足球鞋_高帮运动鞋和晕车症可以教给我们有关VR设计的知识
  9. LeetCode刷题——279. 完全平方数
  10. 功夫小子实践开发-英雄实体类的基本分析和实现
  11. 计算机组成原理课程设计
  12. [计算机系统-01] 计算机系统漫游
  13. TIBCO.Rendezvous简单的发消息的过程
  14. google aviator:Java逻辑公式引擎
  15. java 求两个list 集合的交集,重复的元素
  16. Allegro_理解通孔焊盘
  17. vba调用python代码_Python替代Excel Vba系列(终):vba中调用Python
  18. 关于Windows命令提示符中的 xxx > nul 2 > nul
  19. Laradock Mac下的环境配置和安装
  20. 2008年度十大科技突破

热门文章

  1. ArcGIS二次开发软件安装
  2. wpa或者wpa2暴力破解WiFi(因为wep已经很少有人使用了,所以略过)
  3. hibernate基础sessionFactory
  4. 助力战“疫”,主“力”生产:伊利的战“疫”平衡术
  5. 计算机网络作业评价,计算机网络作业-20210412094502.docx-原创力文档
  6. 生活就是诗和远方,能走多远走多远。
  7. 人到中年:三忘,三不忘
  8. 2023年【劳务员-岗位技能(劳务员)】找解析及劳务员-岗位技能(劳务员)考试技巧
  9. WPF DevExpress 主题包无法在别的电脑使用问题
  10. 其实我是一个文艺范的程序员