Restore Grub After Windows Install

Today I decided to install Windows 10 Tech Preview on another partition. I guess I was forgetting that this would replace GRUB. The Win10 Boot loader recognizes Windows 7, but not Ubuntu. I know how to replace GRUB with Windows boot loader, but not viceversa. Right now my priority is to bring back GRUB to boot 7 and 14.04, as 10 is not important.

Site Index • Wiki • Blog

After Repair Install the Mint GRUB loader screen no longer pops up. How do I restore the GRUB to it's previous state allowing the dual boot of Win7 and Mint 9? Thank you for pointing me in the right direction. After installing Windows 7 Ultimate x64 on a machine running Arch Linux the MBR became rewritten (I do not think GRUB has been uninstalled). Arch is now unbootable except if I use the live-CD to boot, and then choose from the local drives.


GRUB and Master Boot Record

Restore grub after windows installer

Web lore indicates that Windows is not friendly when installedafter/over Linux. Linux should normally installed after Windows ina dual-boot system, because it's niceenough to leave the system set up to dual boot into both. Installing Windows second sort of destroys Linux bootcapability.

This document describes how to put GRUB (GRand UnifiedBootloader) back on a hard drive that has beentaken over by a Windows 2000 install, which itself was installed afterLinux, which was installed after Windows XP. Thecritical concept is how to put GRUB back on the Master Boot Record,which is taken over during a Windows install. Bibliography andadditional references are at the end.


Mandriva Linux vs.Windows XP

My daughter's laptop computer at college crashed. Ihad theWindows XP install CD-ROM, and the plan was to send it to her and talkherthrough the installation. To be sure I had the step-by-stepinstructions memorized, I used the CD to install Windows XP ona local hard drive first, while writing down each step. I also wanted toinclude a MandrivaLinux Operating System on the same hard drive, so Idirected the WindowsXP Pro installprocess to only use the first 10 GB of the hard drive.

During the install process, Windows XP refused to fullyregister.When it contacted Microsoft over the Internet, their databaseproperly knew that this operating system was licensed to run only on mydaughter's laptop. So, I knew I only had 30 days to use XP. But that was no problem because the main reason to installit was accomplished. I intended normal work to be done on thissystem using Linux,allowingthe first 10 GB to be a play partition where I could re-install WindowsXP if I wanted, or eventually let Linux have it.

In order to put Linux on the rest of the drive (beyond the first 10 GB), I had to getinstalldisks. Normally, a person could download the MandrivaInstall CD-ROM Image(s) andinstall from a CD-ROM. Interested in doing somethingdifferent with my 250 Kbit/s Internet link, I decided to download thesmall, bootable Mandriva Network Install CD-ROM. Doingthe network install downloads the applications only if you select them. Of course, the down-side is that you have to have areasonably fast internet available during the installation procedure.The 2006MandrivaNetwork Install CD-ROM image for anormal PC computer is only 26 MB, so it fits nicely on asmall 50 MB CD-ROM, and initiates the install process.

During install, the Mandriva sequence allowed me to createpartitions on the four primary partition table entries of /dev/hda:

0 10 GBWindow (leave it as is)
00 6 GBLinux root filesystem
400 MB Linux swap space
0 60 GBLinux home filesystem

I chose the GRUBboot program and the Gnome deskstop, and havebeen pleased with both.

The GRUB loader is nice because the piece of code that isactually writtenon either the Master Boot Record of the drive or on the Boot Sector ofa partition, is static. It's smart enough to reach onto aLinux filesystem and read the rest of the files it needs to operate. One of these files is the the /boot/grub/menu.lstfile, which lets GRUB know what operating systems are available to boot.

TheGRUB bootloader is often compared to the LILO bootloader,which reads itsconfiguration file at install time, and puts a piece of code on thedisk drive that goes directly to the right files based on lower-levelsector and track mapping. LILO is a little more efficient,and in theory lets you pull a boot program off a hard drive formattedin any file system or not formatted at all. In practice, mostpeople pull the boot program from a Linux file system anyhow, so theyuse and enjoy the addition run-time options of GRUB. I've used LILO since 1994, and have just started using GRUBin the last year or so. Here's the GRUB configuration fileleft on my computer after the Mandriva install procedure:

timeout7
color black/cyan yellow/cyan
default 0
title
linux
kernel (hd0,1)/boot/vmlinuz root=/dev/hda2 resume=/dev/hda3
splash=verbose vga=788
initrd (hd0,1)/boot/initrd.img
title
linux-nonfb
kernel (hd0,1)/boot/vmlinuz root=/dev/hda2 resume=/dev/hda3
splash=verbose
initrd (hd0,1)/boot/initrd.img
title
failsafe
kernel (hd0,1)/boot/vmlinuz root=/dev/hda2 failsafe resume=/dev/hda3
initrd (hd0,1)/boot/initrd.img
title
windows
root (hd0,0)
makeactive
chainloader +1

Even to the unitiated, it's probably obvious that there arefour bootoptions, accessing partitions 0 or 1 on the first hard drive. The first three boot into Linux with various options, and thefourth boots into Windows.


Windows Writes over Linux Boot Sectors

