Virtual PC Guy

Distribuir contenido
Talking about Hyper-V and Virtual PC at Microsoft.
Actualizado: hace 1 hora 38 mins

Windows Virtual PC Hotfix for AMD Bulldozer Processors

Jue, 19/01/2012 - 09:05
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2012/01/19/windows-virtual-pc-hotfix-for-amd-bulldozer-processors.aspx';

We have just published a hotfix for Windows Virtual PC that addresses a compatibility problem when trying to install on an AMD Bulldozer system.

You can download it here: http://support.microsoft.com/kb/2519949

Cheers,
Ben

Categorías: Virtualización

Hotfix: Guest may crash during live migration

Mié, 11/01/2012 - 00:36
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2012/01/10/hotfix-guest-may-crash-during-live-migration.aspx';

We released a new hotfix for Hyper-V today.

This hotfix addresses an issue where virtual machines may crash (with a STOP 0x000000D1, DRIVER_IRQL_NOT_LESS_OR_EQUAL error) when it is being live migrated.  While this problem is relatively hard to encounter – I would encourage anyone who is using live migration to plan to deploy this hotfix in the near future, as you do not want to hit this accidentally.

You can download this fix directly from here: http://support.microsoft.com/kb/2636573

Alternatively, it is also being distributed through Windows Update.  Unfortunately it is only available as an optional update though – so you will need to explicitly select to install it on your servers. 

Either way, this hotfix does require that you reboot the physical server so you will need to plan the deployment of the fix appropriately for your environment.

Cheers,
Ben

Categorías: Virtualización

Converting to a fixed virtual hard disk–for a Server core installation

Vie, 30/12/2011 - 23:36
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/30/converting-to-a-fixed-virtual-hard-disk-for-a-server-core-installation.aspx';

My last challenge for getting all of my server virtual machines over to fixed-size virtual hard disks is moving some of my Windows Server 2008 R2 virtual machines.  As a reminder, the goal here is to move a virtual machine on a large dynamically expanding virtual hard disk to a smaller fixed-size virtual hard disk. I have used the same technique as I discussed here – but for obvious reasons the process is quite different, as I cannot use any of the GUI tools.  Here is the process I followed:

 

  1. Login to the virtual machine using an administrative account
  2. Run diskpart
  3. Check your disks with list disk
  4. Select the disk you want to shrink (disk 0 in my case – so select disk 0)
  5. Check your partitions with list partition
  6. Select the partition you want to shrink (partition 4 in my case – so select partition 3)
  7. Check how much space you can save with shrink querymax
  8. Shrink the partition to your desired size (in my case - shrink desired=70000 – note that the value here is how much you are shrinking the partition by, not the new size of the partition)
  9. Check that you are happy with the new size with list partition
  10. Exit diskpart with quit
  11. Once you have shrunk the partition(s) use Windows Server Backup inside the virtual machine (if you have not installed this – you can do so by running start /w ocsetup WindowsServerBackup – don’t worry, this does not take up much space and does not require a reboot to install)
  12. Run a full backup on a Remote shared folder and provide a file share to use for storing the back
    1. I have a share setup on my parent partition for backing up virtual machines to when I am doing this
    2. The command that I used for this is: wbadmin start backup -backupTarget:\\Hyper-V\Backups –allCritical –include:d: –VSSfull
  13. While the backup is going you can actually jump to the next step.  Creating a new fixed virtual hard disk
  14. Open the New Virtual Hard Disk Wizard
  15. Choose to create a new fixed size virtual hard disk that is the right size for your smaller partitions
  16. Once the backup is complete, and the fixed virtual hard disk is created, shutdown the virtual machine
  17. Open the virtual machine settings and replace the dynamic virtual hard disks with the new fixed size virtual hard disks
  18. Boot the virtual machine using a Windows Server 2008 R2 installation DVD
  19. After choosing your language, choose Repair your computer (instead of clicking on Install now)    
  20. Then select Restore your computer using a system image that you created earlier and click Next
  21. Click Cancel on the warning that comes up, and then click Next followed by Advanced…
  22. Select Search for a system image on the network, followed by clicking Yes
  23. When prompted – enter the network path that you used to create the backup and click OK
  24. Select your backup from the table and click Next
  25. Select the disks you want to restore and click Next, Next, Finish and Yes
  26. The virtual machine will reboot automatically once the backup is restored

