Thursday, February 21, 2013

Reclaiming disk space in your Windows Server Hyper-V virtual lab through deduplication

My 5 machine Windows Server 2012 virtual lab was using 91GB of space on my Macbook after installing the OS and infrastructure components into the host and guest machines. I was able to reduce the actual disk space used on my MacBook SSD by 50% through Windows Server deduplication and virtual disk shrink operations. That results in 47GB savings of physical disk space.

Disk Drive Layout

I have Windows Server Virtual Machine that runs Active Directory, DNS, Hyper-V and SQL Server Management Studio.  It also hosts 4 other guest machines whose disk drives are over provisioned for the actual drive allocated. We can do this because none of the guest machines use all their disk space and because.

As an advanced topic, we can get additional savings with Disk Deduplication where windows can create only one copy of disk space that is identical across the guest VMs/VHDs located on the same server drive.  The same operating system files exist across all VMs so we can get a 75% reduction in actual disk usage for all Windows O/S files.

Windows Server sees two hard drives c: 50GB and v: 60GB.  Hyper-V manages 4 30GB expandable virtual drives inside the 60GB disk.

Disk usage after virtual machine creation and OS installation

Windows Server Disks after Active Directory and Hyper-V installation and after 4 Virtual machines crated with operating systems. The VMWare VMDKs are 42GB
Disk usage in the VHDs after OS installation

Disk usage after basic software installation in VMs

 Windows Server Disks after Active Directory, Hyper-V and SQL Management Studio installation and after Virtual machines populated with SQL Server, Windows Message Bus and two App Servers.  The VMWare VMDKs are 90gb
Disk usage in VHD after Application Role , SQL Server and Message Bus installed in Virtual machines.

Reclaiming Disk Space

  1. Defragment the drive holding the VHDs
  2. Repeat the following for each VHD
    1. Defragment the VHD using the windows defragmentation tool
    2. Compact the Dynamic VHD 
  3. De-duplicate the drive holding the VHD
I used this blog article to aide in understanding the process.

Defragment a VHD

  1. Launch Disk Management
  2. Mount the VHD in Disk Management
    1. Use the Action-->Attach VHD
    2. Browse to the desired VHD
  3. Run the Disk Defragmenter and Optimize the hard drive.
  4. Unmount the VHDs in the Disk Management tool. 
    1. Select a Disk in the Disk Management view
    2. Right Mouse and select Detach VHD.

Compact a VHD

  1. Use the Hyper-V Manager Action-->Edit Disk...  feature.  You can also use Edit Disk... in the Actions menu you see on the right hand side of Hyper-V Manager
    1. Follow the instructions in the Edit Virtual Hard Disk Wizard for a VHD.  
    2. Browse to a vhd or vhdx.  
    3. Select Compact as the action in the Choose Option panel.

Impact

This only gained 4GB back.

De-duplicate the drive holding the VHDs

The next step is to de-duplicate the drive holding the VHDs while they VMs are down.  We know that a lot of the VHD contents are identical OS files and patches so we get huge savings.  You don't want to run deduplication on running VMs so make sure they all down. I got some of the details from this blog.  

Verify Data Duplication is installed.  Install it using the Server Manager --> Manage --> Add Rolls and Features.  Then look in Server Roles.

I'd recommend using the powershell de-dup commands and would consider not scheduling de-duplication jobs because you really only want to run this while the VHDs in the deduplicated volume are idle.
  1. Start Powershell
  2. Enable deduplication with  Enable-dedupvolume <drive_letter> 
  3. Set the deduplicaton configuration for the volume to 0 days instead of the default 5 if you wish to see results today Set-DedupVolume -Volume <drive_letter> -MinimumFileAgeDays 0 
  4. Start the deduplication process  Start-DedupJob -Volume <drive_letter> –Type Optimization 
  5. Track the deduplication process  Get-dedupjob and Get-dedupstatus 
  6. You can see the amount saved with   Get-dedupVolume  or in the ServerManager --> File and Storage Services --> Volumes screen.
Deduplication reduced the space used by 85% going from 10GB to 52GB free.
We can see the guest VM disks, after starting the VMs.  Their disk size hasn't change even though the V: drive that contains them has additional free space.

Compacting the Parent Drive when Nested

The above made space in my windows virtual machines.  It didn't save me any physical disk space on my hard drive.

I'm running my windows -virtual lab inside VMWare Fusion on a Mac. That means my C: and V: drives on my Windows 2012 Server instance are really VMDK files on my Mac. All of the above work made additional space inside the VMDK but didn't save any actual disk space on my MacBook. VMware can help here if you have the vmware tools installed inside the Windows Server2012 VM. Run the following from inside the guest machine
c:\program files\vmware\vmware tools\vmwaretoolboxcmd.exe disk shrink V:\
c:\program files\vmware\vmware tools\vmwaretoolboxcmd.exe disk shrink C:\ 
It will run for a while preparing the shrink operation. You will then see a progress bar makes it look like the machine is shutting down that tells you it is shrinking the disk.

