注意:對於可以用好幾條命令實現的,第一條命令已經驗證,其他的命令參考自網上,沒有進行驗證。
查看Linux系統內核的命令有下面幾條
dpkg --get-selections | grep linux-image
dpkg --get-selections | grep linxu-headers
dpkg --list | grep linux-image
dpkg --list | grep linux-headers
ls /boot/
linux內核鏡像包含的包
- linux-image : 內核鏡像
- linux-image-extra : 額外的內核模塊
- linux-headers : 內核文件
刪除內核的命令有下面幾條
以刪除 linux-image-3.19.0-15這個內核為例子
sudo apt purge linux-image-3.19.0-15
sudo apt purge linux-headers-3.19.0-15
sudo apt remove linux-image-3.19.0-15
sudo apt remove linux-extra-3.19.0-15
sudo dpkg --purge linux-image-3.19.0-15
通過shell表達式一次刪除多個內核
對於系統中安裝了多個沒用的內核,一個一個刪比較麻煩,可以采用shell表達式來一次刪除多個內核
sudo apt purge linux-image-3.19.0-{18,20,21}
sudo apt purge linux-image-3.19.0-{18.20,21}
這樣一下就刪除了三個內核
禁止更新內核的命令有下面幾條
sudo apt-mark hold linux-image-3.19.10-18
sudo apt-mark hold linux-image-extra-3.19.10-18-generic
echo "linux-image-3.19.10-18-generic hold" | dpkg --set-selections
恢復原來的設定(即回到原先內核可以更新的狀態)
sudo apt-mark unhold linux-image-3.19.0-15
sudo apt-mark unhold linux-image-3.19.0-15-generic
內核卸載完后,更新一下grub
sudo update-grub
結語:設置為hold狀態的軟件包,對於 apt upgrade 命令不會升級,但是依然可以通過 apt install 命令將其升級並將其狀態切換到install。因此,從安全性角度看,這樣做其實效果不大,僅僅是避免了偶然的操作失誤。本人還是推薦使用 apt install 來進行“定點升級”。
參考博客:
https://blog.csdn.net/w383117613/article/details/78535923
https://blog.csdn.net/weixin_40522162/article/details/80302735
https://www.centos.bz/2017/07/apt-upgrade-ubuntu-system-kernel/