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

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]

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

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

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.

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

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

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

    • No registered users viewing this page.
  • Posts

    • Lilly-Livered American Media Are Scared
    • Really? Despite the memory price rises, nothing can kill it? I thought something would.
    • I think there will be a 27H1 for actual users of 26H1 The 25h2 supports ARM too : Snapdragon X, Snapdragon X Plus and Snapdragon X Elite
    • Poll: Grand Theft Auto VI price predictions, cast your vote by Pulasthi Ariyasinghe After years of waiting, Rockstar will be solidifying the launch date of Grand Theft Auto VI with the launch of pre-orders next week. While the studio has confirmed a date for this occasion, it is yet to attach a price to the highly anticipated game. So let's see what our readers think it will cost at launch. The Grand Theft Auto VI pre-orders will kick off on June 25 for digital and physical editions. Unless some last-minute changes happen, the release date will be November 19, 2026, across Xbox Series X|S and PlayStation 5. Unfortunately, there's still no information about a PC version from the developer or the publisher Take-Two. Now the question becomes, how much will Grand Theft Auto VI cost at launch? The game is predicted by some analysts to be the biggest launch of an entertainment product ever. With the amount of hype that has been built behind it and with ballooning development costs, Take-Two may price this Grand Theft Auto entry differently from other AAA titles. The current price of a AAA game is $69.99. That norm almost rose to $79.99 before calming down. But with such a massive release, Grand Theft Auto VI may be the game that pushes the boundary again. It's also possible that Take-Two keeps the price relatively low to increase the number of players that jump in early and keep them hooked on Grand Theft Auto Online to spend on microtransactions for years to come. Keep in mind that the below poll is asking for a prediction of the standard edition price, not a deluxe or any other special edition that Take-Two will introduce for additional benefits. Also, there is the chance of the company splitting up the campaign and online portions. If you think that will happen, put your vote on what you think will be the total cost of the two. Poll Poll: How much will Grand Theft Auto VI cost? $59.99 $69.99 $79.99 $89.99 $100 or more Submit Vote If you have a very specific prediction in mind, sound off in the comments below.
  • Recent Achievements

    • Week One Done
      Genuinetonerink- Dubai earned a badge
      Week One Done
    • One Month Later
      Genuinetonerink- Dubai earned a badge
      One Month Later
    • One Year In
      hhgygy earned a badge
      One Year In
    • One Month Later
      AMV earned a badge
      One Month Later
    • Week One Done
      AMV earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      513
    2. 2
      +Edouard
      171
    3. 3
      PsYcHoKiLLa
      82
    4. 4
      Steven P.
      74
    5. 5
      Michael Scrip
      72
  • Tell a friend

    Love Neowin? Tell a friend!