This saved me 47GB on my MacBook's physical hard drive taking me from 91GB to 44GB!

There is a Hyper-V equivalent of this if you are running your virtual lab inside of Hyper-V.

Tuesday, February 19, 2013

Installing Microsoft Message Bus for Windows Server in your Virtual Lab

Note: This is a quick off-the-cuff blog so I don't lose my installation notes.

I created a Microsoft Virtual Lab on my Mac to learn and develop against.  Now I want to add Message Bus for Windows Server to that environment.  The message bus requires SQL Server, for queue persistence. I'll use SQL Server instance / VM I've already installed.  The message bus runs in a cluster configuration with from 1-3 message bus machines. I'll use a single node because I'm learning/devloping and not performance testing it.

Message Bus and SQL Server VMs will all be part of my virtual lab's AD domain, virtdev.freemansoft.com. You don't have to use Active Directory but it makes configuration simpler.  My Windows 7 development machine is not part of the virtual lab domain so we will have some configuration to do to give that client access.


Quick Service Bus Overview

The message bus provides a simple way of implementing asynchronous message passing between different systems or modules.  Producers feed messages into the service bus where they wait for consumption. Messages are stored in a SQL Server database so that no messages are lost even if the consumer or message bus itself go down or are restarted.

There are 4 major components to the Service bus that you pay attention to as a developer.
  1. Embedded STS security token service for consumers of the system , including message producers and consumers, not shown in this diagram.
  2. Bus configuration, Queue and Subscription/Topic definition and management.
  3. Message Queues
  4. Topics/Subscriptions, also known as Publish and Subscribe

Security can be handled through the embedded STS which can be integrated with Active Directory.   The STS has it's own port and supports several different authentication methods including windows authentication for AD users and OAuth for non-Domain clients.  Message bus runs on secure ports providing self signed certificates if no CA generated certificates are available.  You have to import the self signed certificate into the client's/caller's certificate store unless you turn off certificate validation.

The system management API makes it possible for authorized client programs to manipulate queues and topics.  This is good because there really isn't any out of the box management GUI.

Queues provide basic message bus functionality where messages is fed into named queues.  Client processes can then read the messages out of the queues.  Any number of consumers can sit act as readers where the load will be spread across the readers.  Each message is read only one time and time.

Topics are another type of message channel where the message is qualified in some  way via headers payload.  Reader clients can then subscribe to the topic with qualifying criteria.  The readers will receive all messages matching their filter qualifiers.   A single message will go to all subscriptions. that match the message's content or headers.

Installation

We are going to follow these basic installation steps when installing the software on a core system. It assumes you have an Active Directory connected VM to install service bus on.
  1. Verify you have SQL Server installed on some machine and you know a user id that can login with schema privs.
  2. Download the message bits to the system.
  3. Install the Message Bus and configure it
  4. Open the firewall ports required by the Message Bus
  5. Create a Namespace and generate the connection string required to connect to this message bus and namespace
  6. Export the certificate and CA from the message bus
  7. Copy it to a client machine
  8. Install the certificates on the Windows 7 client machine
  9. Download the message bus explorer and connect to the message bus.

Acquiring the Installer Package

I installed this on a core machine so there are two basic ways of getting the bits.  Download from the command line or download to a different machine and then copy them over to this machine using the command prompt using the \\<servername>\$C\<path> naming conventions.  


  1. Open a command prompt on the machine from Hyper-V Manager.  Select the server form the Virtual Machines list and right mouse and select connect...  
  2. Run the Start-BitsTransfer with the path down the download location 
  3. Run the Service Bus installer. It will show a GUI even if you installed the core version of Windows server.

Configure the Message Bus

  1. Set up PowerShell. We're going to use a lot of the commands in the azure reference document http://msdn.microsoft.com/en-us/library/windowsazure/jj200653(v=azure.10).aspx
    1. Import the PowerShell command-let library before executing the commands. import-module "$env: programfiles\<pathtoservicebus>.psm1" See  http://msdn.microsoft.com/en-us/library/windowsazure/jj193018(v=azure.10).aspx for available commands. 
  2. Create a new farm and point it at a sql server instance.  You should also create a namespace. The message bus was designed to support multi-tenant through the use of namespaces.  You can think of namespaces as tables  or partitions in the message bus. There are a couple ways configuring the message bus
    1. Use PowerShell   
      1. Use the New-SBFarm command to create the farm.
      2. Use the New-SBNamespace command to create a namespace
    2. You can run the service bus configuration wizard GUI.
      1.  Use c:\Program Files\Service Bus\1.0\GUIMicrosoft.ServiceBus.configWizard.exe even if you are doing this on a core server as long as you connected through the hyper-v manager.
      2. Create a Farm
      3. Create a Namespace
  3. Verify the new farm configuration with the PowerShell command Get-SBFarm.
  4. Verify the Namespace configuration with Get-SBNamespace.