Once this is all complete, and once you have confirmed that the virtual machine is working properly, you can delete the dynamically expanding disk and the backup.

Cheers,
Ben

Categorías: Virtualización

Converting to a fixed virtual hard disk–the hard way

Jue, 29/12/2011 - 22:05
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/29/converting-to-a-fixed-virtual-hard-disk-the-hard-way.aspx';

Yesterday I showed you how to easily convert a dynamically expanding virtual hard disk to a fixed size virtual hard disk.  But, how do you do this if you want to keep your fixed size virtual hard disk as small as possible?  Well, here is the process that I use for my Windows Server 2008 R2 virtual machines:

 

  1. Login to the virtual machine using an administrative account
  2. Open Server Manager and select the Disk Management node under the Storage node.
  3. Right click on the partition that you want to shrink and select Shrink
  4. Select how much you want to shrink the partition by
    1. In my case I want to shrink a 250GB partition to 70GB:
  5. Once you have shrunk the partition(s) open Windows Server Backup inside the virtual machine (if you have not installed this – you can do so by choosing to Add Features from Server Manager – don’t worry, this does not take up much space and does not require a reboot to install)
  6. In Windows Server Backup select Backup Once…
  7. This will open the Backup Once Wizard.  There is only one choice on the first page.  On the second page choose Full server
  8. Then select to store the backup on a Remote shared folder and provide a file share to use for storing the back
    1. I have a share setup on my parent partition for backing up virtual machines to when I am doing this
  9. Complete the wizard and wait for the backup to complete:
  10. While the backup is going you can actually jump to the next step.  Creating a new fixed virtual hard disk
  11. Open the New Virtual Hard Disk Wizard
  12. Choose to create a new fixed size virtual hard disk that is the right size for your smaller partitions
    1. Here I am making a 70GB virtual hard disk for my WDS server:
  13. Once the backup is complete, and the fixed virtual hard disk is created, shutdown the virtual machine
  14. Open the virtual machine settings and replace the dynamic virtual hard disks with the new fixed size virtual hard disks
  15. Boot the virtual machine using a Windows Server 2008 R2 installation DVD
  16. After choosing your language, choose Repair your computer (instead of clicking on Install now)     
  17. Then select Restore your computer using a system image that you created earlier and click Next
  18. Click Cancel on the warning that comes up, and then click Next followed by Advanced…
  19. Select Search for a system image on the network, followed by clicking Yes
  20. When prompted – enter the network path that you used to create the backup and click OK
  21. Select your backup from the table and click Next
  22. Select the disks you want to restore and click Next, Next, Finish and Yes
  23. The virtual machine will reboot automatically once the backup is restored

Once this is all complete, and once you have confirmed that the virtual machine is working properly, you can delete the dynamically expanding disk and the backup.

Cheers,
Ben

Categorías: Virtualización

Converting to a fixed virtual hard disk–the easy way

Jue, 29/12/2011 - 01:24
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/28/converting-to-a-fixed-virtual-hard-disk-the-easy-way.aspx';

As I discussed yesterday – I have been working on converting my virtual machines from dynamic virtual hard disks to fixed virtual hard disks.  There are a couple of ways that you can do this.  The easiest way is to just convert the disks using Hyper-V.  To do this you need to:

  1. Shutdown the virtual machine (do not put it into a saved state)
  2. Open the virtual machine settings and select the virtual hard disks one at a time
  3. Click the Edit button on the settings page:
  4. This will open the edit virtual hard disk wizard with the selected virtual hard disk.  Choose the Convert option:
  5. Next, enter a file name for the new fixed virtual hard disk:
  6. Wait for the virtual hard disk to be converted (this will take a while)
  7. Change the virtual machine settings to point to the new, fixed, virtual hard disk
  8. Boot the virtual machine
  9. Once you have confirmed that everything is working properly, delete the old dynamic virtual hard disks

