1 - 查看内核版本
查看 debian 核心版本信息
查看当前 debian 内核的版本:
$ uname -r
6.1.0-31-amd64
$ uname -v
#1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
$ uname -a
Linux debian12 6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07) x86_64 GNU/Linux
这说明安装时的内核版本为 6.1.0-31-amd64,当前已经更新到 6.1.0-31-amd64 版本(debian 12.9,更新时间 2025-02-07)。
其他方式:
$ cat /proc/version
Linux version 6.1.0-31-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
dmesg 命令:
$ sudo dmesg | grep Linux
[ 0.000000] Linux version 6.1.0-31-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
......
dpkg 命令:
$ dpkg --list | grep linux-image
ii linux-image-6.1.0-31-amd64 6.1.128-1 amd64 Linux 6.1 for 64-bit PCs (signed)
ii linux-image-amd64 6.1.128-1 amd64 Linux for 64-bit PCs (meta-package)
$ dpkg --list | grep -Ei 'linux-image|linux-headers|linux-modules'
ii linux-image-6.1.0-31-amd64 6.1.128-1 amd64 Linux 6.1 for 64-bit PCs (signed)
ii linux-image-amd64 6.1.128-1 amd64 Linux for 64-bit PCs (meta-package)
2 - 更新内核
更新 debian 核心
可以单独更新 linux 内核:
$ sudo apt update
$ sudo apt install linux-image-amd64
也可以使用 apt upgrade
更新所有内容:
$ sudo apt update
$ sudo apt upgrade
3 - 删除内核
删除不再需要的 debian 核心
多次升级之后,系统内就会累计有多个内核版本,可以考虑删除旧的不用的内核。
参考:
https://askubuntu.com/questions/1253347/how-to-easily-remove-old-kernels-in-ubuntu-20-04-lts
vi remove_old_kernels.sh
新建一个文件内容如下:
#!/bin/bash
# Run this script without any param for a dry run
# Run the script with root and with exec param for removing old kernels after checking
# the list printed in the dry run
uname -a
IN_USE=$(uname -a | awk '{ print $3 }')
if [[ $IN_USE == *-generic ]]
then
IN_USE=${IN_USE::-8}
fi
echo "Your in use kernel is $IN_USE"
OLD_KERNELS=$(
dpkg --list |
grep -v "$IN_USE" |
grep -v "linux-headers-generic" |
grep -v "linux-image-generic" |
grep -Ei 'linux-image|linux-headers|linux-modules' |
awk '{ print $2 }'
)
echo "Old Kernels to be removed:"
echo "$OLD_KERNELS"
if [ "$1" == "exec" ]; then
for PACKAGE in $OLD_KERNELS; do
yes | apt purge "$PACKAGE"
done
fi
执行
bash ./remove_old_kernels.sh
看查看到要删除的内核版本和相关的包,确认没有问题之后再通过
sudo bash ./remove_old_kernels.sh exec
进行实际删除。
之后重启,再检查现有的内核是否符合预期。