前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >关于如何使用包管理器APT(Advanced Package Tool)进行内核升级更换Ubuntu内核版本

关于如何使用包管理器APT(Advanced Package Tool)进行内核升级更换Ubuntu内核版本

原创
作者头像
Tadeic
修改2024-12-28 11:58:00
修改2024-12-28 11:58:00
2820
举报
文章被收录于专栏:Ubuntu内核Ubuntu内核

提示:使用包管理器APT(Advanced Package Tool)进行内核升级。进行任何系统更改之前,务必备份重要数据和配置文件,以防意外发生。

演示系统说明:目前使用的系统版本为:Ubuntu 20.04.06

应用范围:内核版本5.4.0-29至5.6.0-10等(以实际升级现有软件内核包为准)

操作步骤:

1. 更新软件包列表,确保软件包列表是最新的:

sudo apt update

2. 升级现有软件包:

sudo apt upgrade

3. 搜索可用的内核版本:

sudo apt search linux-image

4. 安装新内核:

sudo apt install linux-image-<version>

确保将<version>替换为选择的实际内核版本。

当前需要试用的版本为ubuntu20.04.06

需要的内核版本为linux-image-5.15.0-91-generic

安装如下:(image、headers、modules均需安装,否则会导致切换内核以后,识别不到网卡信息)

sudo apt install linux-image-5.15.0-91-generic

sudo apt install linux-headers-5.15.0-91-generic

sudo apt install linux-modules-5.15.0-91-generic

sudo apt install linux-modules-extra-5.15.0-91-generic

5. 更新引导加载程序:

sudo update-grub

6. 重新启动系统: 内核升级完成后,重新启动系统,以使更改生效。

sudo reboot

7. 验证新内核:

uname -r

8. 删除旧版本内核

使用命令dpkg --get-selections |grep linux查看如下:

使用命令sudo apt autoremove linux-headers-5.4.0-170

删除旧版本内核相关信息

小白操作步骤(纯小白参考):

1.先将装有Ubuntu系统的服务器设备接上网线,检测网络是否正常;

ubuntu@ubuntu:~$ ip a

2.输入ping 8.8.8.8看网络是否正常

ubuntu@ubuntu:~$ ping 8.8.8.8

3.输入uname -r检查现有的内核版本

ubuntu@ubuntu:~$ uname -r

4.输入sudo su获取管理员权限然后输入服务器密码

ubuntu@ubuntu:~$ sudo su

5.输入服务器密码:

6.输入sudo apt update更新软件包列表,确保软件包列表是最新的;

root@ubuntu:/home/ubuntu# sudo apt update

7.输入sudo apt upgrade升级现有软件内核包

root@ubuntu:/home/ubuntu# sudo apt upgrade

8.输入sudo apt search linux-image搜索可用的内核版本

root@ubuntu:/home/ubuntu# sudo apt search linux-image

示例(版本太多以下做了删减):

linux-image-unsigned-5.4.0-29-lowlatency/focal-updates,focal-security 5.4.0-29.33 amd64

Linux kernel image for version 5.4.0 on 64 bit x86 SMP

linux-modules-nvidia-455-5.6.0-1036-oem/focal-updates 5.6.0-1036.39 amd64

Linux kernel nvidia modules for version 5.6.0-1036

....

9.输入sudo apt install linux-image-<version>安装新内核,将<version>替换为选择的实际需要更换的内核版本;

例如:实际需要的内核版本为linux-image-5.15.0-91-generic则输入sudo apt install linux-image-5.15.0-91-generic 确保将<version>替换为选择的实际内核版本。

root@ubuntu:/home/ubuntu# sudo apt install linux-image-5.15.0-91-generic

示例(更换完重启系统):

root@ubuntu:/home/ubuntu# sudo apt install linux-image-5.15.0-91-generic

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following additional packages will be installed:

linux-modules-5.15.0-91-generic

Suggested packages:

fdutils linux-doc | linux-hwe-5.15-source-5.15.0 linux-hwe-5.15-tools linux-headers-5.15.0-91-generic

linux-modules-extra-5.15.0-91-generic

The following NEW packages will be installed:

linux-image-5.15.0-91-generic linux-modules-5.15.0-91-generic

0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.

Need to get 32.3 MB of archives.

After this operation, 140 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-modules-5.15.0-91-generic amd64 5.15.0-91.101~20.04.1 [21.0 MB]

Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-image-5.15.0-91-generic amd64 5.15.0-91.101~20.04.1 [11.4 MB]

Fetched 32.3 MB in 5s (6,752 kB/s)

Selecting previously unselected package linux-modules-5.15.0-91-generic.

(Reading database ... 108845 files and directories currently installed.)