Open the Firewall Ports

We need to open the firewall ports, 9350-9355, for the Service bus.  We're going to use the netsh command
netsh advfirewall firewall add rule name="service bus 9350-9355 In" dir=in action=allow localport=9350-9355 protocol=tcp

Get the Namespace Connection String

Use PowerShell to find out the connection string for the message bus and namespace.  We'll use this to with the ServiceBusExplorer and when creating connection strings for applications.

This connection string assumes you are using an AD account to connect to service bus.  We'll ad OAuth authentication to this connect string for programs not using windows authentication. We're using PowerShell probably as a domain account with administrator privileges.
  1. Type Get-SBNamespace to see the available namespaces.
  2. Get the connection string for your service bus and namespace with get-SBClientConfiguration -name <namespace>  I received the following.
    Endpoint=sb://ServiceBus1.virtdev.freemansoft.com/FreemanSoft;StsEndpoint=https://ServiceBus1.virtdev.freemansoft.com:9355/FreemanSoft/;RuntimePort=9354;ManagementPort=9355
  3. In my case, I needed to use OAuth so I could connect to the message bus with one of my other PCs.  I ended up with 
    Endpoint=sb://ServiceBus1.virtdev.freemansoft.com/FreemanSoft;StsEndpoint=https://ServiceBus1.virtdev.freemansoft.com:9355/FreemanSoft/$STS/OAuth;RuntimePort=9354;ManagementPort=9355;WindowsUsername=Administrator;WindowsDomain=virtdev.freemansoft.com;WindowsPassword=Password!

Copy Autogenerated Certificate to Client

Service expects to use SSL and creates a self signed certificate to get you started.  You need to copy that certificate to any client machine and install it in the certificate store.  You can write programs to ignore this certificate problem but programs like the Service Bus Explorer may fail unless you have a recognized certificate.
  1. Export the certificate using the Get-SBAutoGeneratedCA PowerShell command. It will create AutogeneratedCA.cer and AutoGeneratedCA.crl files.
  2. Copy these files to the client machine.  I was running on Windows Server 2012 Core so no Gui explorer was available.  I copied with the command line. 
    1. copy AutogeneratedCA.* \\client-machine\c$\<some-directory>
  3. Install the certificate and authority in the client machines using the MMC Certificate Authority snap in following these instructions http://msdn.microsoft.com/en-us/library/windowsazure/jj192993(v=azure.10).aspx 

Verify Installation 

Use the Service Bus Explorer to verify the installation. I did this on a different machine but you could do it on the Service Bus machine if you were doing this all on your local Windows dev box.  Service bus comes as a Visual Studio project that you have to build.  In my case service bus is a core system so I installed my dev tools and Service Bus Explorer on a different machine.
  1. Download Service Bus Explorer from code.microsoft.com Do not use the version on the Microsoft Service Bus download page.  It is out of date.
  2. Open the Service Bus Explorer project in Visual Studio and build the project.
  3. Run the Service Bus Explorer
  4. Select Connect
  5. Paste in the connection string built in a step above.  Use the OAuth version if you are not calling from an AD machine and account.
  6. You should connect but see no queues or topics
Connection problems are usually certificate errors, an error in the connection string or missing firewall exception rules on the service bus host machine.

Multiple Service Bus Hosts

You add additional configured hosts with the Add-SBHost command. I have not used this command.

Credits.

I'd like to thank Harin and Ryan for their patience with repeated questions.



Thursday, February 14, 2013

Subdomain DNS for VMWare/Hyper-V Virtual Lab on a MAC

Scenario

I have a Windows 7 VM that I do general development on in addition to writing Java or other code on my Mac.  Sometimes I want to push code from my Windows 7 VM to a virtual Windows Server Lab set of VMs.  Other times I want to write a program on the Mac that communicates with servers in my virtual lab.  Direct IP address connection is always possible across these machines butI want name based address resolution so that I can test software the same way it would be in our data center.

The virtual lab is powered down most of the time so the DNS solution must work well for general internet traffic when that lab's DNS server is unavailable.  

The virtual lab has its own AD server that registers all the Domain members host names and IP addresses. In my case, I have it act as a subdomain of a domain that I have. The subdomain DNS is visible to machines on that private network whether they are in the AD Domain or not.

