?
Solved

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

Posted on 2014-04-09
3
Medium Priority
?
4,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
Tony Giangreco earned 2000 total points
ID: 39990423
0
 
LVL 59

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

800 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