Preparing to unpack .../linux-modules-5.15.0-91-generic_5.15.0-91.101~20.04.1_amd64.deb ...

Unpacking linux-modules-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Selecting previously unselected package linux-image-5.15.0-91-generic.

Preparing to unpack .../linux-image-5.15.0-91-generic_5.15.0-91.101~20.04.1_amd64.deb ...

Unpacking linux-image-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Setting up linux-modules-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Setting up linux-image-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

I: /boot/vmlinuz.old is now a symlink to vmlinuz-5.4.0-171-generic

I: /boot/initrd.img.old is now a symlink to initrd.img-5.4.0-171-generic

I: /boot/vmlinuz is now a symlink to vmlinuz-5.15.0-91-generic

I: /boot/initrd.img is now a symlink to initrd.img-5.15.0-91-generic

Processing triggers for linux-image-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

/etc/kernel/postinst.d/initramfs-tools:

update-initramfs: Generating /boot/initrd.img-5.15.0-91-generic

W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast

/etc/kernel/postinst.d/zz-update-grub:

Sourcing file `/etc/default/grub'

Sourcing file `/etc/default/grub.d/init-select.cfg'

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-5.15.0-91-generic

Found initrd image: /boot/initrd.img-5.15.0-91-generic

Found linux image: /boot/vmlinuz-5.4.0-171-generic

Found initrd image: /boot/initrd.img-5.4.0-171-generic

Found linux image: /boot/vmlinuz-5.4.0-144-generic

Found initrd image: /boot/initrd.img-5.4.0-144-generic

Adding boot menu entry for UEFI Firmware Settings

done

root@ubuntu:/home/ubuntu# sudo apt install linux-image-5.15.0-91-generic

Reading package lists... Done

Building dependency tree

Reading state information... Done

linux-image-5.15.0-91-generic is already the newest version (5.15.0-91.101~20.04.1).

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

root@ubuntu:/home/ubuntu# sudo apt install linux-headers-5.15.0-91-generic

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following additional packages will be installed:

linux-hwe-5.15-headers-5.15.0-91

The following NEW packages will be installed:

linux-headers-5.15.0-91-generic linux-hwe-5.15-headers-5.15.0-91

0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.

Need to get 14.8 MB of archives.

After this operation, 105 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-hwe-5.15-headers-5.15.0-91 all 5.15.0-91.101~20.04.1 [12.0 MB]

Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-headers-5.15.0-91-generic amd64 5.15.0-91.101~20.04.1 [2,766 kB]

Fetched 14.8 MB in 5s (2,950 kB/s)

Selecting previously unselected package linux-hwe-5.15-headers-5.15.0-91.

(Reading database ... 110162 files and directories currently installed.)

Preparing to unpack .../linux-hwe-5.15-headers-5.15.0-91_5.15.0-91.101~20.04.1_all.deb ...

Unpacking linux-hwe-5.15-headers-5.15.0-91 (5.15.0-91.101~20.04.1) ...

Selecting previously unselected package linux-headers-5.15.0-91-generic.

Preparing to unpack .../linux-headers-5.15.0-91-generic_5.15.0-91.101~20.04.1_amd64.deb ...

Unpacking linux-headers-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Setting up linux-hwe-5.15-headers-5.15.0-91 (5.15.0-91.101~20.04.1) ...

Setting up linux-headers-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

root@ubuntu:/home/ubuntu# sudo apt install linux-modules-5.15.0-91-generic

Reading package lists... Done

Building dependency tree

Reading state information... Done

linux-modules-5.15.0-91-generic is already the newest version (5.15.0-91.101~20.04.1).

linux-modules-5.15.0-91-generic set to manually installed.

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

root@ubuntu:/home/ubuntu# sudo apt install linux-modules-extra-5.15.0-91-generic

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following NEW packages will be installed:

linux-modules-extra-5.15.0-91-generic

0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

Need to get 57.9 MB of archives.

After this operation, 355 MB of additional disk space will be used.

Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-modules-extra-5.15.0-91-generic amd64 5.15.0-91.101~20.04.1 [57.9 MB]

Fetched 57.9 MB in 60s (958 kB/s)

Selecting previously unselected package linux-modules-extra-5.15.0-91-generic.

(Reading database ... 138423 files and directories currently installed.)

Preparing to unpack .../linux-modules-extra-5.15.0-91-generic_5.15.0-91.101~20.04.1_amd64.deb ...

Unpacking linux-modules-extra-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Setting up linux-modules-extra-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

Processing triggers for linux-image-5.15.0-91-generic (5.15.0-91.101~20.04.1) ...

/etc/kernel/postinst.d/initramfs-tools:

