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?

DocSalvager
  • 2,143
  • 2
  • 25
  • 38
  • 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 '14 at 02: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 '14 at 02: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 '14 at 02:25

2 Answers2

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.

c1one
  • 3
  • 1
Gibado
  • 596
  • 5
  • 4
  • 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 '16 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 '18 at 03:47
  • the `boot` (as in `set boot`) environment variable is undocumented (info, html). how do i get information on its purpose? –  Jul 24 '18 at 06:31
  • 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 '18 at 01: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 04 '20 at 13:36
  • After running this command `insmod normal` I get: `symbol \`grub_calloc\` not found.` – foba May 09 '21 at 20:06
  • 1
    Perhaps, it's worth to mention that `(hd0,msdos5)` is the same as `(hd0,5)`. Related: https://web.mit.edu/rhel-doc/3/rhel-rg-en-3/s1-grub-terminology.html – Artfaith Aug 23 '21 at 11:07
  • What if the `insmod normal` returns `error: symbol 'grub_file_filters_all' not found`? – ComputerScientist Sep 16 '21 at 16:31
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 ...

DocSalvager
  • 2,143
  • 2
  • 25
  • 38
  • 4
    I cannot find any boot folder at the root level in the BusyBox – isnvi23h4 Sep 20 '16 at 09: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.. – DocSalvager Sep 21 '16 at 05:48
  • In my case, after running `ls (hd0,7)/boot`, it shows `attempt to read or write outside of disk 'hd0'`. – d a i s y Nov 17 '16 at 05:19
  • There are less than 7 partitions on drive hd0. It may also be that there is some unallocated space on the drive that is not part of any partition. – DocSalvager Nov 17 '16 at 06:04
  • 2
    I had to set the prefix to /boot/grub before being allowed to run insmod linux! – Emil Feb 06 '17 at 15:32
  • 1
    Cant find any boot folder cd /boot/. When trying / it says permission denied. – Faiz Hameed Jul 12 '20 at 05: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. – DocSalvager Jul 14 '20 at 03:09
  • Can't cd to boot. Using ls I find dev, etc, conf, lib, scripts, proc, root, var, run, bin, usr, tmp, kernel, lib64, sbin, init, sys folders only. – Noob Geek Nov 01 '20 at 18:58
  • 1
    You have to go through all the steps in the bullet list with the `boot` command item running successfully before you get to a Busybox commandline. It is Busybox that has a `cd` command. – DocSalvager Nov 03 '20 at 16:06
  • `insmod linux` results in error: `symbol 'grub_file_filters_all' not found` – ComputerScientist Sep 16 '21 at 16:39