Hyper-V, PowerShell, Tips

Resizing VHDX in Windows 2012 using PowerShell

In order to be able to resize the VHD you need to follow few steps first. You can do that from the GUI, however in my experience your best rate of success is to use the PowerShell. Please note that this apply only to Hyper-V in Windows 2012 and above, there isn’t a process available yet for the previous versions of Hyper-V

Below are the steps of how to do that, just as an explanation in order to be able to resize the VHD we need to resize the partition inside the Virtual machine, as to let the vhd file know that this space is free and its safe to remove it.

The command below will provide all the steps required to resize the vhd, however it requires the server to be shut down. The steps are as follow:

1. Shut down the VM

2. Mount the VHD using mount-vhd command with command line as follow:

mount-vhd path\drive.vhdx -passthru | get-disk | get-partition | get-volume

This command will provide you with information of what drive letter the partitions inside vhdx files have been assigned as well as the size details (remember that from Windows 2008 and up the system create a 100-300MB partition on the main drive used in booting process, don’t resize it)

3. The next command is resize-partition, that is to resize the size of the partition inside the vhdx to the size you want it to be

resize-partition –driveletter E -size 35GB

-driveletter is the drive letter we get from the first command, and –size is the size to what we want to shrink the partition to.

4. Next we will dismount the vhd using dismount-vhd:

dismount-vhd path\drive.vhdx

5. The last command is actual resizing of the VHD, to do that we use: resize-vhd command:

resize-vhd path\drive.vhdx -ToMinimumSize
Hyper-V

Networking on Hyper-V

When you install Hyper-V role and assign the network cards you will noticed that your host will have doubled the number of the network cards. The reason behind that is that Hyper-V create Virtual Switch that takes over the Physical NIC and then create Virtual NIC on your host and assign all the static IP setting to it. Now it’s not a mayor problem 99% of the times, but the issue I came across was a bit unusual and had to go through number of steps to recover from it. Just to point out the advise solution was to reinstall the Windows and Hyper-V that couldn’t be done :). The issue that happen to my server was that I had one NIC on DMZ and other on LAN. You could work generally but if you would like to access any of the LAN resources it would time out or would take ages to get to. I tries the routing table but that haven’t fixed the problem. Now because that disabling the Virtual NIC connected to DMZ wouldn’t fix the issue. The steps I had to take were following:

  1. Remove the Networks from Hyper-V
  2. Remove the Physical NIC from within Device Manager
  3. Restart the system
  4. Add the networks back to Hyper-V
  5. Disable DMZ Virtual NIC

Although it seam to be very straight forward solution it took me some time to get around to it. So I hope it will help you to get quicker to it 🙂

Just to say as well Microsoft have still a lot to do with Hyper-V (there is already 2.0 Beta) but they managing to close the gap to the market leaders quickly. There are still areas that they have to work on, but generally their product is stable and works very well in most environments just from time to time you have to do stuff in a bit awkward way but the result will be achieved.

Hyper-V, Setup

Migration from VPC to Hyper-V

The Hyper-V is the next generation of the VPC from Microsoft, it have fixed number of issues that the previous version had like lack of x64 support. The Hyper-V at the moment is only available on Windows 2008 Servers as one of the roles.

The biggest advantage for Administrators is the fact that hyper-v use the same .vhd files for virtual machines hard drives. That mean that migration from VPC to Hyper-V is much quicker, below are some steps on how to do that in best way. Just to point that solution is for Windows 2003 R2.

  1. Firstly, you need to record the TCP/IP information from each of your VM’s to migrate, as you’ll need to reconfigure the NIC from scratch a bit later;
  2. When you’ve record the TCP/IP information, you should uninstall the Virtual Machine Additions from the guest operating systems – This is a fairly important step, as I’ll explain further on; Continue reading “Migration from VPC to Hyper-V”