Solved

Proper steps to compact a hyper-v VHD without bringing down live VM.

Posted on 2014-04-09
3
3,495 Views
Last Modified: 2014-11-12
Hi all,

I have a hyper-v 2008 R2 hyper-v host with some VM's that are dynamic disks. Some of them have grown to the point where our backup is failing because its exceeding the capacity of the tape.

I know the general proper process to compact a VHD is to
1. Defrag the VM
2. zero out empty space with a utility like sdelete or precompact.exe
3. compact within the VM manager edit disk or to use diskpart. (I think diskpart will be faster?)

Since these are live VM's I don't want to bring them down for too long. I was thinking I could take a of copy the VHD's and put them on another machine, Mount the VHD as a drive and perform the steps above. Then I would remove the old VHD on the production server and copy over the compacted VHD.

What Im not sure about, is whether it is ok to run defrag and sdelete on the mounted VHD or whether its preferable to run that within the VM itself?

Lastly does the machine where I mount the VHD's need to be the same OS and have hyper-v installed? For example if I copied the VHD to a windows 7 machine and mounted for these steps would that cause a problem when I restore it back on the server 2008 hyper-v server?
0
Comment
Question by:binovpd
3 Comments
 
LVL 25

Accepted Solution

by:
Tony Giangreco earned 500 total points
ID: 39990423
0
 
LVL 56

Expert Comment

by:Cliff Galiher
ID: 39990430
I don't think you'll be able to accomplish what you want here. You want the VM to be up as much as possible, which inherently means it is offering service or data that needs availability and the VM will be doing reads and writes (which are all tracked and journalled by Windows, even if the journals are flushed regularly.)  By taking a copy of the VHD and working with it offline, when you "swap out" the VHDs later, you are regressing and Windows *will* notice the issue. At best you have data loss, and far worse is possible.

In essence, you are asking a pilot to stop a plane so you can perform maintenance. Except the plane is in flight. Forward momentum is essential to the plane staying airborne because of aerodynamics and such, and you can't stop or the plane falls out of the sky. The two are intrinsically linked.

Even if you take Hyper-V out of the equation, this is still true. There are servers that support hot-swappable drives, but you can't just take out an old drive, clone it to a larger drive, and plug the new drive in and expect things to work. You have to work with the partitions *on* the machine it is running on, or you have to replace a failed drive in a RAID array with a working drive and let the array rebuild...again, on the machine it is running on. Messing with drives or data while they are offline will almost assuredly kill the partition or prevent a RAID array from rebuilding. Hot-swap drives don't change the basic nature of this. Hyper-V just virtualizes the storage, but doesn't  change the underlying behavior of how Windows responds to disk changes.

Your best path here is to announce a maintenance window for each VM (all at once or individually) and bring them down and work with the virtual drives with the VM in a powered off state. It is the only safe way to work with the data.
0
 

Author Closing Comment

by:binovpd
ID: 39995635
Thanks for the input guys. I do have one last question. I've been using Diskpart to compact vhd's after defrag and sdelete. Its worked fine, but I have a vhd that hangs at 90% and I think its because the vhd actually contains two partion not one big drive.

After I do the following:

DISKPART> select vdisk file=c:\vhd\my.vhd

DiskPart successfully selected the virtual disk file.

DISKPART> attach vdisk readonly

usually I would do:

compact vdisk

But if the vhd has two partitions within (volumes) do I need to specify the volume like this instead:

compact volume 0 etc.?
0

Featured Post

How does your email signature look on mobiles?

Do your employees use mobile devices to reply to emails? With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices.

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now