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:
- Login to the virtual machine using an administrative account
- Run diskpart
- Check your disks with list disk
- Select the disk you want to shrink (disk 0 in my case – so select disk 0)
- Check your partitions with list partition
- Select the partition you want to shrink (partition 4 in my case – so select partition 3)
- Check how much space you can save with shrink querymax
- 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)
- Check that you are happy with the new size with list partition
- Exit diskpart with quit
- 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)
- Run a full backup on a Remote shared folder and provide a file share to use for storing the back
- While the backup is going you can actually jump to the next step. Creating a new fixed virtual hard disk
- Open the New Virtual Hard Disk Wizard
- Choose to create a new fixed size virtual hard disk that is the right size for your smaller partitions
- Once the backup is complete, and the fixed virtual hard disk is created, shutdown the virtual machine
- Open the virtual machine settings and replace the dynamic virtual hard disks with the new fixed size virtual hard disks
- Boot the virtual machine using a Windows Server 2008 R2 installation DVD
- After choosing your language, choose Repair your computer (instead of clicking on Install now)
- Then select Restore your computer using a system image that you created earlier and click Next
- Click Cancel on the warning that comes up, and then click Next followed by Advanced…
- Select Search for a system image on the network, followed by clicking Yes
- When prompted – enter the network path that you used to create the backup and click OK
- Select your backup from the table and click Next
- Select the disks you want to restore and click Next, Next, Finish and Yes
- 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
from Virtual PC Guy's Blog http://blogs.msdn.com/b/virtual_pc_guy/