?
Solved

Compacting dynamic VHD

Posted on 2015-01-06
16
Medium Priority
?
143 Views
Last Modified: 2015-01-25
Hey guys

Ok, this one has me stumped. Host is Hyper-V 2012 R2 server.  Guest server is Server 2008 R2 with Dynamic VHD.  I was able to install software that would defragment the drive and optimize it by moving all the files that were near the end of the drive to be closer to the beginning.  Looked great.  Then I thought I should go ahead and try and shrink the drive (within the guest OS).  It shrunk down to about 200 gigs (which is where I wanted it to be.. vs. 300 gigs).  So I am sitting here all happy and decided to try and compact the drive.  The actual contents of the drive were only taking up about 90 gigs so I estimated that the compact should knock it down to about 100 or so gigs.  The VHD file was sitting at 234 gigs.  I started the compacting (with the guest shut down of course) and after about an hour it finished with no errors... but also no shrinkage at ALL.  The vhd was still sitting at 234 gigs.  I went thru the error logs and could not find ANY errors.

Any ideas?
0
Comment
Question by:jonmenefee
[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
  • 8
  • 5
  • 3
16 Comments
 
LVL 39

Expert Comment

by:Philip Elder
ID: 40534891
0
 
LVL 37

Expert Comment

by:Mahesh
ID: 40534993
You can try below.
Start elevated PowerShell prompt on Hyper-V server and run below commands
Mount-VHD -Path D:\VM\OS.vhdx -ReadOnly
Optimize-VHD -Path D:\VM\OS.vhdx -Mode Quick
Dismount-VHD D:\VM\OS.vhdx

Open in new window

0
 

Author Comment

by:jonmenefee
ID: 40542210
Thanks guys,  For some reason I did not get notified until today about these answers.  I will try them tonight and let you guys know which one worked for me :-)
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Accepted Solution

by:
jonmenefee earned 0 total points
ID: 40559667
Well, I tried both but neither was what I was looking for unfortunately.  Mahesh's works for VHDX files, mine are VHD so I had to get a third party software that's not even published in English anymore called VHD-Resizer.  I had to find the link here in Experts-Exchange.

Phillips suggestion was good and would probably work on Dynamic VHDs but since there were no Switches to make a minimum size (I didn't want to compact it down to where the drive has zero bytes of free space) I didn't want to take a chance.  

Anyways
I went with the third party software and it worked great
0
 
LVL 39

Expert Comment

by:Philip Elder
ID: 40559694
What product did you use?
0
 
LVL 37

Expert Comment

by:Mahesh
ID: 40560462
I don't see any issue with VHD file with same cmdlet

Have you tried the cmdlet with VHD file?

http://technet.microsoft.com/en-us/library/hh848458.aspx
0
 

Author Comment

by:jonmenefee
ID: 40560478
I just went to that website and it refers Only to dynamically expanding hard drives. I have a Fixed VHD that I need to shrink
0
 
LVL 39

Expert Comment

by:Philip Elder
ID: 40560530
But the original question says "DYNAMIC"?
0
 
LVL 37

Expert Comment

by:Mahesh
ID: 40560549
If the disks are not dynamic then above cmdlet won't work
In case of fixed disk, then what you got is right (VHD-Resizer)
0
 

Author Comment

by:jonmenefee
ID: 40560570
Yeah. Sorry about that. I should have specified that a little more clearly
0
 

Author Comment

by:jonmenefee
ID: 40560586
Hello Phillip
you are correct. When I first started tackling this I had a dynamic vhd with the Hyper-V settings of 300 gigs as being the largest it would grow.  Unfortunately I moved it to a 256 gig mirrored VHD and as long as it didn't grow I was fine but then it grew to 250 gigs with lots of blank space.  So I tried compacting it and I could never get it compacted. Turns out I should have gotten a better disk defragmenter. Anyways. I changed it to a fixed disk in the hopes of then compacting it. I will now use the vhd resizer to do that
0
 
LVL 39

Expert Comment

by:Philip Elder
ID: 40560637
Make sure your backups are good.
0
 

Author Comment

by:jonmenefee
ID: 40560680
I will shutdown the machine. Copy the VHD to another area and then run the vhd - resizer on the original file

:-)
0
 
LVL 39

Expert Comment

by:Philip Elder
ID: 40561949
Okay. I've not used the tool in all my years working with Hyper-V. If the backups are _not_ tested then approach this process with caution.
0
 

Author Comment

by:jonmenefee
ID: 40562020
I will. Thanks. :-)
0
 

Author Closing Comment

by:jonmenefee
ID: 40568991
Here is the link to the right software solution, it is posted here in Experts-Exchange

http://www.experts-exchange.com/Software/Virtualization/Q_28139514.html
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
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…
In this video tutorial I show you the main steps to install and configure  a VMware ESXi6.0 server. The video has my comments as text on the screen and you can pause anytime when needed. Hope this will be helpful. Verify that your hardware and BIO…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

801 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