在 Ubuntu 中清理旧内核可以释放磁盘空间,同时避免启动时内核列表过长。下面是安全、常用的做法,适合桌面和服务器。
uname -r
⚠️ 千万不要删除当前正在运行的内核!
dpkg --list | grep linux-image
sudo apt update
sudo apt autoremove --purge
Ubuntu 会自动:
✅ 这是官方推荐方式,最安全
ls /boot | grep vmlinuz
假设要删除 5.15.0-76-generic:
sudo apt purge linux-image-5.15.0-76-generic linux-headers-5.15.0-76-generic
sudo apt autoremove --purge
如果 /boot 满了,apt 可能失败,可这样处理:
df -h /boot
ls /boot
sudo rm -f /boot/vmlinuz-5.15.0-xx-generic
sudo rm -f /boot/initrd.img-5.15.0-xx-generic
sudo rm -f /boot/System.map-5.15.0-xx-generic
sudo rm -f /boot/config-5.15.0-xx-generic
然后修复依赖:
sudo apt -f install
sudo apt autoremove --purge
sudo update-grub
/lib/modules 或 initrd 文件sudo apt update
sudo apt autoremove --purge
sudo update-grub
如果你愿意,可以把下面信息发我,我可以帮你判断哪些内核可以删:
uname -r
dpkg --list | grep linux-image
df -h /boot