从“grub 救援>”崩溃中恢复

Doc*_*ger 29 ubuntu boot-loader grub2 busybox

最初发布到 AskUbuntu.com ...

AskUbuntu 采用了关闭有关 EOL(生命周期结束)版本问题的策略。还有一个声音队伍来删除它们。为了防止可能丢失这个热门问题(迄今为止有 342335 次浏览),我在此处放置了一个修订版。--- 文档打捞者

“经典”系统...

  • Puppy Linux 5.2.8 (Lucid) 基于 Ubuntu 10.04 (Lucid Lynx)
  • GRUB 2引导加载程序

GRUB 2将许多*.mod文件(内核模块)放在/boot/grub. 删除这些文件(认为它们是放错位置的声音文件)导致重新启动失败并提示grub rescue>.

在这种情况下如何恢复?

小智 48

这个答案适用于 DocSalvager 的答案不适用的其他人。

  1. 我按照 DocSalvager 的使用ls来找到正确的硬盘分区。就我而言,它是(hd0,msdos5).
  2. 然后我执行了以下命令以返回正常的 grub 引导加载程序屏幕。

    grub rescue>  set boot=(hd0,msdos5)
    grub rescue>  set prefix=(hd0,msdos5)/boot/grub
    grub rescue>  insmod normal  
    grub rescue>  normal  
    
    Run Code Online (Sandbox Code Playgroud)
  3. 启动到 Ubuntu 后,我使用终端中的以下命令修复了 grub 启动加载程序。

    sudo grub-install /dev/sda 
    
    Run Code Online (Sandbox Code Playgroud)

请参考此来源以直观地了解此过程。

  • 我很高兴你们在关闭之前发布 (7认同)
  • 完美 - 正是我启动所需的帮助!我还在 `grub-install` 之前运行了 `sudo update-grub`,因为我的分区布局已经改变。 (2认同)

Doc*_*ger 34

从grub救援崩溃中恢复......

  • grub rescue>不支持cd,cp或任何其他文件系统命令,除了它自己的变体ls实际上是一种find命令。
  • 所以首先,必须找到/boot包含vmlinuz和其他启动映像文件的目录的分区......

    grub rescue>  ls  
    (hd0,4) (hd0,3) (hd0,2) (hd0,1)  
    
    grub rescue>  ls (hd0,4)/boot
    ... some kind of 'not found' message
    
    grub rescue>  ls (hd0,3)/boot
    ... some kind of 'not found' message
    
    grub rescue>  ls (hd0,2)/boot
    ... grub ... initrd.img-2.6.32-33-generic ... vmlinuz-2.6.32-33-generic 
    
    Run Code Online (Sandbox Code Playgroud)
    • ls 不带参数返回此系统上的四个分区。
    • ls (hd0,4)/boot/boot在分区上找不到目录(hd0,4)
    • ls (hd0,3)/boot/boot在分区上找不到目录(hd0,3)
    • ls (hd0,2)/boot/boot在分区上找到一个目录(hd0,2),它包含vmlinuz我们想要的一个和其他启动映像文件。
  • 要从grub rescue>提示符手动引导...

    grub rescue>  set root=(hd0,2)/boot  
    grub rescue>  insmod linux  
    grub rescue>  linux (hd0,2)/boot/vmlinuz-2.6.32-33-generic  
    grub rescue>  initrd (hd0,2)/boot/initrd.img-2.6.32-33-generic  
    grub rescue>  boot  
    
    Run Code Online (Sandbox Code Playgroud)
    • 设置root为使用/boot分区上的目录(hd0,2)
    • 加载 grub 模块linux
    • 将该模块设置为使用内核映像vmlinuz-2.6.32-33-generic
    • 设置 initrd(init RAM disk) 以使用镜像initrd.img-2.6.32-33-generic
    • 启动 Linux。
  • 这将引导至BusyBox命令行提示符,其中包含所有基本文件系统命令(还有一些!)。

  • 然后可以将*.mod文件移回/boot/grub目录...

    busybox>  cd /boot  
    busybox>  mv mod/* grub
    busybox>  reboot
    
    Run Code Online (Sandbox Code Playgroud)
  • 重启成功!

也可以看看 ...

  • 我在 BusyBox 的根级别找不到任何启动文件夹 (3认同)
  • 在允许运行 insmod linux 之前,我必须将前缀设置为 /boot/grub! (2认同)