While this process is fairly easy to follow – it has one big drawback.  The fixed virtual hard disk will take up the maximum space of the dynamically expanding virtual hard disk.  For some of my virtual machines I had created small dynamically virtual hard disks, so this worked well.  But for some of them I had created foolishly large dynamically expanding virtual hard disks.

Tomorrow I will document the process that I used for these virtual machines.

Cheers,
Ben

Categorías: Virtualización

Time for some server maintenance

Mié, 28/12/2011 - 00:43
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/27/time-for-some-server-maintenance.aspx';

I have had a couple of days off for Christmas, and once the children were happily playing with their new presents, my mind naturally turned to some outstanding server maintenance that I needed to do.

Top of my list was completing the process of switching all of my servers over to fixed virtual hard disks.

There are two reasons why you should use fixed virtual hard disks in production environments:

  1. Performance.
  2. Avoiding oversubscription of disk space.

Given that my servers are only used by me and my family – performance is not a big concern.  And for a long time now I have been using dynamically expanding virtual hard disks for all my server virtual machines.  But recently I had a big problem.  One of my virtual machines started chewing up huge amounts of space.  The result was that my Hyper-V server ran out of space and paused all of my virtual machines (to stop any of them from crashing).  When this happened I did some emergency space management, but left most of the virtual machines still using dynamic virtual hard disks.

Converting a virtual machine from a dynamic virtual hard disk to a fixed virtual hard disk can be quite tricky.  So this week I am going to blog about some of the tips-and-tricks that I have picked up in the process of switching over to fixed virtual hard disks.

Cheers,
Ben

Categorías: Virtualización

Using “built in” applications with Windows XP mode

Jue, 22/12/2011 - 23:23
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/22/using-built-in-applications-with-windows-xp-mode.aspx';

Last week I was asked, on Twitter, if it was possible to publish a built in application (like Internet Backgammon) from Windows XP mode.  The answer is: Yes, but it is a little tricky.

Most people use Windows XP mode to run specific applications that they have that will not run under Windows 7.  These people do not want to have their start menus cluttered with all the applications that populate the Windows XP menu – they just want to access their applications.  For this reason, we block publishing of all of the built in applications in Windows XP – but you can unblock them.

To test this out – I published Internet Backgammon on one of my systems.  The process that you need to follow is this:

  1. Figure out the path and name of the executable that you want to publish.  In my case this was “bckgzm.exe” in “C:\Program Files\MSN Gaming Zone\Windows”:
  2. Then you need to open RegEdit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtual Machine\VPCVAppExcludeList
  3. Search the entries here and you should find a string value with a name of the executable (“bckgzm.exe” in my case) and a data value of the path.  Delete this key.
  4. Reboot the virtual machine.

After doing this – the application will appear in the Windows 7 start menu:

And you can run it as an integrated application:

Cheers,
Ben

Categorías: Virtualización

Why you should be using BitLocker on your servers

Jue, 22/12/2011 - 01:24
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/21/why-you-should-be-using-bitlocker-on-your-servers.aspx';

In Windows Vista we introduced “BitLocker” to Windows – a native full disk encryption technology for Windows.  Most people immediately saw the potential for BitLocker on laptops.  Encrypting your laptop meant that if you were ever unfortunate enough to lose your laptop (through theft or forgetfulness) you would not have to worry about someone else getting access to your data.

But today I would like to explain to you why you want to use BitLocker on your servers too.  All of your servers.

Recently, I had a hard disk fail in one of my servers.  This happens from time to time, and thanks to RAID it was not a big deal.  I just bought a new drive, popped out the old drive, put in the new one, rebuilt the array and I was off and running.

But now I have a problem: what do I do with the old drive?

It’s broken.  So broken that it is hard to delete the data that is on there – but there is data on there none the less.  And despite how unlikely it is that anyone will ever look at it – I am not entirely comfortable with just dropping it in the trash.  Personally, I have had the experience of connecting a broken drive that had been sitting on the shelf for a couple of months and finding that it would work for a couple of hours before failing again.  It is plausible to imagine that someone might find my old drive and hook it up just to see if it worked.

