Linux内核升级失败原因找到

之前在这个贴子(Linux内核升级失败后回退)提到我升级内核遇到了问题,导致系统无法启动。后边又尝试了几次依旧同样的报错。最近又有了新的内核版本,现在跨版本升级,还是失败。研究好久才搞明白根本原因。原来是升级过几次后服务器/boot分区满了,所以当再次升级适合就遇到奇怪的报错。

Filesystem Size Used Avail Use% Mounted on
udev 445M 0 445M 0% /dev
tmpfs 98M 1.1M 97M 2% /run
/dev/sda3 20G 5.8G 13G 32% /
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda2 371M 309M 35M 91% /boot
/dev/loop1 56M 56M 0 100% /snap/core18/2751
/dev/loop2 56M 56M 0 100% /snap/core18/2785
/dev/loop3 64M 64M 0 100% /snap/core20/1891
/dev/loop0 45M 45M 0 100% /snap/certbot/3024
/dev/loop4 74M 74M 0 100% /snap/core22/750
/dev/loop6 45M 45M 0 100% /snap/certbot/2913
/dev/loop5 74M 74M 0 100% /snap/core22/766
/dev/loop7 54M 54M 0 100% /snap/snapd/19457
/dev/loop8 174M 174M 0 100% /snap/lxd/25086
/dev/loop9 171M 171M 0 100% /snap/lxd/24918
/dev/loop10 54M 54M 0 100% /snap/snapd/19361
/dev/loop11 64M 64M 0 100% /snap/core20/1950
tmpfs 98M 0 98M 0% /run/user/1000

可以看到这个服务器虽然提供20G的内存,但是/boot分区只有371M,并且用掉了91%。当再安装新的内核时候,就会由于内存满了而失败。

我们可以将除当前使用内核之外的旧内核删除掉,再进行新的内核升级。先查下现在所用的内核版本:uname -a

Linux audicdn 5.4.0-144-generic #161-Ubuntu SMP Fri Feb 3 14:49:04 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

查询系统中共安装了哪些内核:apt list *linux* –installed

Listing... Done
console-setup-linux/focal,now 1.194ubuntu3 all [installed,automatic]
libselinux1/focal,now 3.0-1build2 amd64 [installed,automatic]
linux-base/focal-updates,now 4.5ubuntu3.7 all [installed,automatic]
linux-firmware/now 1.187.36 all [installed,upgradable to: 1.187.39]
linux-headers-5.4.0-139-generic/focal-updates,focal-security,now 5.4.0-139.156 amd64 [installed,automatic]
linux-headers-5.4.0-139/focal-updates,focal-security,now 5.4.0-139.156 all [installed,automatic]
linux-image-5.4.0-139-generic/focal-updates,focal-security,now 5.4.0-139.156 amd64 [installed,automatic]
linux-image-5.4.0-144-generic/focal-updates,focal-security,now 5.4.0-144.161 amd64 [installed,automatic]
linux-modules-5.4.0-139-generic/focal-updates,focal-security,now 5.4.0-139.156 amd64 [installed,automatic]
linux-modules-5.4.0-144-generic/focal-updates,focal-security,now 5.4.0-144.161 amd64 [installed,automatic]
linux-modules-extra-5.4.0-139-generic/focal-updates,focal-security,now 5.4.0-139.156 amd64 [installed,automatic]

可看到除了144内核外,系统中还有139旧内核。现在我们将其卸载掉:

sudo apt purge linux-headers-5.4.0-139-generic linux-headers-5.4.0-139 linux-image-5.4.0-139-generic linux-modules-5.4.0-139-generic linux-modules-extra-5.4.0-139-generic

然后更新一下grub:

sudo update-grub

查看一下内存:

Filesystem Size Used Avail Use% Mounted on
udev 445M 0 445M 0% /dev
tmpfs 98M 1.1M 97M 2% /run
/dev/sda3 20G 5.4G 13G 30% /
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda2 371M 209M 135M 61% /boot
/dev/loop1 56M 56M 0 100% /snap/core18/2751
/dev/loop2 56M 56M 0 100% /snap/core18/2785
/dev/loop3 64M 64M 0 100% /snap/core20/1891
/dev/loop0 45M 45M 0 100% /snap/certbot/3024
/dev/loop4 74M 74M 0 100% /snap/core22/750
/dev/loop6 45M 45M 0 100% /snap/certbot/2913
/dev/loop5 74M 74M 0 100% /snap/core22/766
/dev/loop7 54M 54M 0 100% /snap/snapd/19457
/dev/loop8 174M 174M 0 100% /snap/lxd/25086
/dev/loop9 171M 171M 0 100% /snap/lxd/24918
/dev/loop10 54M 54M 0 100% /snap/snapd/19361
/dev/loop11 64M 64M 0 100% /snap/core20/1950
tmpfs 98M 0 98M 0% /run/user/1000

可看到boot空间腾出来了。

接下来升级就好了:

sudo apt update
sudo apt upgrage

现在不报错了,顺利完成升级。

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.