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
Solved

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

Posted on 2014-04-09
3
3,759 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 57

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell script 9 64
Windows 10:  Delay in entering RDP credentials 19 26
Veeam Replication vs. SRM for DR scenario ? 6 73
Extend AD schema for SCCM 2012 3 27
It Is not possible to enable LLDP in vSwitch(at least is not supported by VMware), so in this article we will enable this, and also go trough how to enabled CDP and how to get this information in vSwitches and also in vDS.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

838 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