update-initramfs: Generating /boot/initrd.img-5.15.0-91-generic

W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast

/etc/kernel/postinst.d/zz-update-grub:

Sourcing file `/etc/default/grub'

Sourcing file `/etc/default/grub.d/init-select.cfg'

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-5.15.0-91-generic

Found initrd image: /boot/initrd.img-5.15.0-91-generic

Found linux image: /boot/vmlinuz-5.4.0-171-generic

Found initrd image: /boot/initrd.img-5.4.0-171-generic

Found linux image: /boot/vmlinuz-5.4.0-144-generic

Found initrd image: /boot/initrd.img-5.4.0-144-generic

Adding boot menu entry for UEFI Firmware Settings

done

root@ubuntu:/home/ubuntu# sudo update-grub

Sourcing file `/etc/default/grub'

Sourcing file `/etc/default/grub.d/init-select.cfg'

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-5.15.0-91-generic

Found initrd image: /boot/initrd.img-5.15.0-91-generic

Found linux image: /boot/vmlinuz-5.4.0-171-generic

Found initrd image: /boot/initrd.img-5.4.0-171-generic

Found linux image: /boot/vmlinuz-5.4.0-144-generic

Found initrd image: /boot/initrd.img-5.4.0-144-generic

Adding boot menu entry for UEFI Firmware Settings

done

root@ubuntu:/home/ubuntu# sudo reboot

Connection closing...Socket close.

10.安装相关驱动(image、headers、modules、modules-extra)均需安装,否则会导致切换内核以后,识别不到网卡信息。

10.1:安装 image 输入sudo apt install linux-image-5.15.0-91-generic

root@ubuntu:~$ sudo apt install linux-image-5.15.0-91-generic

10.2:安装 headers 输入sudo apt install linux-headers-5.15.0-91-generic

root@ubuntu:~$ sudo apt install linux-headers-5.15.0-91-generic

10.3:安装 modules 输入sudo apt install linux-modules-5.15.0-91-generic

root@ubuntu:/home/ubuntu# sudo apt install linux-modules-5.15.0-91-generic

10.4:安装 modules-extra 输入sudo apt install linux-modules-extra-5.15.0-91-generic

root@ubuntu:/home/ubuntu# sudo apt install linux-modules-extra-5.15.0-91-generic

11.输入sudo update-grub更新加载引导程序(内核升级后需要更新引导加载程序,以便在启动时可以选择新的内核版本)

root@ubuntu:/home/ubuntu# sudo update-grub

12. 内核升级完成后,输入sudo reboot重新启动系统,以使更改完成的内核版本生效

root@ubuntu:/home/ubuntu# sudo reboot

13.重启后输入uname -r查看更新好的内核版本,以验证新内核是否生效

ubuntu@ubuntu:~$ uname -r

示例(内核版本如下):

1| ubuntu@ubuntu:~$ uname -r

2| 5.15.0-91-generic

3| ubuntu@ubuntu:~$

14.输入命令dpkg --get-selections |grep linux来查看系统上已安装的内核包列表

ubuntu@ubuntu:~$ dpkg --get-selections |grep linux

示例(存在的内核如下):

ubuntu@ubuntu:~$ dpkg --get-selections |grep linux

console-setup-linux install

libselinux1:amd64 install

linux-base install

linux-firmware install

linux-generic install

linux-headers-5.15.0-91-generic install

linux-headers-5.4.0-144 install

linux-headers-5.4.0-144-generic install

linux-headers-5.4.0-171 install

linux-headers-5.4.0-171-generic install

linux-headers-generic install

linux-hwe-5.15-headers-5.15.0-91 install

linux-image-5.15.0-91-generic install

linux-image-5.4.0-144-generic install

linux-image-5.4.0-171-generic install

linux-image-generic install

linux-modules-5.15.0-91-generic install

linux-modules-5.4.0-144-generic install

linux-modules-5.4.0-171-generic install

linux-modules-extra-5.15.0-91-generic install

linux-modules-extra-5.4.0-144-generic install

linux-modules-extra-5.4.0-171-generic install

util-linux install

ubuntu@ubuntu:~$ sudo apt autoremove linux-headers-5.4.0-144

[sudo] password for ubuntu:

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package 'linux-headers-5.4.0-144' is not installed, so not removed

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

15.输入命令sudo apt autoremovelinux-headers-5.4.0-170删除不需要的旧版本内核相关信息

ubuntu@ubuntu:~$ sudo apt autoremove linux-headers-5.4.0-170

[sudo] password for ubuntu:

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package 'linux-headers-5.4.0-144' is not installed, so not removed

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

ubuntu@ubuntu:~$

16. 删除完成后,输入sudo reboot重新启动系统,以使更改完成的生效

