Friday, April 22, 2011

Configuring Virtual Machines and Hosts

Last time, I covered setting up Windows 7 to run XP virtual machines. What came next was figuring out how to setup VirtualPC optimally.

First, make sure that Virtualization Technology is enabled in your BIOS, if such a setting exists. Without it, VirtualPC can't take full advantage of the host's hardware if this is not enabled. This would mean you can't run CAD, GIS, or play games, which need a closer relationship to available hardware. Since nearly everything to do with hardware is "emulated", hardware intensive apps won't run on VirtualPC without Virtualization Technology enabled.

The goal is to have enough memory for both the host and the VM, while minimizing paging operations. Robbing the host of too much memory is worse than robbing the VM. So the host should get the priority. If the host is slowed down, it will slow the VM down, so there’s no winning way to give a VM very much more than it will ever need.
1. First, log onto the host and launch all the applications you’re used to running. Let all initial processing (AV def update, AV initial scan, email sync with server, etc.) finish until the computer comes to rest.) You might want to launch maybe one or two more apps, especially if there’s an app you use maybe once every day, even if you don’t leave it running all the time. Especially launch any memory-hogs you use regularly.
2. Bring up Task Manager and go to the Performance tab. Look at the bottom under Physical Memory and note how much memory is available.

In this example, we have 2336MB.
Now subtract about 200MB for additional applications. This totals 2136MB available (max.) for the VMs to use.
3. Repeat this process for each virtual machine, but don’t just record “Available” – figure out how much is used.

In this example, the VM has been pre-configured on the host to allow 1024MB of memory to the VM. It is only using 593.3MB (1048048 – 454696 = 593352). Add ~35MB for additional applications. The VM actually needs 629MB.

Adding additional memory, above what your VM needs, will not speed it up. It will only allow you to run more applications. Most VMs are dedicated to 1-3 specific legacy applications, and no more. So it is best to allot barely more than the minimum. If your VM becomes sluggish, you might want to double-check your VM memory usage as time goes on. Newer versions of applications usually use additional memory, as the trend is towards code-bloat. If your host has more than enough memory, you might want to allow your VMs 100-200MB more, to allow for memory-hogging upgraded applications, like newer versions of IE, new OS Service Packs, etc.) as the years go by. This way you’re not hassled with VM configuration maintenance in the future.

4. So the last step is to reconfigure Virtual PC. Since 4GB on the host is a healthy quantity, I rounded 629MB upward to ¾ of a gig. I changed 1024MB to 768MB.

After making the change, and launching my VM, I see the host still has just over 1702MB available. The VM still has 203MB available.

- Dual NICs
Some machines have more than one NIC available. Our Server group advises against this practice, as it has caused issues with DNS and/or AD. However, it is possible to configure your host to use one NIC exclusively, while configuring your VM to use the other exclusively.
Since our Server group advises against dual NICs, I will only mention it, not detail the steps, since I don't have experience with it.

- No NIC Found
If your VM can’t find an available NIC, then make sure you have the latest version/patch-level of Virtual PC and that “Integration features” are enabled.

Then make certain the appropriate host computer’s NIC is selected in the VM settings…

"Turn off" versus "Shutdown"
“Turn off” is not accurate. This term refers to yanking the power cord. This is only good if the VM is attacked by a virus, or a similar panic situation.
“Shutdown” is a normal, controlled shutdown, where any open apps will be closed, and temporary files released.

Slow Explorer Access Between host and VM
There’s a problem with some VMs copying files from the host hard drive – phenomenally slow. There are a few possible fixes…

Method 1
The 1st method is for servers, not clients. Follow the hyperlinked text above if you want the details.
Method 2
Disable TCP task offloading in the registry of the host computer. To do this, add the following value.
Restart your computer for it to take effect.
Method 3
Most NICs don’t have the choices detailed in Method 3, so don’t be surprised if Method 2 is the only one available.
If you do not want to disable TCP segmentation offloading on the whole system, and you want to only disable TCP segmentation offloading on the network adapters that Virtual Server guests use, you must not add the DisableTaskOffload registry entry that is described in Method 2. Instead, you can disable the task offload properties on the Advanced tab of the Properties dialog box of the network adapter.

