Adding A Windows Hard Disk To A Linux Server


It’s relatively easy to add a Linux disk to a Windows machine. But it’s not as easy to add a Windows disk to a Linux machine.

I have a powerful Linux server that I spent a number of weeks installing software on. When I configured it, I decided to make it a dedicated Linux server. However, a lot of software actually works on Windows. I’ve considered virtual machines. But if you have read my escapades with Virtual Box, a dual boot just makes one less variable and software to be concerned with.

In the past, I’ve created a number of Windows/Linux dual boot machines, and the order of operations was pretty easy. First, install Windows on disk 1. Then install Linux on disk 2. Installing Linux will install grub, update the Master Boot Record (MBR) on disk 1, and give a choice of Windows or Linux when booting.

But this time the order of operations was reversed, and Linux was installed first. Since it took so long to install all the software on Linux, I didn’t want to modify anything on the Linux disk. If there was a problem, I wanted to put it back to the way it was; just remove the Windows disk, and boot Linux as before.

So, the requirements were: Install Windows on a second disk. Get the machine to dual boot, without modifying any of the existing Linux install. Allow for rollback.

————-

At first, I tried using EasyBCD for a few hours. But I was unable to figure out a solution. On the forums, there were no responses to my question on how to accomplish my task.

Eventually, I got this to work using two methods. The first was to use an older version of SuperGrub. The second method was to use Linux commands. In both cases, I had to get to the Linux OS using either Supergrub, or Supergrub2.

The SuperGrub documentation is not good. It seems to be useful for those who have already spent many hours studying grub, as if the documentation is just a reminder to show how someone very familiar with grub how to accomplish the same things via the Supergrub menu. Interestingly, the Supergrub documentation also says that its purpose is to teach people about grub. Hmm, I thought a good GUI was supposed to eliminate the need to know the intricacies. Unfortunately, this is the case for so much documentation out there these days. ūüė¶ Go figure.

So, here is the solution for any other poor soul that needs to accomplish this.

—-

Before doing any of this, you should practice with two non critical hard drives first. Much of grub is not intuitive or clear.

Install windows on a single hard disk, as the only standalone drive in the server. Disconnect the Windows drive.

On another hard disk, install Linux as the only standalone drive.

Now, you will have the two disks to experiment with.

—-

In The BIOS:

Connect both the Linux and the Windows drive in the BIOS. Set the windows drive to be the first one in the boot sequence and make sure that it is Windows that boots.

—-

Boot With Supergrub:

Note that I was using an old Supergrub CD that I had, version 0.98-os.1. It is not the newer Supergrub 2, but the concepts will be the same. Supergrub does not have a great interface. You have to poke around quite a bit to see what you can and can’t do with Supergrub. Read the instructions, and navigate around. There are lots of paths and the tree structure through the menus gets pretty big. I wonder how many leave nodes you can eventually reach.

———

Practice Booting Windows:

Boot the machine with the Supergrub disk.

This can also be done from the main menu.
!WIN!

or

Choose Language and Help
English SuperGrub disk
Windows
Boot Windows

———

Practice Booting Linux:

Boot the machine with the Supergrub disk.

On the main menu, highlight, but don’t hit the enter key:
!Linux ! (1)  Auto

If your Linux configuration was that of only one Linux hard drive in the machine, then the hard drive will be known in grub.conf as:  hd0,1

Supergrub should be able to find grub easily enough, and give you the selection options that grub.conf gives. However, since you have now changed the boot order of the Linux disk in the BIOS, it now needs to be: hd1,1

If you choose one of the grub selections, and hit enter, you will get an error. With my Redhat, I got: Error 17: Cannot mount selected partition

To solve this, highlight one of the selections

press e, for edit.

Go to the line that contains hd0:
root (hd0,0)

press e, for edit.
Change (hd0,1) to (hd1,1)
Press enter to return to the grub boot sequence

Press b for boot.

Linux should now boot.

—-

If you get lost in the editing, and can’t navigate back to the Supergrub menus,
press c for the command line.
help
reboot

And the computer will reboot.

—–

Boot Into Linux, Backup And Edit grub.conf:

cd /boot/grub/
cp   grub.conf        grub.confYearMonthDay

