在 Debian 系统中,随着内核更新,旧内核会占用 /boot 空间,可能导致更新失败。以下是安全清理旧内核的方法。
uname -r
⚠️ 不要删除当前正在使用的内核
dpkg --list | grep linux-image
或
ls /boot/vmlinuz-*
sudo apt autoremove --purge
Debian 默认会保留当前内核和上一个内核。
sudo apt purge linux-image-旧版本
例如:
sudo apt purge linux-image-5.10.0-21-amd64
sudo rm -f /boot/vmlinuz-旧版本
sudo rm -f /boot/initrd.img-旧版本
sudo rm -f /boot/System.map-旧版本
sudo rm -f /boot/config-旧版本
然后更新 grub:
sudo update-grub
sudo apt-get -y purge $(dpkg -l | grep 'linux-image' | grep -v "$(uname -r)" | awk '{print $2}' | grep -v meta)
⚠️ 会删除除当前内核外所有内核
先手动删一个旧内核:
sudo rm -f /boot/initrd.img-旧版本
sudo apt -f install
编辑 /etc/apt/apt.conf.d/50unattended-upgrades:
Unattended-Upgrade::Remove-Unused-Dependencies "true";
如果你愿意,可以贴出:
uname -r
dpkg -l | grep linux-image
我可以帮你精确判断该删哪一个。