Recovering moved .mod files using grubrescue

I did a dumb thing... I forgot that Ubuntu 10.04 (Lucid Lynx) switched to GRUB 2 which puts a ton of *.mod files (kernel modules) in /boot/grub. I thought they were soundtrack files put there erroneously, and I moved them. Needless to say, the next reboot was traumatic. I was presented with something I had no memory of ever seeing... a 'grub rescue>' prompt.

With the help of Fixing GRUB error: “error: unknown filesystem” however, I was able to recover...

  • I discovered that GRUB rescue does not have 'cd', 'cp' or any other filesystem commands except its own variation of 'ls'.
  • So first I had to find the partition with the /boot directory containing vmlinuz file and other boot image files... (approximation from memory of failed attempts, as well as blank lines for clarity, added 2014-07-10 by docsalvage)

    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 
    
  • I found a /boot directory containing the vmlinuz file vmlinuz-2.6.32-33-generic on partition (hd0,2).

  • Then I manually booted from the 'grub rescue>' prompt. The following commands will...

    • Set the root to use the /boot directory on partition (hd0,2).
    • Load kernel module linux.
    • Set that module to use the kernel image vmlinuz-2.6.32-33-generic.
    • Set initrd(initialize RAM disk) to use the image initrd.img-2.6.32-33-generic.
    • Boot Linux.
  • grub rescue>  set root=(hd0,2)/boot  
    grub rescue>  insmod linux  
    grub rescue>  linux (hd0,2)/boot/vmlinuz-2.6.32-33-generic root=/dev/sda2
    grub rescue>  initrd (hd0,2)/boot/initrd.img-2.6.32-33-generic  
    grub rescue>  boot  
    
  • This boots and crashes to the BusyBox prompt which DOES have some rudimentary filesystem commands.

  • Then I moved the *.mod files back to the /boot/grub directory...

    busybox>  cd /boot  
    busybox>  mv mod/* grub
    busybox>  reboot
    
  • The reboot was successful, but that was a lot of work.

Is there an easier way?


Solution 1:

Here are some general and basic instructions to help with boot errors such as GRUB loading stage 1.5 error 15 (e.g. after the installation of Windows on different disk drive) :

  1. Boot with a LiveDVD (e.g., the Ubuntu Desktop disk).

  2. Open a terminal, and re-write the grub configuration using these commands:

    • sudo mount /dev/sdXY /mnt
    • sudo grub-install --root-directory=/mnt /dev/sdX

Where /dev/sdX is the disk where Ubuntu is installed, and /dev/sdXY is the partition on the disk where Ubuntu is installed. In other words, /dev/sdXY contains /boot and so on.

Use fdisk -l to verify the Ubuntu installation location.

Solution 2:

No. I think you pretty much found the easiest way to recover from the state of your system using grub rescue; it is a very minimalistic system giving just enough capability to boot the system.

BTW, I believe you must have found the .mod files and executed insmod linux or the linux command would have failed.

The only other way, as mentioned, would be to boot a Live CD and reinstall grub2 after chroot'ing to the 'broken' system.