SDB:Repair MBR after Windows install

Jump to: navigation, search


Tested on openSUSE Recommended articles Related articles
Icon-checked.png

Icon-manual.png Icon-help.png

Situation

After installing Windows alongside Linux, GRUB has been replaced by the Windows bootloader. How do you get GRUB back into the MBR?

Note "has been". When openSUSE is installed according to recommendation to keep a neutral MBR that Grub will have been installed to a partition rather than the MBR, which will result in a simpler "repair" procedure..

Procedure

You have to make sure to be able to boot into openSUSE. You can do this either by using the Rescue System mode on the installation DVD or by using a CD with Plop Boot Manager or Super Grub Disk, for example. Note that you can let boot any ISO on USB with UNetbootin. Then you can repair the Master Boot Record with a few commands:

If using grub2 (default on openSUSE 13.1)

Open a terminal and type commands. Firstly elevate your priviledges (not required in Rescue System mode):

sudo -i

Figure out from the partition table what is your (main) linux partition, e.g. /dev/sda3:

fdisk -l

Then type:

mount /dev/sda3 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc # maybe superfluous
mount --bind /sys /mnt/sys # maybe superfluous
mkdir /mnt/mounts # could be needed if booted with rescue openSUSE 13.1
mount --rbind /mounts /mnt/mounts # could be needed if booted with rescue openSUSE 13.1

If this preparation went well, perform the actual change:

chroot /mnt
grub2-install /dev/sda
exit

And if that succeeded,

reboot

If using legacy grub

Open a terminal and type (no 'sudo' is required in Rescue System mode):

 sudo /usr/sbin/grub

Then execute the following commands:

 grub> find /boot/grub/stage2 (will show the path of actual grub installation, you will need on the next step)
 grub> root (hdx,y)
 grub> setup (hdx)
 grub> quit

Caution: x represents the disk number and y represents the partition number where GRUB stage2 is installed. The numbering starts at 0. For example, if the first command outputs (hd0,5) you should do root (hd0,5) followed by setup (hd0). After rebooting, the GRUB menu should reappear.

This solution was sourced from please_try_again on the forums.

If a neutral MBR was employed

All that is necessary is to use any available partitioning tool to move the boot flag from the Windows partition to the partition to which Grub is installed. This is easily done with FDISK (which calls the boot flag the active flag) from a DOS boot or from DISKPART or Disk Management from a Windows boot, or using one of the partitioning tools from a generic bootable media such as the Ultimate Boot CD or Hiren's BootCD.

See also