Re-Install grub after a windows install

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
xlancealotx

Re-Install grub after a windows install

Post by xlancealotx »

Been a while, but my windows partition got hosed. I would like to re-install the basic OS which will naturally kill grub. So my question which I think is pretty easy, can I simply re-install windows, get that working. Then just boot off my mint live CD, issue something like a grub-install which will then re-write making the world a happy place again?

Tnx
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Lantesh

Re: Re-Install grub after a windows install

Post by Lantesh »

This will work for Grub2 on Helena

* Boot your Helena live CD
* Open a terminal - Applications, Accessories, Terminal.
* Determine your normal system partition - `sudo fdisk -l` (That is a lowercase L)
* If you aren't sure, run `df -Th`. Look for the correct disk size and ext3 or ext4 format.
* Mount your normal system partition:

sudo mount /dev/sdXY /mnt

- Example: sudo mount /dev/sda1 /mnt
- Note: substitue the correct partition: sda1, sdb5, etc.
- Note: GRUB 2 counts the first drive (X) as "0", but the first partition (Y) as "1"

* Only if you have a separate boot partition:

sudo mount /dev/sdXY /mnt/boot

- with sdXY being your /boot partition designation.

* Reinstall GRUB 2:

sudo grub-install --root-directory=/mnt /dev/sdX

- Example: sudo grub-install --root-directory=/mnt /dev/sda
- Note: Substitute the correct device - sda, sdb, etc. Do ''not'' specify a partition number.

* Unmount the partition:

sudo umount /mnt

* Reboot.
breaker

Re: Re-Install grub after a windows install

Post by breaker »

You can also back up your mbr (and thus grub), reinstall Windows, then restore your mbr.
sv1xv

Re: Re-Install grub after a windows install

Post by sv1xv »

breaker wrote:You can also back up your mbr (and thus grub), reinstall Windows, then restore your mbr.
How do you backup MBR? Do you use "dd" or some other utility?
breaker

Re: Re-Install grub after a windows install

Post by breaker »

I have used both dd and the Windows program HDHacker. The second option is slightly easier because after your install, you will be booting to Windows anyway, just keep the HDHacker installer and the mbr file on a handy pen drive. I like to back up the boot sector too in case something goes really wrong. If your Windows is too hosed to use before your install, just use dd before and HDHacker after, but you could use dd from a Live CD or Live usb of course.

HDHacker: http://dimio.altervista.org/eng/
dd examples: http://www.debianhelp.co.uk/ddcommand.htm

For dd /dev/sdx is for mbr of drive x and /dev/sdx1 is for first boot sector of drive x... don't forget the count=1 bs=512... don't get if= and of= mixed up!
viking777

Re: Re-Install grub after a windows install

Post by viking777 »

I read about a different method the other day I have never tried it (because you need to have Windows on your mbr for it to work and I don't have). If it works then I believe it is a far better way to dual boot than I have ever heard of before - if it works.

This is what you do.
Install Windows first

Then install Linux which will recognise the windows install and add it to the grub start up list. Where the process differs is that you DO NOT install grub to the MBR, you install it only to the partition you are installing Linux on. This is easy to achieve, you just click the 'Advanced' button when you get to the summary screen of the installer (step 8 I think it is). In here you will see a drop down box with a choice of places to install grub the default is the hard disk mbr but you change that to the correct partition instead then install normally.

When the install is finished - but before rebooting, you open gparted from the live cd and have a look at where the boot flag is (it will probably be on your windows partition still). If that is the case move it to the Linux partition. (simply right click your linux partition select manage flags and tick boot) If the installer has moved it to the Linux partition then you need do nothing.

When you boot you should be presented with a grub menu with a choice of linux and windows.

So far there is not much difference from a normal install. The difference comes though if you want to remove linux at any stage. With a normal install (grub on the mbr) removing linux will result in a failed boot and you will have to repair your mbr from a windows disk. With this method, all you have to do is to move the boot flag back onto your windows partition with gparted before you delete your linux partition and windows will boot again on its own - no effort and much more user friendly.

Should you decide to install a third distro you repeat the procedure above but this time move the boot flag to the new install (which will already include the other two distros in its boot menu).

I stress I have never tried this, but it came from a very authoritative source and would not have been published if it didn't work.

So now you have three choices of what to do!

EDIT. I just tried this out in Virtualbox - it works, so I can really recommend it.
allis0
Level 1
Level 1
Posts: 1
Joined: Sat Jun 26, 2010 9:51 am

Re: Re-Install grub after a windows install

Post by allis0 »

I'd just like to say a big thank you to Lantesh. Your tip (the first reply) worked brilliantly for me. :D
Lantesh

Re: Re-Install grub after a windows install

Post by Lantesh »

allis0 wrote:I'd just like to say a big thank you to Lantesh. Your tip (the first reply) worked brilliantly for me. :D
You're welcome. 8)
Locked

Return to “Installation & Boot”