Handling VHD Files

Writing previous post I had so many advices on handling the VHD files I’d like to share, I had to put them down too. But it’s a subject that deserves an article of it’s own. Since VHD files are usually very large files they require special treatment.

About VHD files

VHD Files represent an image of virtual hard drive on a sector-by-sector basis. They store raw sectors of data just like physical disk drives. They can contain boot sector, partitions and everything that regular physical drives can.

One can imagine a virtual disk drive as an external USB disk drive. It’s just not made of metal, silicon and plastic but is made of one single file.

VHD file to hard drive is like ISO image to a CD-ROM medium. Because VHD file has same properties as physical drive it can replace it in many applications.

Storing VHD files

VHD files must be stored on NTFS partitions, since they can grow really big. Nothing more to discuss about here. If we want to use undo disk feature, the drive on which the Windows is installed also need to be NTFS.

Fixed-sized or Dynamically expanding

A word of advice: Use fixed-sized VHDs for disks that will contain operating systems or other frequently changing content of predictable maximum size.
Use dynamically expanding VHDs for storage of less frequently modified data or data of less predictable size.

Second word of advice: Forget the advice above. You can always convert from one form to another, so the first choice doesn’t need to be the final one.

Fixed-sized VHD is faster, providing it is contiguous. We’ll discuss defragmentation next.
The only drawback of a fixed-size VHD is it occupies the entire space it emulates. It doesn’t matter what you write on it, the fixed-size VHD file is always of it’s maximum size.

On the other hand dynamically expanding VHD file comprise of only non-empty sectors. Only the sectors that gets changed/written to are stored. It basically prevents empty sectors to initially occupy space in VHD file. Alas, the sectors once written to, remains in VHD even if you empty them later. Sooner or later the VHD file will grow enough to consider converting it to fixed-sized one, since the size benefit will diminish.
Dynamically expanding VHD’s can be compacted, but it’s a lengthy process and requires the VHD file to be offline.
Dynamically expanding VHD’s performance is lower than fixed-sized’s.

Defragmentation of VHD file

To achieve maximum performance of fixed-sized VHD you should always defragment it. Since it doesn’t grow or shrink in time, once contiguous, it stays contiguous. In my experience Microsoft Virtual Server and VirtualPC take ages to create new fixed-sized VHD and usually a heavily fragmented one too. I recommend you defragment it before use.

The defragmentation of dynamically expanding VHDs is futile. It has inherent internal fragmentation, so if you defragment it or not, doesn’t affect performance much.

NTFS Compression of VHD files

Never!

VHD files are usually very big ones and NTFS has problems compressing big files. You risk “Delay write failed” system errors. Besides, NTFS compression is suitable only for the files that don’t change often, which is not the case for the VHD files used by live virtual computers.

Mounting with Undo Disk Enabled or Disabled?

Undo disk feature has it’s performance penalty and should be used selectively.

Undo disk is nothing but another (differencing) VHD file mounted on top of the one we are mounting. This way we get a stack of two or more drives appearing as one. All changes are written to the top drive in the stack only, and the drives below it remain intact.

If you don’t like, what you just did to your drive stack at some point, you can easily detach undo disk and delete it. If you agree with your changes, you can finish your session and choose to merge the undo disk with the second drive in stack.

Yes I intentionally used plural. It is possible to mount more differencing drives in a stack to achieve more checkpoints to return to.

Leave a Reply

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