So how do I get rid of that data?

Drives these days are quite hard to destroy.  I have tried to pull them apart manually, I have hit them with a hammer, I have even driven a car over one.  They are surprisingly rugged.  You could sit magnets on them – but you won’t know how effective it has been.  Microwaving the drive should be quite good – but would probably damage the microwave as well.  Besides, there is a much simpler solution: use BitLocker.

Once you have enabled BitLocker on a server – your data is now protected, even if the disk fails.  Especially when the disk fails.  With BitLocker on you can take that failed hard disk and drop it in the bin with no concern of anyone ever getting data off of it.

Happy times.

Cheers,
Ben

Categorías: Virtualización

Creating virtual hard disks–the slow way

Mié, 21/12/2011 - 01:36
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/20/creating-virtual-hard-disks-the-slow-way.aspx';

Over the weekend I reconfigured one of my main servers.  As part of this process – I had to make some large fixed virtual hard disks (800-1600GB in size).  This took a long time…

I spent quite some a while looking at this screen…

In the past I have talked about why this takes a long time and I have also talked about a tool that is available that can make fixed virtual hard disks quickly.  So you may be wondering why I would still create virtual hard disks the slow way.

Well – there are two reasons:

  1. Support.  I know that all of our testing is done using virtual hard disks created by Hyper-V – not by any other tools.  This means that I can have high confidence in the fact that I am unlikely to have problems with these disks – and that if I do have any problems, we will fix them.
  2. Reliability. I like to know that every sector of the disk has been touched before I put it into production.  For the same reason, I always do a full (not quick) format of a disk before putting real workload on it.  I have personally had the experience of having a system where everything appeared to be fine – but creating a 200GB fixed virtual hard disk (the slow way) would cause the system to crash; which in turn revealed that there was a bug in the disk driver I was using.

In my opinion – when it comes to production systems, sometimes it is just worth taking the time to do things properly.

Cheers,
Ben

Categorías: Virtualización

Testing data protection with virtual machines

Lun, 19/12/2011 - 22:54
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/19/testing-data-protection-with-virtual-machines.aspx';

Hopefully what I am about to say is not news to you – but it is worth saying: data protection systems that have not been tested are useless.  Whether you are backing up computers, using RAID or replicating data – the first thing you need to do once you have everything setup is to test that you are actually getting the data protection you think you are getting, and that you can actually recover from a problem.

Too often, people setup data protection systems and believe everything is fine – until they need to recover lost data.  Then they discover that:

  1. They have been protecting the wrong data / not protecting the right data
  2. They do not know how to recover the data, and in the worst case scenario they make a mistake during the recovery process that results in the loss of data that was saved.

So for this reason – I always test my data protection systems.  To make sure that they are working, and that I actually know how to use them.

Ordinarily – I use a combination of Windows backup and hardware RAID1 in my home environment.  I know my hardware RAID systems like the back of my hand – and have frequently tested my backups by restoring them into a handy virtual machine (just to confirm that everything is still working).  However, recently I bought some new hard disks that did not approve of my older RAID controller.  After some thought and investigation – I decided that the easiest (and cheapest) solution would be to setup a software mirror using Windows.

The problem with this is that it has been a long time since I used software mirroring in Windows.  “Dynamic versus basic disks”, “foreign disks”, “pack IDs” are all terms that I could remember – and I could remember that it could be a little tricky.  I needed more confidence than that to trust my data to this.

Virtual machines to the rescue!

It took me about an hour to:

  1. Setup a blank virtual machine
  2. Create a two disk mirror and copy some data onto it
  3. Simulate losing and replacing a disk, and then rebuilding the mirror
  4. Simulate rebuilding the system disk and reconnecting the mirror
  5. Simulate plugging one of the mirror disks into a separate system and recovering data

All of this went well – and I was soon setting up my software mirror on hardware, with complete confidence in what I was doing.

Cheers,
Ben

Categorías: Virtualización

