Ubuntu無法啟動、無法更新、boot 100%修復辦法
背景
今天在去開一台好久沒用的Ubuntu的時候,發現系統啟動不了,報“Kernel panic – not syncing: VFS: Unable to mount root fs on unknown-block(0,0)” 這個錯誤,出現一個的一般原因是由於boot分區滿了導致的,這個時候,可以嘗試啟動一下以前的內核版本,通過Grub的Ubuntu advance,去選一個盡可能早的版本來可用的版本來啟動。
修復方式
1.嘗試進入恢復模式,然后盡可能的騰出來一點空間
進入恢復模式后,選擇clean,dpkg,grub,fsck執行之后,重啟,看一下能不能進入,如果能進入到當前內核的版本了,那么恭喜你,可以嘗試去直接看下面的清理boot的方法
2.選擇一個Ubuntu advance中版本號最大的一個能進去的
選擇一個舊版本中最新的版本,能進入系統的進去
進入后,直接查看下boot的空間df -h
清理boot分區的方式
1.常規方式
直接卸載舊版本的內核
- uname -a 查看目前在用的內核版本
- dpkg --get-selections|grep linux-image 顯示所有的內核版本
- sudo apt remove linux-image-XXXX-generic 卸載舊內核,注意只保留最新的 兩個 版本
- sudo apt autoremove 清理無用的依賴
2.暴力方式
但是有很多人可能跟我一樣,在刪除內核時提示
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'linux-image-5.0.0-23-generic' for regex 'linux-image-5.0.0-23'
Note, selecting 'linux-image-5.0.0-23-lowlatency' for regex 'linux-image-5.0.0-23'
Package 'linux-image-5.0.0-23-lowlatency' is not installed, so not removed
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
linux-image-generic-hwe-18.04 : Depends: linux-image-5.3.0-46-generic but it is not going to be installed
linux-modules-extra-5.0.0-23-generic : Depends: linux-image-5.0.0-23-generic but it is not going to be installed or
linux-image-unsigned-5.0.0-23-generic but it is not going to be installed
linux-modules-extra-5.3.0-46-generic : Depends: linux-image-5.3.0-46-generic but it is not going to be installed or
linux-image-unsigned-5.3.0-46-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
核心就是Unmet dependencies
那問題來了,這不死循環了嘛。想刪除需要保持完整的依賴關系,但是沒有空間啊,那就導致舊的刪不掉,新的安裝不上。
只好手動刪除了,直接進入到``/boot`分區,將舊版本的image移動到一個別的分區,別刪除,移動一下。備份保留。
然后現在看boot的空間,肯定會有空間的了,然后強制安裝最新版本的內核apt-get install -f
然后,移除掉舊版本的apt-get autoremove linux-image-XXXX-generic
到這里應該就解決了
最后
建議取消掉Ubuntu的自動更新,或者將/boot
空間做大一些。因為Ubuntu是會自動更新的。
關閉自動更新:
sudo apt-mark hold linux-image-x.xx.x-xx-generic
sudo apt-mark hold linux-image-extra-x.xx.x-xx-generic