Repair a VHD from snapshot

When you are a system administrator working on an environment with virtual computers and servers, you probably have to enlarge the size of a virtual hard disk sooner or later. In this case, I’m writing about something specific for Microsoft Hyper-V.

When you want to resize a virtual hard disk, you have to make sure the virtual computer using this disk doesn’t have any snapshots. Normally Hyper-V will warn you for this and tries to make sure you aren’t able to resize the disk. But when you shut down the virtual computer and you edit the VHD with the wizard to edit any virtual hard disk, you might have a chance to resize the VHD while there still is a snapshot linked to the virtual computer.

I managed to do that. But when I tried to start the virtual computer it showed me an error about the VHD’s size not matching the size for the snapshot. I thought I had made it corrupt and that the data was inaccessable for ever. A snapshot also holds data on how large the VHDs attached to the virtual computer are. And when you start the computer, it will check on those sizes. When they don’t comply, you’ll receive that error. And the worst part is, you can’t size a VHD down with the wizard in Hyper-V!

So, how can you fix this without losing any data previously on the VHD? There is a certain tool, a very handy one: VhdTool. It is also hosted by Microsoft, so it should also be a safe tool to use. With this, you can repair a VHD’s size to the size of a snapshot of that VHD. But be warned, sizing down can make data corrupt on the disk. But in this case, no data had been added to the disk. So we could size it down in peace to it’s previous size. After that, the virtual computer started without errors and was running again.

So, if you want to size up a VHD, make sure it isn’t used by any computers with a snapshot! If so, then first remove the snapshot before resizing. You can always make a new snapshot afterwards. If you have forgotten this, then you be sure to remember the VhdTool.

Leave a Reply

Your email address will not be published. Required fields are marked *