My Windows 7 development VM and my Windows Server virtual lab run in VMWare Fusion on my MacBook using NAT networking.  This puts them on a non-publicly routable network "behind" my Mac.  Fusion provides DNS support using the same DNS support used by the MAC itself. By default all DNS for non AD Domain machines runs through the Mac.  All DNS for AD Domain machines runs through the AD controller and then through the MAC.



Option 1: Routing all VM DNS through AD/DNS

I didn't use this option because I only run my Virtual Lab part of the time.

One option is to route all the non-domain windows VM's DNS through the AD/DNS controller.  That DNS server acts as the sole DNS system of record for the AD domain, VIRTDEV in the diagram, and forwards all other requests to the internet DNS servers.  You can either set this behavior in the Windows 7 VM directly using the network properties or you can configure Fusion to provide this behavior via DHCP using dhcpd.conf (/Library/Preference/VMWare Fusion/vmnet8/dhcpd.conf)

host MyDevMachine {
    hardware ethernet 00:15:5D:90:84:03;
    fixed-address 172.16.144.104;
    option domain-name-servers 172.16.144.100;
}

Option 2: Routing DNS through the Mac Using Resolver

I used this option because

  1. The Mac itself can use DNS to access the virtual lab machines by name.
  2. DNS works well whether the virtual lab, with it's DNS, is up or not.  


An alternative is to use the default "through the Host" while routing slightly change the way the MAC resolves addresses.  Normally the Mac uses the DNS servers provided by the host, external, network.  That network doesn't know about our private lan, virtual lab, machines.  We can configure the MAC to use an alternative servers for specific domains while retaining the default behavior for all other domains.  We can configure the AMC to use an alternative server for the VIRTDEV domain in this example.

Unix machines, in genera, use /etc/resolv.conf to tell them where to find their DNS nameservers. This file can be modified through the Network control panel or effectively modified via DHCP at startup.  The Mac can also be configured to use specific DNS servers for specific domains in a way that is unaffected by the control panel or DHCP.  When looking for a DNS server for a domain:

  1. The Mac first looks for a file with that domain name in the /etc/resolver directory.  Assuming that file exists, it uses the server specified in that file to provide DNS namespace to address support.
  2. If step 1 fails then the Mac then looks at the servers in resolv.conf and uses those servers to provide DNS resolution

Configuring the Mac to use Alternative DNS for Specific Subdomains

This must be done with an account that has elevated privileges or the ability to sudo. You can do this with GUI tools or with a shell prompt. 
  1. Create the directory /etc/resolver.  It does not exist, by default.
  2. Create a file with the fully qualified domain name of your virtual lab.  In my example the file name is /etc/resolver/virtdev.freemansoft.com
  3. Add two lines to the file
    1. domain <your domain>
    2. nameserver <ip of your DNS server on the private domain>
The changes are picked automatically up.  You can verify this by using the nslookup command in a terminal window. Here are the contents my /etc/resolver/virtdev.freemansoft.com file.

nameserver 172.16.144.100
domain virtdev.freemansoft.com

Works for Linux Guests and the Mac Itslef

The Mac resolver file approach has works for guests running any operating system that want DNS support for the machines joined to the AD domain independent of their operating systems.  Those guests do not require per VM configuration and do not require custom DHCP nameserver settings in the Fusion dhcpd.conf.  It also works with pre-built VMs or appliances available of the internet.




Options Not Considered

I never considered the option of editing the windows host file or editing the network adapter settings.  This wouldn't work for the Mac itself and it would require that every consumer of that private network/domain be modified to know about the private network's DNS server.  I wanted something that would work for any number of virtual machines without having to modify each individual machine.

Conclusion

Modifying the Mac DNS resolver to support a virtual domain makes it easy to provide support for programs on the Mac, on linux guests and non-AD domain windows machines.   The virtual lab, with its DNS domain, appears to the host and guests as if it is a "real" domain on the internet making it possible to test code the same way you would if you were in your data center or in some cloud deployment.   

Saturday, February 9, 2013

Enabling Remote Management for a Windows Server 2012 Core Hyper-V instance

I have a small virtual lab running inside hyper-v hosted on a Windows Server 2012 standard instance.  The host is running AD and DNS and has a GUI interface.  The virtual lab machines all run Windows Server 2012 Core.

Connect to the Hyper-V Instances