Edit grub.conf so that all references to hd0 are changed to hd1

Copy both grub.conf and grub.conf backup to a USB stick.

———

Snag Configuration For Windows:

Reboot with SuperGrub

Highlight, but do not enter:  WIN => MBR and !WIN!
Press e for edit.

You will notice the a few dd commands to put grub on the MBR, then the commands:

rootnoverify (hd0,0)
makeactive
chainloader +1
boot

Write these commands down.

hit c for the grub> command prompt

reboot

———

Modify The MBR Of The First Hard Disk (Windows), And Install Grub.Conf On It:

Reboot with SuperGrub

GRUB => MBR & !Linux! (Auto)  (1)

Boot into Linux.

———-

Edit Grub.Conf And Add Windows As An Option:

Add this to the bottom of the grub.conf file

title Windows
rootnoverify (hd0,0)
makeactive
chainloader +1
boot

Set the appropriate default choice for the server to boot. Remember that the first entry in the list is not 1, but: 0

default=2

———-

Important To Note:

/boot/grub/grub.conf will be on the second Linux disk. If you remove the Linux disk, Windows will not boot.

If you remove the Windows hard drive, Linux will now be on hd0,0, not hd1,0, and Linux will not boot.

———-

To Remove The grub MBR From Windows and Return To The Original State:

To go back to what things were, you can use the Windows restore CD and run the command, FIXMBR. Do some google searches to figure out how to do this. To use Supergrub:

First, restore the Linux disk to what it was:
Boot to Linux.
Login as root.
cd /boot/grub
cp   grub.confYearMonthDay  grub.conf

Restore the Windows disk to single standalone:

Boot with SuperGrub:

WIN -> MBR & !WIN!

———–

Installing Grub Using Linux Commands:

This method is actually shorter and faster than using Supergrub. But first, you have to be able to get to the Linux install.

Configure the disks and the BIOS as above. Windows as the first hard drive. Linux as the second.

Use Supergrub, or Supergrub2 to get to the Linux installation. Login as root. Find and backup the file: grub.conf.

cd /boot/grub
cp   grub.conf        grub.confYearMonthDay

run the command: grub

grub>

From within grub>, search for the file grub.conf. On my Redhat installation, grub’s root directory is not /, but /boot.

grub> find /boot/grub/grub.conf
Error 15: file not found

grub> find /grub/grub.conf
find /grub/grub.conf
(hd1,0)

If there was only one hard drive in the machine, the output would have been: (hd0,0)

With this output from find, (hd1,0), run the command:

root (hd1,0)
Filesystem type is ext2fs, partition type 0x83

Install a new MBR on the first hard drive, hd0,0.

setup (hd0)
Checking if “/boot/grub/stage1” exists… no
Checking if “/grub/stage1” exists… yes
Checking if “/grub/stage2” exists… yes
Checking if “/grub/e2fs_stage1_5” exists… yes
Running “embed /grub/e2fs_stage1_5 (hd0)”… 27 sectors are embedded.
succeeded
Running “install /grub/stage1 d (hd0) (hd0)1+27 p (hd1,0)/grub/stage2 /grub/grub.conf”… succeeded
Done.

Edit the grub.conf file. Ensure that the Linux choices are on (hd1,0). Add a choice for Windows.

title Windows
rootnoverify (hd0,0)
makeactive
chainloader +1
boot

Test that the boot works, and the different boot options.

Conclusion:

This is one of those things that is not difficult if you install Windows first. But installing Linux first, and later adding a Windows hard drive, turned out to be much more difficult. I hope this is useful for anyone else who is stuck on the same issue.

———

Useful links:
http://www.supergrubdisk.org/wiki/Howto_Fix_Grub

http://www.fatmin.com/2012/07/rhel6-restore-grub-on-mbr.html

http://www.av8n.com/computer/htm/grub-reinstall.htm

http://forums.fedoraforum.org/showthread.php?t=257631

 

Advertisements

One Response to Adding A Windows Hard Disk To A Linux Server

  1. rodgersnotes says:

    After completing this post, and thinking about it, I came up with a much simpler method. See it here:

    https://rodgersnotes.wordpress.com/2013/02/20/rodgers-very-simple-dual-boot-method/

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: