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

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
    image
  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
      image
  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