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.



Tuesday, May 1, 2012

Rear panel headphone sockets

The Situation

In my Home Office I like to work to the sound of background music, so I'll crank up some Progressive house trance from DI.FM.   Usually I just use my 2.1 (speakers and subwoofer) combo but sometimes I need to use my headphones, as I either need to be quiet due to my son sleeping in the room behind me or just so I can block out the sounds of all three of my boys going apeshit outside the study door.

You'd think this was an easy task to do, right?  Not so fast, young Padawan!  The roadblocks I hit on the path to glory were numerous and stupid.


Headphone sockets

If your PC has both speakers and headphones, how do you reliably switch between them?  Well as far as all the hardware manufacturers are concerned, you use "jack detection" which detects when a pair of headphones are plugged into the headphone socket on the front of your PC, and switches the audio output device accordingly.  This means you have to continually keep plugging in and removing my headphones every time you want to use them, which is highly annoying and over a long period of time will just result in worn out connectors and broken cables.


AC97 and HD audio front panels

So the manufacturers of sound devices say "just use jack detection".  That's great if you like to keep yanking cables all the time, but as it turns out hardly any cheaper PC cases have HD audio front panels and instead follow the "AC97" standard.  Jack detection is only possible on HD audio compliant panels, so if you don't have one of these panels you can't use jack detection and you will need to manually switch your audio output from the speakers to the headphones.  

OK, that seems easy enough, right?  Nope.


Windows 7 audio device switching (or lack of it)

As it turns out, Windows 7 does not have the ability to easily switch between audio outputs.  The only way to do it out of the box is to open the "Playback Devices" icon in the System Tray, then when the list of devices pops up, right click the audio output device you want to use and then selecting "Set as Default Device".






Ugly, right?

Anyway, once you've done the manual device change, you'll need to repeat the process in order to switch your audio devices back.   Sigh.








There is light at the end of the tunnel though, with tools such as SoundSwitch that let you assign a HotKey to do all of the above for you.  I can't recommend this tool enough.


Benefits - VoIP/video call software

The other benefit of having multiple audio output (and input) devices active at any one time is that you can dedicate one of them to your video call/VoIP software.  Skype and 3CXPhone in particular use statically assigned audio devices and there is no hot switching of devices within the application (like, say, a "speakerphone" option to switch between your headset and your speakers).   I personally like to make all my VoIP calls via my headset as it means I can sit through a 2-hour teleconference without using my arms.   Trust me when I say that once you have a long teleconference with speakers on both ears rather than one, you will never want to go back to your stupid one-ear headset ever again.


But wait...

So, we're almost there, right?  Well, that depends on whether you like to have your headphone cables sticking out the front/top of your PC all the freaking time.  Since my headphones are always plugged in, my kids are always bumping into them and damaging the wires and plugs.  It's a nightmare for any parent!

And so this leads us into our last major gripe.


Rear panel headphone ports don't exist??

Your swanky expensive motherboard came with what looks like a dozen audio sockets on the back of it, but once you plug your speakers into one (or more) of them, the only way to get your headphones connected is to plug them into a "front panel".   But wait, all I want to do is have both my speakers and my headphones connected to a socket on the rear of the PC!  

Turns out nobody supports this.  Headphones are for the front of the PC, dontchaknow?  GRRR!  Stupid tech companies!  Just let me re-map my freakin audio ports how I want!

Nobody even makes a rear panel connector that acts as a front panel.  I mean, REALLY?  How hard can it be?  I was thinking of knocking one together myself from spare parts, but there are other more elegant solutions.


Secondary sound cards

Whilst Windows 7 doesn't like letting you switch audio outputs, it does however fundamentally support multiple outputs.  So, why not just buy a dedicated soundcard for your headphones?  Indeed, this is really the easiest solution and there are many players here.   Some headphones even come with a USB soundcard, which basically lets you add a dedicated headphone-only audio output device via a USB dongle.  

As for me, I've got enough bloody USB devices hanging off the back of my PC so I decided to step it up a little, and buy an Asus Xonar DG PCI soundcard.  This is a fully featured soundcard but the software drivers and core functionality of this card scream "use me for your headphones".  It supports hardware-assisted Dolby Headphone technology and includes an onboard amplifier specifically designed to boost the volume to your headphones based on the impedance rating of the speakers contained within them.   It's a nice touch and I have to say the sound quality of this card is superb.  It cost me a total of $45 (Australian); a good deal.

I now have my speakers connected to the onboard Realtek soundcard, and my headphones (and headphone microphone) connected to the Xonar DG.  Works a treat, but note that this is a PCI card and you may find it jammed up against your expensive (and hot) PCI-express video card.  Luckily it's a half-height card so the problem is somewhat helped by that.


One last thing

Before signing off with a happy smile on my face, I did discover one last piece of obscurity in the Asus Xonar DG.  This soundcard supports the use of a front panel connector (like any other soundcard), but  unless you specify the front panel type as being "HD Audio" (rather than AC97) it will always default to the front panel as it assumes headphones are connected there.   If you don't do this, every time your PC reboots or comes back from sleep mode, your headphones don't work because the Xonar DG defaults its audio output to the front panel!  This can be changed via the Xonar control panel software, but that's no better than having to manually switch audio output devices via the system tray.

Be warned that you can only switch the "front panel" mode on the Xonar DG  during the installation of the driver.  Stupid!