There is an array of ways to manage or execute operations on Windows Server 2012 core instances.

  • Use the Server Manager -> All Servers tool.  Highlight the server and right-mouse to see the following options
    • Computer Management:  This provides remote access to the Computer Management console. This will not work out of the box due to firewall rules.
    • Remote Desktop Connection: This does not work because core instances do not have any GUI installed
    • Windows Powershell:  This essentially runs a remote Powershell command. I've had inconsistent results with commands typed in this window

  • Use the Hyper-V management console accessible from the Server Manager -> All Tools menu.  Highlight the server and right-mouse to see the following options
    • Connect... This opens up a console screen on that machine.  By default is uses the local Administrator account.  You can force it to use an Active Directory Account by sending that screen a Ctrl-Alt-Delete and selecting Switch user. Note the schizophrenic use of a graphical screen on a Server Core instance that isn't supposed to have any GUI! 


Enable Remote Management

You may receive the following, somewhat misleading, error panel when attempting to remotely manage a Hyper-V virtual machine.  The panel correctly tells you that you have to enable the windows firewall rules.  It tells you the wrong rule sets when the machine you are trying to manage is a server 2012 instance, probably also  Windows 7 and Windows 8 instances.  The panel appears after the remote connection times out.
Note that it tells you to enable rule sets
  • COM+ Network Access (DCOM-In)
  • Remote Event Log Management
You actually want to enable rule sets
  • Windows Management Instrumentation (WMI)
  • Remote Event Log Management
Run these commands as administrator on the machine you wish to manage using the remote console via Hyper-V.  I normally do this with a domain account.

netsh advfirewall firewall set rule group="Windows Management Instrumentation (WMI)" new enable=yes
netsh advfirewall firewall set rule group=“remote event log management” new enable=yes

The Computer Management control panel (mmc) should now be able to remotely connect to and manage your core server.

Saturday, February 2, 2013

Install a Microsoft Virtual Lab on a Mac with Fusion and Hyper-V

Modified 2013/02/09 to add remote management enablement

We're going create a Hyper-V Microsoft virtual lab environment on a Mac with the following configuration as discussed in this previous blog article http://joe.blog.freemansoft.com/2013/01/run-microsoft-virtual-lab-on-mac-with.html.  We can use the same approach on Linux machine using VMWare workstation / player.

Our mini-data center consists of 5 machines.

  • A Windows 2012 Server hosting Active Directory and DNS.  The machine also holds/manages the hyper-v environment used to run the rest of the machines
  • Two Windows 2012 servers to be used as application machines
  • One Windows 2012 server used to run SQLServer 2012
  • One Windows 2012 server used to run the on-prem version of windows service bus
We're not actually going to install any application software in this article..


The basic steps are

  1. Install Windows Server 2012 that will be our AD/DNS/Hyper-V host
  2. Hack the VMWare/Fusion/Workstation dhcp.conf file to give this windows server a fixed address.
  3. Install and configure Active Directory / DNS and Hyper-V
  4. Install multiple guest machines
    1. Install a guest machine in Hyper-V
    2. Give the machine a sensible host name
    3. Hack the VMWare/Fusion/Workstation dhcp.conf file to give this Hyper-V guest a fixed IP address and to point it at the server first created that has DNS.
    4. Add the machine to Active Directory
    5. Add the machine to the pool of managed servers on the base machine's Server Manager console
  5. (Optional) Activate all the machines.
  6. (Optional) Enable remote Computer Management on the virtual machines

Sizing Our Virtual Lab

We're going to create a VMWare virtual disk (vmdk) to hold our primary, Hyper-V/AD/DNS, machine.  That VMDK will be fully allocated to the server.  That windows server hosts Hyper-V and will allocate pieces of the at VMDK  for each of the VHD used by the individual Hyper-V virtual machines.  


The default minimum size for a windows virtual machine is 30GB.  In our case we have essentially 5 virtual machines including the AD machine for a total of 150GB of disk space as allocated by VMWare Fusion to its VMDK. You can actually allocate less disk space when not using pre-allocated disks because the hypervisors will only grow the virtual disks to the size actually used.  I've allocated 110GB and could easily have gotten away with less. The following picture shows how much disk space is actually used before any software is installed on each machine. 


I actually ended up allocating two drives. One for the Hyper-V/AD/DNS machine and one that is used as disk space for all of the virtual machines hosted in Hyper-V.  I did this because I didn't initially think through how much space I needed for all of the virtual machines.  Note that I only allocated 60GB for the Hyper-V machines even though I had 4 30GB machines running on that.  I've over-allocated the disk space knowing that most of the machines will never reach anywhere near 30GB of disk usage.  The hyper-v VHDs can not all expand to their maximum sizes because they are sitting on a VMDK smaller than that amount.  

Disk space usage after main Windows Server 2012 (AD/Hyper-V) and 4 bare Windows Server 2012 core installations

Disk space usage after loading SQL Server, SQL Studio, Windows Message Bus and Application Server features into the VMs.

