Thursday, May 3, 2012

Mirroring disks in Windows Server 2008

Like many geeks, I have a server running at home to store all of my files and perform various functions like backups of PCs in the network and also to host virtual machines.  In my case, this server is running Windows 2008 R2.  I learned recently (thanks to a disk failure on a different PC) that disk mirroring of the C: drive will not allow you to boot from the secondary disk in a software RAID mirror without diving into the command line and hacking files.

To keep my power consumption down, my server at home does everything.  It runs Windows Home Server 2011, and to achieve disk resiliency I configured Windows disk mirroring (essentially software RAID-1) on the operating system (C:) drive and data (D:) drive.    I then loaded a bunch of important data and Virtual Machines - using VirtualBox - onto this server, so it's pretty critical that I don't lose it.

In order to configure reliable disk mirroring that lets us boot to either disk in our RAID set if one of them fails, we need to understand how Windows 2008 handles its boot process.


How Windows 2008 boots

When Windows boots, it looks for the primary hard disk as defined in BIOS/EFI and then executes the boot loader on that drive, which is located in a special 100MB hidden partition called the  "System" partition, not the C: (boot/operating system) partition.  Also note that Windows 2008 uses a different boot system to Windows 2003; rather than NTLDR it uses BOOTMGR, which interrogates a small database file called "Boot Configuration Data" (BCD) for boot instructions.  This BCD database is encoded using the same format as the Windows registry, so it can only be viewed or edited with the bcdedit.exe tool.

The important point to take away from here is that Windows Server 2008 (and indeed Windows Vista and Windows 7) do not boot from the C: drive but rather from the System partition.  This partition must exist on whichever disk is being booted from and the BCD database must contain the correct references to that disk's unique identifier (GUID).  Without both the system partition and the correct BCD configuration on the disk, that disk cannot be booted from.


What everyone does wrong

People mirror the C: drives on their servers on the assumption that this will make it possible to boot from the secondary disk.  This is wrong, and here's why: when you create a mirror of the C: drive on a Windows 2008 server, it makes only one small change to the BCD information located in the primary disk's system partition.  That change basically allows the system partition on the primary disk to complete the boot process using either the C: drive on the primary disk or the mirror of C: drive on the second disk.  

This is great if you ever lost the C: partition only, but in reality what's going to happen is that you will lose the entire primary disk.  If you lose the primary disk, you lose the system partition, and you cannot boot without it!

What happens when the primary disk fails

Put simply, if your primary disk fails your server won't boot.  The BIOS or EFI will go looking for the boot loader files on the secondary disk and it will not find them because there is no copy of  the System partition (and BCD) on the secondary disk.  At this point you're hosed.

Luckily you can actually create a disk mirroring solution in Windows 2008 (or even Windows 7) which does let you boot from the secondary disk.  All guidance provided here is extracted form the Microsoft document on Configuring Disk Mirroring  for Windows Server 2008 R2, but we're going to discuss the juicy bits.

How to set up Windows 7/2008 disk mirroring so you can boot when one of the disks fail

Put simply, you need to copy the system partition from the primary disk to the secondary disk, and edit the BCD info on the secondary disk so that it points to itself rather than the primary disk.  Here are the major caveats:
  • The system partition cannot be mirrored.  You must perform scheduled or manual copies of the contents from one drive to the other using robocopy.
  • The BCD data on each disk must point to itself using its own GUID
  • If your primary disk fails, your secondary disk will become the primary disk and will then hold this role forever.  The new disk will become the secondary disk.
  • To replace a failed disk, you must boot to the remaining healthy disk and manually break any mirror sets using the diskpart tool.  When the new disk is installed you must repeat the entire process of mirroring your C: (and other) partitions, and the manual copying of the System partition to the new disk.  You must also configure the BCD data on the new disk again.



2 comments:

  1. Thanks! Looking forward to your screenshots and any additional advice you might have.

    ReplyDelete
  2. Windows 10 Key Sale Store

    Go the online store http://www.windows10keysale.com/ . You even don't need to spend a lot of time but only need to place the order and finish the payment in several minutes. The product key will be sent to you via email in short time. Very efficient!

    Windows 10 Key Sale Store

    ReplyDelete