Solved

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

Posted on 2014-04-09
3
4,056 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 500 total points
ID: 39990423
0
 
LVL 58

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

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

728 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