I'm not recommending it but one advantage of a two drive setup is that the primary drive won't run out of disk space even if the hyper-v virtual disks grow beyond the 60GB allocated to them.

Windows Server with Multiple Drives when Hosted

Windows Server 2012 treats non-primary virtual disks as SAN drives.  So in this case, I allocated two VMWare VMDK drives to VMWare Fusion.  Fusion then made one of those the primary for our main Windows Server 2012 instance and the other a supplemental drive V in the picture.  That Windows Server 2012 instance sees the second drive as a SAN.  You have to enable the SAN drive before you are able to use the Windows Server 2012 disk manager to partition, format and mount the drive as a drive letter.

Installing Microsoft Server 2012 in VMWare Fusion

  1. Create a new virtual machine with the appropriate configuration.
  2. The quad core MacBooks appear as 8 core machines due to hyperthreading. I allocated 4 cores to the Microsoft Server 2012 virtual machine because it will need to then divy those cores out to it's Hyper-V managed virtual machines.  Use NAT networking and allocate enough memory.  I allocated the Fusion 4 maximum 8GB of memory because Hyper-V will also divy that up among the virtual machines it is managing

    • 4 cores
    • NAT Networking
    • 8GB memory
    • Enough disk space for all the virtual machines needs.  We discussed non-preallocated 150GB above. I allocated 110GB across two drives. You can use one drive and size appropriately based on your needs.
  3. Boot the virtual machine and install Microsoft Server 2012 in VMWare Fusion
    You should have a running standalone Windows Server 2012 VM running in Fusion after the installation.  It will not have AD , DNS or Hyper-V enabled.
    1. You will be asked to pick an administrator password.  I re-use this password here for all the VMs I created later to simplify managing this cluster.  
  4. Capture the network device MAC address Fusion gave your new server.  You will need it later. Virtual Machine --> Network Adapter --> Network Adapter Settings We will use this to reconfigure the VMWare Fusion DHCP server later.
    1. Note I found that the MAC address on this adapter wasn't as useful as I thought.
  5. Capture the network device MAC address for the Virtual switch in the Microsoft Server 2012 instance. We will use this to configure the VMWare Fusion DHCP server later.
    1. Type ipconfig  in a powershell window and look at the line labeled Physical Address
    • or
    1. Server Manager --> Local Servers --> click on vEthernet
    2. You should see the Server 2012 Network Connects.  
    3. Double click on the vEthernet (Intel(R) PRO 1000 MT) Network Connection - Virtual Switch
    4. Double click on Details
    5. Record the MAC address under Physical Address 
      1. We would use 00-50-56-21-B8-6A in the screen shot below.




Configure Fusion VMX to fool Windows Server for Hyper-V

  1. Shutdown Windows Server 2012
  2. Terminate Fusion
  3. Edit the VMX file and add the following settings at the bottom of the file. 
    1. hypervisor.cpuid.v0 = FALSE
    2. vhv.enable = TRUE
    3. mce.enable = TRUE
  4. Start Fusion and edit the VM settings.
    1. Change the preferred virtualization engine to Intel VT-X with EPT in the drop list
    2. Enable 3D graphics if you intent to install VMWare Tools in this VM

Configure For Fixed IP Even Though Running DHCP


Fusion must be restarted for any dhcpd.conf changes to take affect.

We want all of our machines to used fixed IP addresses and are going to use the dhcpd.conf file to make this happen. I used this tutorial as a reference http://nileshk.com/2009/06/24/vmware-fusion-nat-dhcp-and-port-forwarding.html We don't know all the MAC addresses for all of the servers so we're going to have to do this in phases.

The Windows server hosting Hyper-V will end up with two IP addresses, one for the ethernet adapter created by Fusion and one for the Virtual Switch created inside Microsoft Windows.  We recorded those above when we installed the server.

  1. Edit the VMWare vmnet8 dhcpd.conf file with an elevated privilege account.
    1. MAC: This is located in /Library/Preferences/VMWare Fusion/vmnet8/dhcpd.conf
    2. PC: [notes to be added later]
    3. Linux: [notes to be added later]
  2. Add sections at the bottom for both the MAC assigned by Fusion and the VNET adapter assigned by windows.  
    • Choose addresses outside of the range shown in the subnet range attribute.  That range is the list of addresses the VMWare dhcp server dynamically allocates.
    • I believe the domain-name field is actually ignored.  I left it in to remind me of the AD domain I intend to use.
  3. Start Fusion and this virtual machine
  4. Verify the vEthernet Virtual switch has the IP address you assigned to it's MAC address
Example: 
# the ethernet fusion provided
host server2012hostFusion {
    hardware ethernet 00:50:56:38:2F:68;
    fixed-address 172.16.144.99;
}