To disable the task offload properties, follow these steps:
1. Click Start, click Run, type ncpa.cpl, and then click OK.
2. Right-click your network adapter, and then click Properties.
3. Click the General tab, and then click Configure.
4. Click the Advanced tab.
5. In the Property box, click the Offload TCP Segmentation property.
6. In the Value list, click Off, and then click OK.
7. If you also have the following task offload properties in the Property box, you must repeat step 5 to step 6 to disable these properties:
o Offload Receive IP Checksum
o Offload Receive TCP Checksum
o Offload Transmit IP Checksum
o Offload Transmit TCP Checksum
Sysinternals has a Secure-Delete utility that some say improves performance of VM’s. I’m not sure how or why it would, but for what it’s worth, they say to run the switch to clean empty space on the host hard drive where the VM’s VHD resides…
:: usage: sdelete [-p passes] [-s] [-q]
:: sdelete [-p passes] [-z|-c] [drive letter]
:: -c Zero free space (good for virtual disk optimization)
:: -p passes Specifies number of overwrite passes (default is 1)
:: -q Don't print errors (Quiet)
:: -s Recurse subdirectories
:: -z Clean free space
sdelete.exe -c C:

Hard Drives

It will give better performance for both the host and VM if the VM is on a different physical drive from the host OS. This is often not possible, but it is more ideal.
This may not be true for external drives – it depends on the overall data-rate. Alleged speeds are never reached, and some connections may be running at 1/20th the rated speeds, for whatever reason. Running from a mapped network drive is a very bad idea.
It’s also good to keep disc fragmentation to a minimum, on both the host and the VM.

Virtual PC and XPMode

Many of you may work in a corporate environment with Volume Licensed Mircosoft products. Moving to Windows 7 from Windows XP (nearly every company skipped Vista) can be difficult. The biggest headache is compatibility. The solution is often to include a Windows XP virtual machine with every new Windows 7 machine.

Install Virtual PC first, either x86 or x64 for your OS type...

Then install Windows XP Mode...

Update for Windows XP SP3 to enable RemoteApp (install on your VM)...

The first one is installed into Windows 7 to allow you to run a virtual machine. WindowsXPMode allows you to create a Windows XP virtual hard drive with Windows XP on it, and then to run applications inside the XP VM without manually launching VirtualPC.
This is a big download because the Windows XP CD is included within the installer. Every Vista and Windows 7 install comes with a Windows XP license at no extra charge. Microsoft did this to allow you to work around compatibility issues. When all else fails, run in from a virtual machine.

Copying your Volume Licensed XP Virtual Machine
In a corporate environment, with Volume Licensed products, there's a problem. The WndowsXPMode VHD that gets created automatically is an OEM license, not a VL license. So in a corporate environment, don't bother going through the XPMode wizard to create the image. You'll have a production-line of new computers anyway.
So one problem is your license, but another is that each VM has to be set up the way real, physical machines are set up, if they are going to be 100% functional. Our domain has quite a few web-based systems everyone needs access to. Some don't yet work with IE8, much less IE9. Some don't work on Windows 7. Many server-based applications automatically grab the logged-on user's credentials. This means an OEM license is not legal, and your VM will have to be joined to the domain like a real machine. So you need to build a VHD/VM using your Volume Licensed copy of Windows XP. Every Windows 7 machine will have to have Virtual PC and WindowsXPMode installed, and you'll have to copy your XP VM to every new Windows 7 machine.

I've decided, since multiple users sometimes use one machine, that I would store the VHD here: D:\VirtualMachines\WinXPMode\WinXPMode.vhd

Microsoft designed Virtual PC in a clunky per-user manner, storing the VHD within profiles. To me, this is crazy. On a multi-user computer, this means every user gets their own separate VHD that is several gigabytes in size! This might even be a license violation, since each Vista or Win7 machine is only allowed one XP license. But that depends on the fine-print (since only one person at a time can actually use a computer, only one VM will be running).
I move it to the D: partition where everyone can get to it.
Unfortunately, every user who logs on has to run the VPCWizard located here...
And Microsoft didn't bother to create a menu shortcut for you (did they really think this through?)

Setting up your XP VM
I unplug the network wire on my Win7 host machine and launch the VM. I run Sysinternals' NewSID (sorry folks, this is no longer included within Sysinternals' package because it ruins Windows 7 and Vista. Maybe you can still find it somewhere else? Or use something else.
I rename the VM the same as the computername, but with an extra "VM" tacked onto the end. That way, when looking at computers on a domain, and you see \\Q123456 and \\Q123456VM, you know the the latter is a VM being hosted by the former.

After the VM reboots with a new SID and name, I join it to the domain.
Every new user added to the VM has to run VPCWizard to create individual *.vmc and *.vmcx files. These will be stored in the individual user Profiles pointing at the common VHD on the D: drive.