服务热线:0755-3317 6650

技术百科

提供技术相关问题的百科知识以及解决方法,帮您轻松学习处理使用过程中遇到的任何问题
新闻详情您现在的位置:网站首页 >新闻资讯 > 新闻详情

Ubuntu-Liunx内核升级教程

发布时间:2024-05-31

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

 

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

 

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

 

操作步骤:

 

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

 

linux-modules-nvidia-455-5.6.0-1039-oem/focal-updates,focal-security 5.6.0-1039.43 amd64

  Linux kernel nvidia modules for version 5.6.0-1039

 

linux-modules-nvidia-460-5.6.0-1042-oem/focal-updates,focal-security 5.6.0-1042.46 amd64

  Linux kernel nvidia modules for version 5.6.0-1042

 

linux-modules-nvidia-460-5.6.0-1047-oem/focal-updates,focal-security 5.6.0-1047.51 amd64

  Linux kernel nvidia modules for version 5.6.0-1047

 

linux-virtual/focal-updates,focal-security 5.4.0.171.169 amd64

  Minimal Generic Linux kernel and headers

 

linux-virtual-hwe-20.04/focal-updates,focal-security 5.15.0.94.104~20.04.50 amd64

  Minimal Generic Linux kernel and headers

 

linux-virtual-hwe-20.04-edge/focal-updates,focal-security 5.15.0.94.104~20.04.50 amd64

  Minimal Generic Linux kernel and headers

 

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

 

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

 

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.安装相关驱动(imageheadersmodulesmodules-extra)均需安装,否则会导致切换内核以后,识别不到网卡信息。

 

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

 

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

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

 

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

8.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

 8.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

示例(内核版本如下):

 

ubuntu@ubuntu:~$ uname -r

5.15.0-91-generic

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 autoremove linux-headers-5.4.0-170删除不需要的旧版本内核相关信息

 

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.

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系统及其他系统版本,内核需要更换的用户的实用指南。文章的主要目标是帮助理解升级过程并确保其系统的稳定性和安全性。

 

 声明:金超云控原创资料,转载请注明出处。


免责声明1




产品和性能信息

1

金超云控正在从当前文档、用户界面和代码中移除非包容性语言。请注意,有些更改可能不具追溯力,某些非包容性语言可能仍存留在旧的文档、用户界面和代码中。




Jcyk Corporation; Postal code 710000; 70 Jinyao Road, Sanzhong Village, Qingxi Town, Dongguan City, China

® 金超云控公司 – 法律信息 – www.godspm.com
金超云控是金超云控公司或其子公司在中国和其它国家(地区)的注册商标。
*其它名称和品牌可能是其它公司的财产。


粤公网安备44030002002429号 | 营业执照   |   诚信企业