#the ethernet provided by server2010 virtual switch 
host server2012host {
    hardware ethernet 00:50:56:21:B8:6A;
    fixed-address 172.16.144.100;
    option domain-name "virtdev.freemansoft.com";
}

Install Active Directory and Hyper-V Features

I used this blog article as a starting point http://www.petri.co.il/windows-server-2012-as-domain-controller.htm You only need about half the information on that page if you are just doing a lab setup. Microsoft's page http://technet.microsoft.com/en-us/library/jj574166.aspx is useful but also feels a little out of order.

  1. Use the Server Manager  to Add Roles and Features  via the Manage menu item.
  2. Add Active Directory Domain Services (with DNS) and Hyper-V features.
  3. Promote this machine to be the Active Directory.  
    • I did this a stand alone lab so I made a New Forest.
    • For my example, I picked virtdev.freemansoft.com.  I recommend that you pick some subdomain of your domain.  Some examples use .local which can be confusing when using Apple Bonjour which also uses .local.
  4. Make sure DNS is enabled as you go through the wizard.  This machine will provide DNS to all the Hyper-V guests.
  5. The machine may restart one or more times.
  6. You should see <domain>\Administrator as the user id at the password prompt the next time you log in.

Hyper-V Virtual Switch

You may get asked how you want the Hyper-V virtual switch configured during the feature installation.  Select "External" and not "Private" or "Internal".

You should verify that the Hyper-V Virtual Switch is set to External.
  1. Run the Hyper-V manager
  2. Select Virtual Switch Manager along the right hand side.
  3. Select the Intel (Pro)/1000 MT Network Controller
  4. Verify that it is set to External and allow Management operating system to share the controller.

Installing Guest Machines Inside Virtual Hyper-V

This http://www.prescriptiveit.com/build-hyper-v-virtual-lab-hyper-v-role-and-virtual-network/ blog is another good reference for Hyper-V and a virtual lab.

Basic Installation

The simplest thing to do is to download the server installation iso to the windows server hard drive (virtual drive). That will make it visible to Hyper-V guest machines as installation media. You can also use a physical DVD but I haven't done that. We're going to do a Server Core install. Useful information can be found here http://technet.microsoft.com/en-us/library/ee441257(v=ws.10).aspx

  1. Run the Hyper-V  manager with Tools-->Hyper-V Manager menu in the Windows 2012 Server Manager
  2. Select Action->New->Virtual Machine... in the Hyper-V Manager.
  3. Use the Wizard
    1. Pick a host name
    2. Select the Virtual Switch on the networking page.  It picks "no network" by default.
    3. Pick a disk size that makes sense
    4. Select Install Operating System from Bood CD/DVD-ROM and select the ISO you downloaded earlier.
  4. Start the newly configured machine in the Hyper-V Manager. 
  5. Start the machine and install the software
  6. Connect remotely from the Hyper-V Manager
  7. Set the timezone of the machine using tzutil.  A good blog on setting the timezone can be found here Setting timezones I used the command tzutil /S "Eastern Standard Time"
  8. Bring down the newly created VM machine using reboot /s /t 0 or the Hyper-V server manager
  9. Switch from the virtual machine back to the Hyper-V Server Manager.

Binding VM MAC address to DHCP config for fixed IP

By default the guest VMs are configured with DHCP we really want fixed IP addresses to make DNS easier and make life better with AD.

We could pick fixed addresses on each machine and configure their DNS server entry. I found it easier to just configure all my machine IP address and DNS server pointers in the same place in the dhcp.conf file.
  1. Select the network settings for that machine along the right hand side
  2. Select the adapter and the Advanced section.
    1. Look at the MAC address.  It was dynamically created.
    2. A MAC address of all 00 pairs means the server is not up (or was never brought up). You may have to start the server in this case.  Remember though, the MAC address can only be changed while the machine is down.
  3. Change the MAC address to static.  
  4. Change the MAC address to something other than what was dynamically allocated. I usually change it to be one digit off (not in the last pair) from what was assigned by Hyper-V.  You want a MAC address that is outside Hyper-V's pool of managed MAC addresses.
    1. My originally was 00-15-5D-90-83-01.  I changed the 83 to 84.
  5. Bring down the Windows 2012 Server running Hyper-V.  This will shutdown the newly created VM if it is still running
  6. Quit Fusion
  7. Edit the dhcp.conf to provide a fixed address for the newly created machine.  That address is bound to the MAC address for the new machine.
    • host AppServer1 {
          hardware ethernet 00:15:5D:90:84:00;
          fixed-address 172.16.144.101;
          option domain-name-servers 172.16.144.100;
      # option domain-name "virtdev.freemansoft.com";
      # option host-name "AppServer1.virtdev.freemansoft.com";
      }
      
      
  8. Start Fusion which runs the Windows Server 2012 VM
  9. Start the newly created Hyper-V managed VM
  10. Connect remotely to the Hyper-V managed VM using the Hyper-V Manager
  11. Verify you got the IP address you expected instead one from the dynamically allocated DHCP pool.  You can use ipconfig /all at the powershell command prompt for that virtual machine.