Linux Integration Services Version v3.2 for Hyper-V now available

Sáb, 03/12/2011 - 02:21
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/12/02/linux-integration-services-version-v3-2-for-hyper-v-now-available.aspx';

Yesterday we released a new version of the Linux Integration Services for Hyper-V.  You can download them directly from here: http://www.microsoft.com/download/en/details.aspx?id=28188

Some key changes / new features to call out are:

  • Integrated mouse support
    Yay!  This means that you no longer need to install a separate package to get integrated mouse support, and will not have to worry about the mouse being captured by the virtual machine.
  • Updated network drivers that work with the Windows 8 Developer Preview builds
    I am happy to see this – as I am running this build of Windows *everywhere* at the moment
  • Fixes the issue with SCVMM compatibility
    The problem is documented here: http://support.microsoft.com/kb/2586286 – and should not be a problem anymore.

For more details, check out the link and read the documentation.

Cheers,
Ben

Categorías: Virtualización

Hyper-V Extensible Switch in Windows Server 8

Jue, 10/11/2011 - 10:40
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/11/10/hyper-v-extensible-switch-in-windows-server-8.aspx';

Mike Neil has blogged about the Hyper-V Extensible Switch in Windows Server 8 over on the Server and Cloud Platform blog (here: http://blogs.technet.com/b/server-cloud/archive/2011/11/08/windows-server-8-introducing-hyper-v-extensible-switch.aspx).

This is something that I am actually quite excited about.  Specifically – I am really interested to see what ideas other people are able to come up with around extending the capabilities of virtual networking.

As Mike mentions – we talked about this at //BUILD/ and you can watch the recording of the session here: SAC-559T

The highlight of this session for me was the number of partners that we already have looking for ways to build in new functionality here.  Some of the partner solutions that were presented in this session include:

  • Support for the Cisco Nexus 1000V for Hyper-V, in addition to the Cisco VM-FEX extension with direct I/O (SR-IOV).
  • Inmon with their traffic capturing &analysis and their sFlow product.
  • 5Nine showed their Virtual Firewall.
  • Broadcom demonstrated a DoS Prevention extension.
  • NEC demonstrated an extension that converts Hyper-V to an OpenFlow virtual switch and integrates it with their Programmable Flow product.

And this is just the beginning of what people are going to build here.

Cheers,
Ben

Categorías: Virtualización

Friday Afternoon–hardware time

Sáb, 05/11/2011 - 00:30
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/11/04/friday-afternoon-hardware-time.aspx';

I spend far too much time in meetings these days.  But I try to keep my Friday afternoons free of meetings – and often use this time to update my various servers and try out new configurations.  Today it is time to rebuild some of my storage:

Specifically I am throwing a bunch of disks into one of my servers and setting up a storage space to play around with (you can learn more about spaces here: http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-474T).

These days I find that the most common cause of performance issues in my virtualized environments is the storage subsystem.  So I try to build systems with as much parallelism in the storage as possible – as I will be running dozens of virtual machines at the same time and a single disk just will not cut it for performance.

Cheers,
Ben

Categorías: Virtualización

Using CPU Reserve to enforce virtual processor ratio

Jue, 03/11/2011 - 19:45
//

On Monday I posted a script for configuring virtual machine CPU scheduler settings.  This script got me to thinking about another use for the virtual machine CPU reserve.

You see, it can also be used to ensure that you do not unintentionally start too many virtual machines at once.

If you were to set the CPU reserve on each virtual machine at 20% (or at 20,000 using the underlying API) then it is not possible to start extra virtual machines once you hit a ratio of 5 virtual processors for each physical processor.  This is actually what System Center Virtual Machine Manager does to enforce limits on the system.

Here is a script that will do just that:

# Function for handling WMI jobs / return values Function ProcessResult($result, $successString, $failureString) { #Return success if the return value is "0" if ($result.ReturnValue -eq 0) {write-host $successString} #If the return value is not "0" or "4096" then the operation failed ElseIf ($result.ReturnValue -ne 4096) {write-host $failureString " Error value:" $result.ReturnValue} Else {#Get the job object $job=[WMI]$result.job #Provide updates if the jobstate is "3" (starting) or "4" (running) while ($job.JobState -eq 3 -or $job.JobState -eq 4) {write-host $job.PercentComplete "% complete" start-sleep 1 #Refresh the job object $job=[WMI]$result.job} #A jobstate of "7" means success if ($job.JobState -eq 7) {write-host $successString} Else {write-host $failureString write-host "ErrorCode:" $job.ErrorCode write-host "ErrorDescription" $job.ErrorDescription} } } # Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"   # Prompt for the new CPU reservation $NewReservation = Read-Host "Specify the CPU reservation (from 0-100000)" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get all VSSDs for non-snapshots $VSSDs = gwmi "MSVM_VirtualSystemSettingData" -namespace "root\virtualization" -computername $HyperVServer | ? {$_.SettingType -eq 3} foreach ($VSSD in $VSSDs) { # Get the related VM $VM = $VSSD.getRelated("MSVM_ComputerSystem") | select -first 1 # Get the processor setting data $ProcSetting = $VSSD.getRelated("Msvm_ProcessorSettingData") | select -first 1   # Update ProcSetting with the new value $ProcSetting.Reservation = $NewReservation # Apply the changes to the processor setting data back to the virtual machine $result = $VMMS.ModifyVirtualSystemResources($VM, $ProcSetting.GetText(1)) # Process the result $successMessage = "Updated processor scheduling settings on '" + $VM.ElementName + "'" $failureMessage = "Failed to update processor scheduling settings on " + $VM.ElementName + "'" ProcessResult $result $successMessage $failureMessage }

If you run this script and specify “20000” then you will be able to run at a ratio of 5 virtual processors for each physical processor.  If you run this script and specify “25000” then you will be able to run at a ratio of 4 virtual processors for each physical processor.

Note that this will not apply to any virtual machine snapshots, or to any newly created virtual machines, so it is a little fragile as a solution.

Cheers,
Ben

Categorías: Virtualización

Diagnosing a cause of PXE boot failure

Mié, 02/11/2011 - 19:30
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/11/02/diagnosing-a-cause-of-pxe-boot-failure.aspx';

The other day I was trying to boot a virtual machine over the network using my Windows Deployment Services (WDS) Server.  This normally works fine – but for some reason I was getting nothing but errors.  Sometimes I would get a DHCP failure, other times I received varied PXE error messages:

After some investigation I stumbled on to the problem.  There was a MAC address conflict.  While Hyper-V will not let MAC address conflicts happen on a single server – but you can still have conflicts happen between multiple Hyper-V servers.  John Howard has talked about this extensively here: http://blogs.technet.com/b/jhoward/archive/2008/07/15/hyper-v-mac-address-allocation-and-apparent-network-issues-mac-collisions-can-cause.aspx

Once I realized what was happening – I quickly changed the virtual machine to use a static MAC address and set the MAC address to a unique value:

Then network installation worked fine.

Cheers,
Ben

Categorías: Virtualización

Setting VM CPU scheduler settings with PowerShell [Hyper-V]

Mar, 01/11/2011 - 03:51
//

A while ago I did a number of posts talking about the different controls that are available to you in regards to how Hyper-V schedules virtual machine processor resources (Hyper-V CPU Scheduling–Part 1, Hyper-V CPU Scheduling–Part 2, Hyper-V CPU Scheduling–Part 3 and Hyper-V CPU Scheduling–Part 4).  Today I want to share a PowerShell script that shows you how to configure these settings programmatically:

# Function for handling WMI jobs / return values Function ProcessResult($result, $successString, $failureString) { #Return success if the return value is "0" if ($result.ReturnValue -eq 0) {write-host $successString} #If the return value is not "0" or "4096" then the operation failed ElseIf ($result.ReturnValue -ne 4096) {write-host $failureString " Error value:" $result.ReturnValue} Else {#Get the job object $job=[WMI]$result.job #Provide updates if the jobstate is "3" (starting) or "4" (running) while ($job.JobState -eq 3 -or $job.JobState -eq 4) {write-host $job.PercentComplete "% complete" start-sleep 1 #Refresh the job object $job=[WMI]$result.job} #A jobstate of "7" means success if ($job.JobState -eq 7) {write-host $successString} Else {write-host $failureString write-host "ErrorCode:" $job.ErrorCode write-host "ErrorDescription" $job.ErrorDescription} } } # Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer # SettingType = 3 ensures that we do not get snapshots $SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3}   # Get the processor setting data $ProcSetting = $SystemSettingData.getRelated("Msvm_ProcessorSettingData") | select -first 1   # Get new values from the user $NewReservation = Read-Host "Specify the CPU reserve (from 0-10000) [Currently:"$ProcSetting.Reservation"]" $NewLimit = Read-Host "Specify the CPU limit (from 0-10000) [Currently:"$ProcSetting.Limit"]" $NewWeight = Read-Host "Specify the CPU weight (from 0-10000) [Currently:"$ProcSetting.weight"]"   # Update ProcSetting with the new values $ProcSetting.Reservation = $NewReservation $ProcSetting.Limit = $NewLimit $ProcSetting.weight = $NewWeight # Apply the changes to the processor setting data back to the virtual machine $result = $VMMS.ModifyVirtualSystemResources($VM, $ProcSetting.GetText(1)) # Process the result ProcessResult $result "Updated processor scheduling settings." "Failed to update processor scheduling settings."

Cheers,
Ben

Categorías: Virtualización

How many virtual processors does a virtual machine have?

Mar, 25/10/2011 - 16:17
//

A recent forum poster asked:

How do I write a script that figures out how many virtual processors a virtual machine has, when it is offline (i.e. not running)?

His question showed that he had made a classic mistake when working with the Hyper-V WMI APIs.  You see Hyper-V usually has two WMI objects for many parts of the virtual machine – one of them representing the settings and one of them representing the live object itself.

Case in hand: for a virtual processor you have “MSVM_Processor” which represents the live object, and you have “MSVM_ProcessorSettingData” which represents its settings.

Looking at the wrong object at the wrong time can cause problems.  Live objects should be used for gathering usage information about running virtual machines – settings object should be used for getting and setting configuration details.  90% of the time – the settings object is what you want (and 90% of the time it is the object that ends with the string “SettingData”).

Here is a simple script that gets a virtual machines processor count using both objects:

# Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer   # Set the stage Write-host "There are two ways to get a virtual machines processor count, the wrong way and the right way..." write-host   # Let's do the wrong way first   # Get the virtual processor objects $vProcs = $vm.GetRelated("MSVM_Processor")   write-host Write-host "Doing it the wrong way (using Msvm_Processor):" write-host write-host "The" $VMName "virtual machine is configured with" $vProcs.count "virtual processors."   # Now let's do it the right way   # SettingType = 3 ensures that we do not get snapshots $SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3} # Get the processor setting data $ProcSetting = $SystemSettingData.getRelated("Msvm_ProcessorSettingData") | select -first 1   write-host Write-host "Doing it the right way (using Msvm_ProcessorSettingData):" write-host write-host "The" $VMName "virtual machine is configured with" $ProcSetting.VirtualQuantity "virtual processors."

If I run this on a running virtual machine – both methods return the same thing:

But if the virtual machine is not running – only the MVSM_ProcessorSettingData actually tells me what I want to know:

Cheers,
Ben

Categorías: Virtualización

Running DOS fullscreen applications in Windows XP Mode

Lun, 24/10/2011 - 19:17
tweetmeme_url = 'http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/10/24/running-dos-fullscreen-applications-in-windows-xp-mode.aspx';

Here is a problem that I was asked about a while ago:

When I try to start a DOS application that switches to fullscreen in Windows XP Mode – it fails with an error that states “The video device failed to initialize for fullscreen mode.  Choose ‘Close’ to terminate the application.”  Why is this happening – and how do I fix it?

The reason why this happens is because Windows XP mode uses Remote Desktop technology for its integrated mode – and Remote Desktop does not support the video modes needed by fullscreen DOS applications.  The simplest way to make this work is to disable integrated mode.

This will get you from failure:

To success:

Cheers,
Ben

Categorías: Virtualización

Deleting a snapshot sub-tree–via PowerShell [Hyper-V]

Vie, 21/10/2011 - 18:27
//

Here is a dangerous script!  Given a virtual machine name and a snapshot name, it will delete the specified snapshot *and* any snapshots underneath it in the snapshot tree that Hyper-V manager displays:

# Function for handling WMI jobs / return values Function ProcessResult($result, $successString, $failureString) { #Return success if the return value is "0" if ($result.ReturnValue -eq 0) {write-host $successString} #If the return value is not "0" or "4096" then the operation failed ElseIf ($result.ReturnValue -ne 4096) {write-host $failureString " Error value:" $result.ReturnValue} Else {#Get the job object $job=[WMI]$result.job #Provide updates if the jobstate is "3" (starting) or "4" (running) while ($job.JobState -eq 3 -or $job.JobState -eq 4) {write-host $job.PercentComplete "% complete" start-sleep 1 #Refresh the job object $job=[WMI]$result.job} #A jobstate of "7" means success if ($job.JobState -eq 7) {write-host $successString return $true} Else {write-host $failureString write-host "ErrorCode:" $job.ErrorCode write-host "ErrorDescription" $job.ErrorDescription return $false} } } # Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine"   # Prompt for the name of the snapshot to delete the tree from $SnapshotName = Read-Host "Specify the name of the snapshot to delete the tree from (warning - a lot of snapshots will be deleted)" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer   # Find the snapshot that we want to delete $Snapshot = gwmi -Namespace root\virtualization -Query "Associators Of {$VM} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData" | where {$_.ElementName -eq $SnapshotName} | select -first 1   # Delete the snapshot $result = $VMMS.RemoveVirtualSystemSnapshotTree($Snapshot)   # Check to make sure we succeeded $deleteSucceeded = ProcessResult $result "Deleted snapshot tree." "Failed to delete snapshot tree."

Note that this script actually uses a different WMI method to delete the snapshot sub-tree (when compared to deleting a single snapshot).  There is no way to stop the deletion once it is started, and there is no confirmation prompt in this script – so be careful when you use it!

Cheers,
Ben

Categorías: Virtualización

Deleting a snapshot–via PowerShell [Hyper-V]

Jue, 20/10/2011 - 18:56
//

Here is a script that will allow you to delete a single snapshot from a Hyper-V virtual machine:

# Function for handling WMI jobs / return values Function ProcessResult($result, $successString, $failureString) { #Return success if the return value is "0" if ($result.ReturnValue -eq 0) {write-host $successString} #If the return value is not "0" or "4096" then the operation failed ElseIf ($result.ReturnValue -ne 4096) {write-host $failureString " Error value:" $result.ReturnValue} Else {#Get the job object $job=[WMI]$result.job #Provide updates if the jobstate is "3" (starting) or "4" (running) while ($job.JobState -eq 3 -or $job.JobState -eq 4) {write-host $job.PercentComplete "% complete" start-sleep 1 #Refresh the job object $job=[WMI]$result.job} #A jobstate of "7" means success if ($job.JobState -eq 7) {write-host $successString return $true} Else {write-host $failureString write-host "ErrorCode:" $job.ErrorCode write-host "ErrorDescription" $job.ErrorDescription return $false} } } # Prompt for the Hyper-V Server to use $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine"   # Prompt for the name of the snapshot to delete $SnapshotName = Read-Host "Specify the name of the snapshot to delete" # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer   # Find the snapshot that we want to delete $Snapshot = gwmi -Namespace root\virtualization -Query "Associators Of {$VM} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData" | where {$_.ElementName -eq $SnapshotName} | select -first 1   # Delete the snapshot $result = $VMMS.RemoveVirtualSystemSnapshot($Snapshot)   # Check to make sure we succeeded $deleteSucceeded = ProcessResult $result "Deleted snapshot." "Failed to delete snapshot."

Cheers,
Ben

Categorías: Virtualización