Mydual boot Windows XP / Linux system I created worked great for a month. I knew it was time to make some changes when I tried to bootinto Windows XP, and as predicted, it refused to run because I had notregistered the copy.

So,I got out the original Windows 2000 disks for this computer, and did aninstall onto the 10 GB first partition of the hard drive. Asexpected from the non-friendly Windows, GRUB was written over, and Windows would boot only to Windows.


Putting Back Dual Boot: Mandriva Linux & Windows 2000

Windows 2000 and Mandriva Linux were both on the disk in their respective partitions. However, toput back the dual boot capability you'll have to boot Linux with somethingunrelated to this story. I used a bootable Gentoo LinuxMinimal/Install CD-ROM for the Intel x86 architecture,but I think I could have also used Tom'sRoot Boot Linux, which comes on a single bootable 1.44 MBfloppy. Research on the the Internet until you'recomfortableacquiring and booting one of those.

Once inside of the Gentoo boot Linux, mount up the Mandrivaroot partition:

cd/mnt
mkdir mount-location
mount -t ext3fs /dev/hda2 /mnt/mount-location

In my Linux distribution there was an install script(named install.sh, of allthings) left in place that runs GRUB, which automates three grubcommands. Here's a copy of the script file:

Restore Grub After Windows InstallInstall

Restore Fedora Grub After Windows Install

grub --device-map=/boot/grub/device.map --batch<<EOF
root (hd0,1)
setup --stage2=/boot/grub/stage2 (hd0)
quit
EOF

Drop into the GRUB directory previously created duringtheMandriva install and run the script, which will cause GRUB to re-writeover the Master Boot Record:

chroot/mnt/mount-location /bin/bash
cd /boot/grub
./install.sh

Restore grub after windows install

The chroot command changes the root directory of the file system being used. This allows me access to the GRUB program, theinstall scripts, and the other configuration files left on the Mandrivafilesystem rather than be stuck in the context of the Gentoo bootenvironment which knows nothing of what I'm trying to do. Also, the './' might be new toWindows users. Forsecurity and historical reasons, Linux will not automatically searchthe current directory for a program to run. The '.' directoryexplicitly directs the command processor to use the install.shscript found in the current directory.

Running the script should kick out a few lines of information.Poof! The Master Boot Recordis re-written with GRUB, and because the menu.lstfile mentioned above is already in place on the Linux partition file system, full dual-boot capability hasbeen restored. Here is the output I received from the scriptwhen it ran GRUB:

Windows 10 Restore Grub

GNU GRUB version 0.97-19mdv2007.0 (640K lower /3072K upper memory)

[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub> root (hd0,1)
Filesystem type is ext2fs, partition type 0x83
grub>setup --stage2=/boot/grub/stage2 (hd0)
Checkingif '/boot/grub/stage1' exists... yes
Checkingif '/boot/grub/stage2' exists... yes
Checkingif '/boot/grub/e2fs_stage1_5' exists... yes
Running'embed /boot/grub/e2fs_stage1_5 (hd0)'... 15 sectors areembedded.
succeeded
Running'install --stage2=/boot/grub/stage2 /boot/grub/stage1 (hd0) (hd0)1+15 p(hd0,1)/boot/grub/stage2 /boot/grub/menu.lst'... succeeded
Done.
grub> quit

I rebooted the computer using the exitand reboot commands. TheMandriva/GRUB boot selection screen Iremembered appeared. All is back to normal.

BTW, where the Windows 2000 Master Boot Record went?When running LILO,it saves a copy of the 512 byte sector it's about to write overinto a file called boot.0300 (assuming theMBR on the firstdisk) in the /boot directory. I believe GRUBdoes not do thisbecause I removed the boot.0300 file first,and it did not re-appearafter running the script. I think the Windows 2000 512-byte Master Boot Record was lost.


Bibliography / Additional Resources


InstallHowto recover from 'grub-install /dev/hda1' - Reverse problem.Having accidently slapped GRUB onto a boot sector of apartition, this explains how to put the Windows boot sector back. I wasable to do this trivially with the ddprogramwhen I used LILO, because LILO savesa copy of the original boot sector before it writes into it. In myopinion, GRUB should do this, too. Emphasizes the difference betweenhda (MBR) and hda1 (boot sector of a partition).
Windowsreinstall messes up grub - After re-installing Windows, thisuser wanted to get back a Ubuntu Linux boot option.

Restore Grub After Installing Windows 10


RecoveringUbuntu After Installing Windows- Uses Ubuntuspecific procedure, rather than generic procedure documented in thepage you're reading.

Restore Grub After Windows Installer

Howto Repair a Corrupt MBR and boot into Linux - Sameaccomplishment, but slanted towarda Fedora Linux system. Includes LILO instructions. Includes Knoppixinstructions.

Grub Fix

Revision1.1 - Thisdocument was originally created using AbiWord under theGnomedesktop. AbiWord has alot smaller footprint than OpenOffice and still does Wordcompatiblefiles. One problem: I saved the file as an.html file and when I went back to read it in, AbiWord could not readit. Hmm... I did subsequent editing with the Nvuweb page editor and the TextPadtext editor.