29

Originally posted to AskUbuntu.com ...

AskUbuntu has adopted a policy of closing questions about EOL (End Of Life) versions. There's a vocal contingent to remove them as well. To prevent possible loss of this popular question (342335 views to date), am placing a revised version here. --- docsalvager

The "classic" system...

  • Puppy Linux 5.2.8 (Lucid) based on Ubuntu 10.04 (Lucid Lynx)
  • GRUB 2 boot loader

GRUB 2 puts a number of *.mod files (kernel modules) in /boot/grub. Deleting these files (thinking they were misplaced sound files) resulted in failure on reboot and the prompt grub rescue>.

How to recover in this situation?

3
  • 1
    Seems like a dumb question.. obviously you either restore the deleted files from backup, or reinstall grub ( and there are plenty of questions about how to do that already )
    – psusi
    Dec 28, 2014 at 2:08
  • It would seem to me that booting into rescue mode off the DVD and reinstalling grub from there would probably be ideal. It's probably a lot more straightforward for most people since the mentioned data loss should be restricted to the files in the package.
    – Bratchley
    Dec 30, 2014 at 2:24
  • Not to say that I don't think fishing the specific files out of the initrd isn't clever. I Just think it's likely to confuse people as it is to help. Booting into rescue/recovery mode is a more common procedure.
    – Bratchley
    Dec 30, 2014 at 2:25

2 Answers 2

48

This answer is for others out there that DocSalvager's answer doesn't work for.

  1. I followed DocSalvager's use of ls to find the correct hard drive partition. In my case it was (hd0,msdos5).
  2. Then I executed the following commands to get back to the normal grub boot loader screen.

    grub rescue>  set boot=(hd0,msdos5)
    grub rescue>  set prefix=(hd0,msdos5)/boot/grub
    grub rescue>  insmod normal  
    grub rescue>  normal  
    
  3. After booting into Ubuntu I repaired the grub boot loader with the following commands from the terminal.

    sudo grub-install /dev/sda 
    

Please reference this source for a visual walk through of this process.

8
  • 2
    Perfect - exactly the help I needed to boot! I also ran sudo update-grub before grub-install, because my partition layout had changed.
    – mwfearnley
    Aug 14, 2016 at 14:44
  • 1
    After doing all these steps, I can log into system normally but I shut down and reboot and got "ELF sections outside core" error.
    – zack
    Jul 19, 2018 at 3:47
  • 1
    note that the prefix will depend on the disk layout - e.g. a modern system with a seperate /boot may have something like set prefix=(hd0,msdos5)/grub2
    – Wilf
    Aug 15, 2018 at 1:52
  • 1
    the command listed under point 3. worked for me but I also had to execute the command sudo update-grub2 right after the sudo grub-install /dev/sda2 That's all I did to fix the problem.
    – user25406
    Oct 4, 2020 at 13:36
  • 1
    Perhaps, it's worth to mention that (hd0,msdos5) is the same as (hd0,5). Related: web.mit.edu/rhel-doc/3/rhel-rg-en-3/s1-grub-terminology.html
    – Faither
    Aug 23, 2021 at 11:07
34

Recovering from a grub rescue crash ...

  • grub rescue> does not support cd, cp or any other filesystem commands except its own variation of ls which is really a kind of find command.
  • So first, had to find the partition with the /boot directory containing the vmlinuz and other boot image files...

    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 
    
    • ls without arguments returns the four partitions on this system.
    • ls (hd0,4)/boot does not find a /boot directory on partition (hd0,4).
    • ls (hd0,3)/boot does not find a /boot directory on partition (hd0,3).
    • ls (hd0,2)/boot finds a /boot directory on partition (hd0,2) and it contains a vmlinuz and other boot image files we want.
  • To manually boot from the grub rescue> prompt ...

    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  
    
    • Set root to use the /boot directory on partition (hd0,2).
    • Load grub module linux.
    • Set that module to use the kernel image vmlinuz-2.6.32-33-generic.
    • Set initrd(init RAM disk) to use the image initrd.img-2.6.32-33-generic.
    • Boot Linux.
  • This boots to a BusyBox commandline prompt which has all the basic filesystem commands (and then some!).

  • Then could move the *.mod files back to the /boot/grub directory ...

    busybox>  cd /boot  
    busybox>  mv mod/* grub
    busybox>  reboot
    
  • Successful Reboot!

See also ...

10
  • 4
    I cannot find any boot folder at the root level in the BusyBox
    – isnvi23h4
    Sep 20, 2016 at 9:51
  • 1
    The vmlinuz,... boot images you are looking for could be in the top-level root filesystem so try using just a slash. That will also show top-level directories. If the boot images are not in the top-level root, you can start trying the most promising of the directories till you find them. For example: ls (hd0,1)/, ls (hd0,2)/, ls (hd0,2)/initramfs/, etc.. Sep 21, 2016 at 5:48
  • 2
    I had to set the prefix to /boot/grub before being allowed to run insmod linux!
    – Emil
    Feb 6, 2017 at 15:32
  • 1
    Cant find any boot folder cd /boot/. When trying / it says permission denied. Jul 12, 2020 at 5:04
  • 1
    Grub does not have cd command. The (hd0,1), etc. are the way Grub addresses devices and partitions. Thus, (hd0,1) is the first partition on the first device recognized at boot up. (hd0,1)/ is the top-level directory (also called the "root directory" but that's confusing due to the directory under it named /root). (hd1,2)/boot would be the /boot directory on the second partition on the second device. Device# starts at 0, partition# starts at 1. Jul 14, 2020 at 3:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.