You now have a machine with the same fixed IP address every time without having to adjust the Windows networking adapters in each VM.  The whole configuration was done from the Hyper-V manager and the VMWare Fusion dhcp manager.

Troubleshooting

I did have a problem on one of my virtual machines where I couldn't get it to grab the static IP from the Fusion DHCP server even after several reboots. In that case I changed the machine name from the ugly name windows uses by default to the name I called it in the dhcpd.conf file. I had to do that on the virtual machine.  Note that Hyper-V machine name is not the machine name actually given by the Windows  installation process.

Add the New Hyper-V VM to the AD Domain

You can install several machines using the steps above and then add them all at once to AD or you can do the full path for each machine.

  1. Connect to the VM remotely from the Hyper-V Manager.
  2. If you did a core installation then you will get a powershell prompt.
  3. Join the domain with netdom join <current ugly server name> /Domain:<the domain you selected>
    • My command was netdom join WIN-ADJKS /Domain:virtdev.freemansoft.com
  4. The command should return without errors
  5. Restart the Hyper-V guest machine to pick up the domain name change
  6. Open a console to the VM windows server OS using the Hyper-V manager.
  7. Change the name of the computer from the auto-generated name to something meaningful like AppServer1 or SQLServer1
    • Use netdom renamecomputer <name>
  8. Open the Server Manager on the main (AD/DNS/Hyper-V) windows server.  (You only have one place to do this if you did core installs for the Hyper-V hosted VMs).
  9. Select All Servers 
    • It will initially just have your Windows Server 2012 host machine
  10. Select Manage --> Add Servers
  11. Click the Find Button.  It will show all the servers in your AD domain.
  12. Select the Server and press the "right" arrow to move it to the right pane.
  13. Click OK The server will now appear in the Server Manager -> All Servers pane.

(Optional) Activate the Virtual Machines with Commands

I haven't figured out how to do this without re-entering the product key entered on installation.  
  1. Set the key slmgr.vbs –ipk <key> 
    • This will return immediately. A popup will appear some time later if this succeeds.
  2. Activate the instance with slmgr.vbs –ato
    • This will return immediately. A popup will appear some time later if this succeeds.

(Optional) Enable remote Computer Management on the VMs

Final Comments

That is pretty much it.  You can create several machines in Hyper-V, configure them with fixed IP, add them to Active Directory and then add to the server management pool. Then it is time to install your application software and databases.  

Sample dhcp.conf Modifications

This configuration supports one Windows Server running Hyper-V and 4 Hyper-V hosted VMs, AppServer1, AppServer2, SQLServer1 and ServiceBus1.

# the ethernet fusion provided
host server2012hostFusion {
    hardware ethernet 00:50:56:38:2F:68;
    fixed-address 172.16.144.99;
}

#the ethernet provided by server2010 virtual switch 
host server2012host {
    hardware ethernet 00:50:56:21:B8:6A;
    fixed-address 172.16.144.100;
 option domain-name "virtdev.freemansoft.com";
# option host-name "server2012host.virtdev.freemansoft.com";
}

host AppServer1 {
    hardware ethernet 00:15:5D:90:84:00;
    fixed-address 172.16.144.101;
    option domain-name-servers 172.16.144.100;
# option domain-name "virtdev.freemansoft.com";
# option host-name "AppServer1.virtdev.freemansoft.com";
}

host AppServer2 {
    hardware ethernet 00:15:5D:90:84:01;
    fixed-address 172.16.144.102;
    option domain-name-servers 172.16.144.100;
# option domain-name "virtdev.freemansoft.com";
# option host-name "AppServer2.virtdev.freemansoft.com";
}

host SQLServer1 {
    hardware ethernet 00:15:5D:90:84:02;
    fixed-address 172.16.144.103;
    option domain-name-servers 172.16.144.100;
# option domain-name "virtdev.freemansoft.com";
# option host-name "SQLServer1.virtdev.freemansoft.com";
}

host ServiceBus1 {
    hardware ethernet 00:15:5D:90:84:03;
    fixed-address 172.16.144.104;
    option domain-name-servers 172.16.144.100;
# option domain-name "virtdev.freemansoft.com";
# option host-name "ServiceBus1.virtdev.freemansoft.com";
}