Posey's Tips & Tricks

The Biggest Mistake I Ever Made With Hyper-V

Let my blunder be a learning opportunity. Also, don't forget your backups!

Although most IT pros strive for perfection, we all make mistakes once in a while. Sometimes those mistakes are harmless, teachable moments. Other times Murphy's Law rears its ugly head and a seemingly simple mistake leads to a really bad day. That's what happened to me a while back when I tried doing something really simple and routine with a Hyper-V virtual hard disk, but overlooked one important detail. Thankfully I had a backup. But if a backup hadn't been available, my mistake would have likely led to data loss.

So what happened? It all goes back to a handy feature that I use all the time:  virtual hard disk portability.

Every Hyper-V virtual machine is equipped with a virtual hard disk. This virtual hard disk is accessible from outside of the virtual machine. In fact, you don't even have to have Hyper-V installed in order to do it. Windows can natively mount a Hyper-V virtual hard disk (a VHDX file) and use it as though it were a physical hard disk connected to the system. Let me give you an idea of why this capability is useful.

Recently I was preparing to leave for a trip. Because of what I was going to be working on during my travels, I knew that I was going to need to have some video files with me. Copying these files across my network to a portable hard drive would have been a very slow process. What I did instead was to attach a drive containing an air gapped backup to my PC. That drive essentially just contained copies of the Hyper-V virtual hard disks that I use on my production network. Once the physical disk was up and running, I right clicked on the virtual hard disk containing the files that I needed and selected the Mount command from the Windows shortcut menu. This caused the disk to be mounted and made its contents accessible. I was then able to copy the files from the virtual hard disk to a portable hard disk without having to worry about network latency. That's the way that virtual hard disk portability is supposed to work.

Even though I regularly mount virtual hard disk files to make them accessible outside of the virtual machine, the process can go horribly wrong. As previously mentioned, I once made a mistake that could have led to catastrophic data loss. On that day, I mounted a virtual hard disk file in the same way that I always do. The mistake that I made was forgetting that checkpoints existed for the virtual machine.

When you create a checkpoint in Hyper-V, Hyper-V actually creates a differencing disk. This differencing disk has a parent/child relationship with the virtual hard disk. All future write operations are directed to the differencing disk (for as long as the checkpoint exists), leaving the original virtual hard disk in a pristine state.

The problem with these differencing disks is that Windows does not know how to deal with them outside of Hyper-V. When you mount a VHDX file in Windows (outside of Hyper-V), Windows only knows about the one file that you are trying to mount. It has no idea that there are checkpoint components (namely differencing disks) associated with the virtual hard disk. So remember what I said earlier about checkpoints rendering the original virtual hard disk read only? When you mount a virtual hard disk that has checkpoints associated with it and you perform any write operations whatsoever, it will break the relationship between the VHDX file and the checkpoint files. The next time that you attempt to use the disk with Hyper-V, it will be corrupt.

So how can you fix this sort of problem? The best option is usually to restore a backup. If no backup exists, then there may be one more option.

Open the Hyper-V Manager and select the virtual machine that needs to be repaired. Now, click the Inspect Disk link, found in the Actions pane. This will cause Hyper-V to prompt you to choose a virtual hard disk to repair. Rather than selecting the VHDX file, choose a differencing disk (an AVHDX file). If Hyper-V detects that checkpoint chain has been broken then this dialog box will display a Reconnect button that you can click to fix the problem. Now, just follow the prompts to select the parent virtual disk and click Finish. Your virtual hard disk should be returned to a functional state.

About the Author

Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.

Featured

comments powered by Disqus

Subscribe on YouTube