• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4665
  • Last Modified:

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

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
binovpd
Asked:
binovpd
1 Solution
 
Tony GiangrecoCommented:
0
 
Cliff GaliherCommented:
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
 
binovpdAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now