Restoring GRUB2 on Software RAID 0 using LiveCD after Windows 7 wiped it

11,083

If you boot by recovery CD your root devices is not / but the ISO representation in RAM. In this case we have to mount the real root partition first.

Check if your software RAID is active:

$ cat /proc/partitions

You have to expect your sda, sdb, dm-0 followed by dm-1, dm-2 and so on representing your partition table entries.

If you do not see the dm-* entries you have to activate the software RAID manually:

$ sudo dmraid-activate

Check /proc/partitions again and verify if grub is aware of it:

$ sudo grub-mkdevicemap -m -

The output may differ but should look like (where *ata-WDC_WD5001AALS-00L3B2_WD-WCASY5902194* depends on your hardware configuration):

(hd0) /dev/disk/by-id/ata-WDC_WD5001AALS-00L3B2_WD-WCASY5902194
(hd1) /dev/disk/by-id/ata-WDC_WD5001AALS-00L3B2_WD-WCASY5867648
(hd2) /dev/mapper/nvidia_acajefec

Your real root partition should be /dev/mapper/nvidia_acajefec1 right now. We mount this partition for future tests now:

$ sudo mount /dev/mapper/nvidia_acajefec1 /mnt
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /proc /mnt/proc
$ sudo mount --bind /sys /mnt/sys

Check if grub is able to map the devices to your partitions:

$ sudo grub-mkdevicemap -m - | sudo grub-probe --device-map=/proc/self/fd/0 --target=device /mnt

You should see something like /dev/mapper/nvidia_acajefec1.

Identify the name of your partition as GRUB device:

$ sudo grub-mkdevicemap -m - | sudo grub-probe --device-map=/proc/self/fd/0 --target=drive /mnt

The output should be something like (hd2,msdos1).

So far so good. In order to install/update GRUB we are ready to switch to the real root partition and update the boot block:

$ sudo chroot /mnt /bin/bash
$ sudo update-grub
Generating grub.cfg ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-2.6.32-5-686-bigmem
Found initrd image: /boot/initrd.img-2.6.32-5-686-bigmem
Found Linux on /dev/mapper/nvidia_acajefec1
Found Windows on /dev/mapper/nvidia_acajefec3
done
$ sudo grub-install /dev/mapper/nvidia_acajefec
Installation finished. No error reported.
$ exit

Your are ready to reboot the system.

Share:
11,083

Related videos on Youtube

Karl
Author by

Karl

Updated on September 17, 2022

Comments

  • Karl
    Karl over 1 year

    I have installed Ubuntu 10.10 on my system. However, I need to install Windows 7 back, and I expect that it would alter GRUB and it did.

    Right now, my partition on my Software RAID 0 looks like this:

    alt text

    nvidia_acajefec1 is Ubuntu 10.10 and nvidia_acajefec3 is Windows 7.

    I've been following some guides around and I am always stuck at GRUB not able to detect the usual RAID content.

    I've tried running:

    sudo grub
    
    > root (hd0,0)
    

    GRUB complains it couldn't find my hard disk. So I tried:

    find (hd0,0)
    

    And it complains that it couldn't find anything.

    So I tried:

    find /boot/grub/stage1
    

    It said "file not found".

    Here's the text from the console:

    ubuntu@ubuntu:~$ grub
    Probing devices to guess BIOS drives. This may take a long time.
    
           [ Minimal BASH-like line editing is supported.   For
             the   first   word,  TAB  lists  possible  command
             completions.  Anywhere else TAB lists the possible
             completions of a device/filename. ]
    grub> root (hd0,0)
    root (hd0,0)
    
    Error 21: Selected disk does not exist
    grub> find /boot/grub/stage1
    find /boot/grub/stage1
    
    Error 15: File not found
    

    **Fortunately, I got one person suggesting that what I've been trying to do is for GRUB Legacy, not GRUB2. So I went to the suggested website, (http://grub.enbug.org/Grub2LiveCdInstallGuide) try to look around, and try:

    ubuntu@ubuntu:~$ sudo fdisk -l
    
    Unable to seek on /dev/sda
    

    This is just the step 2 of the instruction in the http://grub.enbug.org/Grub2LiveCdInstallGuide and I cannot proceed because it cannot seek /dev/sda.

    However,

    ubuntu@ubuntu:~$ sudo dmraid -r
    /dev/sdb: nvidia, "nvidia_acajefec", stripe, ok, 488397166 sectors, data@ 0
    /dev/sda: nvidia, "nvidia_acajefec", stripe, ok, 488397166 sectors, data@ 0
    

    So what now? Do you have an idea for how to make fdisk see my RAID array on live cd (Ubuntu 10.10)? Honestly, I am lost, very lost in trying to restore GRUB2 on this software RAID 0 system right now.

  • Karl
    Karl over 13 years
    Unfortunately, I tried: ubuntu@ubuntu:~$ sudo mount /dev/nvidia_acajefec1 /mnt and I got the following as output: mount: special device /dev/nvidia_acajefec1 does not exist
  • Karl
    Karl over 13 years
    Thank you very much. I've followed all of your step. However, the console shows a little different for the last part for install/update GRUB: root@ubuntu:/# sudo update-grub sudo: unable to resolve host ubuntu Generating grub.cfg ... Found linux image: /boot/vmlinuz-2.6.35-23-generic Found initrd image: /boot/initrd.img-2.6.35-23-generic Found linux image: /boot/vmlinuz-2.6.35-22-generic Found initrd image: /boot/initrd.img-2.6.35-22-generic Found memtest86+ image: /boot/memtest86+.bin Found Windows 7 (loader) on /dev/mapper/nvidia_acajefec2
  • Karl
    Karl over 13 years
    Right now, I have rebooted my system, but it goes to Windows 7 right away, and no GRUB at all. Perhaps I am forgetting something...?
  • Anmol
    Anmol over 13 years
    I've missed the sudo grub-install /dev/mapper/nvidia_acajefec in the chroot environment.