Jump to content



Photo

Tricky situation with re-installing windows and Grub


  • Please log in to reply
9 replies to this topic

#1 javagreen

javagreen

    Neowinian

  • Joined: 16-July 04

Posted 04 October 2012 - 15:45

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


#2 zoheb

zoheb

    Neowinian

  • Joined: 02-January 10
  • Location: haLLuNicaTeD pAradISe

Posted 04 October 2012 - 18:53

http://sourceforge.n...bootinfoscript/

More info : http://bootinfoscript.sourceforge.net/

Hope this will help you. .

#3 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 05 October 2012 - 02:47

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

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:

sudo grub-install /dev/sda


#4 OP javagreen

javagreen

    Neowinian

  • Joined: 16-July 04

Posted 05 October 2012 - 05:00

Thanks guys, I'm going to go there later today, I'll try this and see how it goes :D

#5 simplezz

simplezz

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 01-February 12

Posted 05 October 2012 - 12:40

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.

#6 OP javagreen

javagreen

    Neowinian

  • Joined: 16-July 04

Posted 05 October 2012 - 13:41

^ 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!

#7 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 05 October 2012 - 20:42

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
instead of
sudo 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.


I believe that GRUB Legacy uses /boot/grub/menu.lst by default instead of /boot/grub/grub.cfg 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.

#8 OP javagreen

javagreen

    Neowinian

  • Joined: 16-July 04

Posted 06 October 2012 - 03:56

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
instead of
sudo mkconfig -o /boot/grub/grub.cfg
.


I believe that GRUB Legacy uses /boot/grub/menu.lst by default instead of /boot/grub/grub.cfg 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

#9 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 06 October 2012 - 04:05

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).

#10 OP javagreen

javagreen

    Neowinian

  • Joined: 16-July 04

Posted 06 October 2012 - 04:39

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! :)



Click here to login or here to register to remove this ad, it's free!