Tricky situation with re-installing windows and Grub


Recommended Posts

Okay, I have to re-install windows for a cousin, however he has 2 different Linux installations and they both are in middle partitions, not the primary ones. For example :

Hard Disk 1 ----> /Sda1 (windows) /Sda2 (linux) /Sda3 (Data)

Hard Disk 2 ----> Sdb1 (data) / Sdb2 (Linux) /Sdb3 (Data)

Now, Grub is installed onto Sda1 according to him and he's not sure where Grub is for the 2nd installation. It's definitely not (?) in the primary Sdb1 partition because it doesn't boot when I detach Sda and boot with just Sdb attached. Actually I get thrown to a 'Grub-rescue' prompt with a couple other messages that I can't recollect atm, I'm not at the machine.

Does this mean Grub is, in fact, also installed on Sdb for the 2nd Linux install he did? If yes, how can I get Grub to 'see' the Linux installation on /Sdb2? He doesn't have any /boot or /swap for either.

And how do I repair Grub on Sda1 after I reinstall Windows for him? I'm kinda lost to be honest, but I'm willing to touch it _only_ if I can fix it for him... because I just don't have the time to give if it ends up borking both Linux installations. He wants both installations, and preferably be able to boot both individually with their own Grub.

I hope I've explained it clear enough, I need help :p

Link to comment
Share on other sites

After you install Windows and remove GRUB from the MBR, use Super Grub2 Disk to boot from the Linux installation on the secondary hard drive and reinstall GRUB. The command should look something like the following, assuming the drive is /dev/sdb:


sudo grub-install /dev/sdb
[/CODE]

You should now be able to boot GRUB from that hard drive if it is set as primary in BIOS. Next, use Super Grub2 Disk again to boot from the Linux installation on the hard drive with Windows. You can reinstall GRUB using a similar command to the one you used previously; just reference the other hard drive. The command should look something like the following, assuming the drive is /dev/sda:

[CODE]
sudo grub-install /dev/sda
[/CODE]

Link to comment
Share on other sites

If yes, how can I get Grub to 'see' the Linux installation on /Sdb2? He doesn't have any /boot or /swap for either.

You only need one grub (bootloader) installed in the MBR of the first disk (as setup in bios), the VBR (volume boot record) will take care of the rest. As far as getting grub to see additional distros goes, it should be as simple as:

grub-mkconfig -o /boot/grub/grub.cfg

Assuming you're using Grub2. For Grub 1, you'll have to edit grub.cfg by hand or pehaps use something like os-prober.

And how do I repair Grub on Sda1 after I reinstall Windows for him? I'm kinda lost to be honest, but I'm willing to touch it _only_ if I can fix it for him... because I just don't have the time to give if it ends up borking both Linux installations. He wants both installations, and preferably be able to boot both individually with their own Grub.

Load up a live cd / usb pen with the same architecture (32/64 bit) as the installation (important!), then chroot into the installation:

# change sda1 to your linux partition
mount /dev/sda1 /mnt

# mount temporary file systems in preparation for chroot
mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev
mount -t devpts pts /mnt/dev/pts

chroot /mnt /bin/bash

# restore grub
grub-install /dev/sda

That's what I do anyway.

  • Like 2
Link to comment
Share on other sites

^ Thanks for the detailed breakdown bro, I'll be printing this page and taking it across to refer :)

I manage to take good care of my own Linux install, but this Triple installation (Windows, Linux, Linux) with a messy disk structure is kinda throwing me off. I'm going there tonight, will update the thread when I get back.

Cheers!

Link to comment
Share on other sites