ubuntu@ubuntu:~$ sudo reboot

示例:

ubuntu@ubuntu:~$ sudo reboot

#重启开机后进入以下界面完成以上全部操作

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-91-generic x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/pro

System information as of Sun 18 Feb 2024 06:10:18 AM UTC

System load: 0.68 Temperature: 41.0 C

Usage of /: 21.0% of 56.88GB Processes: 846

Memory usage: 0% Users logged in: 0

Swap usage: 0% IPv4 address for enp4s0: 10.168.3.166

* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s

just raised the bar for easy, resilient and secure K8s cluster deployment.

https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.

See https://ubuntu.com/esm or run: sudo pro status

New release '22.04.3 LTS' available.

Run 'do-release-upgrade' to upgrade to it.

Last login: Sun Feb 18 05:34:32 2024

ubuntu@ubuntu:~$

总结

这篇文章是针对想要升级更换Ubuntu Linux 20.04.6系统及其他系统版本,内核需要更换的用户的实用指南。文章的主要目标是帮助小白理解升级过程并确保其系统的稳定性和安全性。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 提示:使用包管理器APT(Advanced Package Tool)进行内核升级。进行任何系统更改之前,务必备份重要数据和配置文件,以防意外发生。
    • 演示系统说明:目前使用的系统版本为:Ubuntu 20.04.06
    • 应用范围:内核版本5.4.0-29至5.6.0-10等(以实际升级现有软件内核包为准)
  • 操作步骤:
  • 1. 更新软件包列表,确保软件包列表是最新的:
  • 2. 升级现有软件包:
  • 3. 搜索可用的内核版本:
  • 4. 安装新内核:
    • 确保将<version>替换为选择的实际内核版本。
      • 当前需要试用的版本为ubuntu20.04.06
      • 需要的内核版本为linux-image-5.15.0-91-generic
    • 安装如下:(image、headers、modules均需安装,否则会导致切换内核以后,识别不到网卡信息)
    • 5. 更新引导加载程序:
    • 6. 重新启动系统: 内核升级完成后,重新启动系统,以使更改生效。
    • 7. 验证新内核:
    • 8. 删除旧版本内核
  • 小白操作步骤(纯小白参考):
    • 1.先将装有Ubuntu系统的服务器设备接上网线,检测网络是否正常;
    • 2.输入ping 8.8.8.8看网络是否正常
    • 3.输入uname -r检查现有的内核版本
    • 4.输入sudo su获取管理员权限然后输入服务器密码
    • 5.输入服务器密码:
    • 6.输入sudo apt update更新软件包列表,确保软件包列表是最新的;
    • 7.输入sudo apt upgrade升级现有软件内核包
    • 8.输入sudo apt search linux-image搜索可用的内核版本
      • 示例(版本太多以下做了删减):
    • 9.输入sudo apt install linux-image-<version>安装新内核,将<version>替换为选择的实际需要更换的内核版本;
      • 例如:实际需要的内核版本为linux-image-5.15.0-91-generic则输入sudo apt install linux-image-5.15.0-91-generic 确保将<version>替换为选择的实际内核版本。
      • 示例(更换完重启系统):
    • 10.安装相关驱动(image、headers、modules、modules-extra)均需安装,否则会导致切换内核以后,识别不到网卡信息。
      • 10.1:安装 image 输入sudo apt install linux-image-5.15.0-91-generic
      • 10.2:安装 headers 输入sudo apt install linux-headers-5.15.0-91-generic
      • 10.3:安装 modules 输入sudo apt install linux-modules-5.15.0-91-generic
      • 10.4:安装 modules-extra 输入sudo apt install linux-modules-extra-5.15.0-91-generic
    • 11.输入sudo update-grub更新加载引导程序(内核升级后需要更新引导加载程序,以便在启动时可以选择新的内核版本)
    • 12. 内核升级完成后,输入sudo reboot重新启动系统,以使更改完成的内核版本生效
    • 13.重启后输入uname -r查看更新好的内核版本,以验证新内核是否生效
      • 示例(内核版本如下):
    • 14.输入命令dpkg --get-selections |grep linux来查看系统上已安装的内核包列表
      • 示例(存在的内核如下):
    • 15.输入命令sudo apt autoremovelinux-headers-5.4.0-170删除不需要的旧版本内核相关信息
    • 16. 删除完成后,输入sudo reboot重新启动系统,以使更改完成的生效
      • 示例:
      • 总结
      • 这篇文章是针对想要升级更换Ubuntu Linux 20.04.6系统及其他系统版本,内核需要更换的用户的实用指南。文章的主要目标是帮助小白理解升级过程并确保其系统的稳定性和安全性。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档