To add to what simplezz said, booting from a live disc and using a chroot to recover your GRUB installation would certainly work (and is, in fact, the method that most distribution's installers use to install from disc in the first place), but is merely an alternative to my method of booting into each OS installation. The main advantage of simplezz's solution over mine is that you can update both installations at once (or only do one or the other, as simplezz suggested).

Also, if you are using Debian or a Debian-based distribution (such as Ubuntu or Linux Mint), the distribution provides scripts that probe for existing OS installations and add them to the boot menu. (These scripts are called every time there is a kernel update and will overwrite your grub.cfg, including any custom modifications you have made. If you want to add custom boot entries, place them in /boot/grub/custom.cfg instead.) Once you are in the chroot or booted into the OS installation, use

sudo update-grub[/CODE]

instead of

[CODE]sudo mkconfig -o /boot/grub/grub.cfg[/CODE]

.

Assuming you're using Grub2. For Grub 1, you'll have to edit grub.cfg by hand or pehaps use something like os-prober.

I believe that GRUB Legacy uses [i]/boot/grub/menu.lst[/i] by default instead of [i]/boot/grub/grub.cfg[/i] like GRUB 2. However, unless your distribution is rather old (like Debian Lenny or CentOS 5), it should have shipped with GRUB 2 instead of GRUB Legacy, so my correction is probably irrelevant.

Link to comment
Share on other sites

You only need one grub (bootloader) installed in the MBR of the first disk (as setup in bios), the VBR (volume boot record) will take care of the rest. As far as getting grub to see additional distros goes, it should be as simple as:

grub-mkconfig -o /boot/grub/grub.cfg

Assuming you're using Grub2. For Grub 1, you'll have to edit grub.cfg by hand or pehaps use something like os-prober.

Load up a live cd / usb pen with the same architecture (32/64 bit) as the installation (important!), then chroot into the installation:

# change sda1 to your linux partition
mount /dev/sda1 /mnt

# mount temporary file systems in preparation for chroot
mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev
mount -t devpts pts /mnt/dev/pts

chroot /mnt /bin/bash

# restore grub
grub-install /dev/sda

That's what I do anyway.

To add to what simplezz said, booting from a live disc and using a chroot to recover your GRUB installation would certainly work (and is, in fact, the method that most distribution's installers use to install from disc in the first place), but is merely an alternative to my method of booting into each OS installation. The main advantage of simplezz's solution over mine is that you can update both installations at once (or only do one or the other, as simplezz suggested).

Also, if you are using Debian or a Debian-based distribution (such as Ubuntu or Linux Mint), the distribution provides scripts that probe for existing OS installations and add them to the boot menu. (These scripts are called every time there is a kernel update and will overwrite your grub.cfg, including any custom modifications you have made. If you want to add custom boot entries, place them in /boot/grub/custom.cfg instead.) Once you are in the chroot or booted into the OS installation, use

sudo update-grub[/CODE]

instead of

[CODE]sudo mkconfig -o /boot/grub/grub.cfg[/CODE]

.

I believe that GRUB Legacy uses [i]/boot/grub/menu.lst[/i] by default instead of [i]/boot/grub/grub.cfg[/i] like GRUB 2. However, unless your distribution is rather old (like Debian Lenny or CentOS 5), it should have shipped with GRUB 2 instead of GRUB Legacy, so my correction is probably irrelevant.

I'm back, and it was very .....easy, thanks to both of you's detailed instructions! Way easier than I had thought it would be :p

Before I reinstalled Windows, I decided to try and boot each hard disk on it's own to see how it goes - and surprisingly this time the 2nd hard disk booted his 2nd Linux install without a hitch. Not sure why it hadn't worked the first time I tried it. I proceeded to reinstall Windows onto his 1st hard disk, and followed simplezz's instructions to get Grub back on his HDD 1. Windows wasn't available as an option until I booted into Linux and did 'sudo update-grub' as xorangekiller said.

That was it, both Linux installs are now bootable and both disks can be booted individually.... mission accomplished! :D

Link to comment
Share on other sites

Thanks for reporting back. Glad to hear that everything went well. Learning something new is always a good thing (especially if it turns out to be easier than you anticipated).

Link to comment
Share on other sites

Thanks for reporting back. Glad to hear that everything went well. Learning something new is always a good thing (especially if it turns out to be easier than you anticipated).

Indeed my friend, and thanks once again to your and simplezz's instructions. They were perfect - that was all I needed to do! :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.