Solved

Compact Linux guest virtual hard disk

Posted on 2013-12-14
9
3,763 Views
Last Modified: 2013-12-22
Hi,

The situation: Windows Server 2012 Hyper-V host, with mixed CentOS 6.4 and Server 2012 guests.

What I'm trying to do: compact the virtual image of a CentOS VM, named XXX, with a vhdx of 43GB.

What I did:
Shut down the VM, booted SystemRescueCD 3.8.1.
Used pvscan to get logical volume information.
Changed /dev/mapper/vg_XXX-lv-root to active:
vgchange /dev/mapper/vg_XXX-lv-root -a y

Ran zerofill -v /dev/mapper/vg_XXX-lv-root
Ran zerofill -v /dev/mapper/vg_XXX-lv-home

Both successful.

Shut down the VM, then tried to compact it using Hyper-V Manager. No effect whatsoever. The vhdx is still at 43GB.

Any ideas what I did wrong and/or how I can successfully compact that VM?

Thanks.

Below you have the disk space usage, as reported by df -h. As you can see, the real space usage is at around 11GB.
Actual disk usage
0
Comment
Question by:Dan Craciun
[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
  • 4
  • 3
9 Comments
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39720655
Can you try the following method for zeroing out inside the guest?

cat /dev/zero > /tmp/zero.out
sync && rm /tmp/zero.out

Open in new window

0
 
LVL 35

Author Comment

by:Dan Craciun
ID: 39720788
Thank you for your reply.

Tried your commands. Still no effect after compact.

Which is strange. Creating the zero.out file should have increased the vhdx size, but that did not happen...
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 0 total points
ID: 39724941
OK, after about 8 hours of searching and testing, I found a solution.

Looks like the compact function in Hyper-V manager has problems with Linux guests.

I managed to compact the vhdx from Powershell, using:

Mount-VHD -Path X:\path\to\file.vhdx -ReadOnly
Optimize-VHD -Path X:\path\to\file.vhdx -Mode Full
Dismount-VHD -Path X:\path\to\file.vhdx

Open in new window

Took about 3 minutes and reduced the size from 43 GB to 18GB.

Tried -Mode Quick too, but with no results.

I posted this so the next person that has the same problem can save him/her self some time.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 21

Expert Comment

by:Mazdajai
ID: 39725090
Good to know! Are you running 2012 R2? May be this is the reason I couldn't reproduce this in my lab.
0
 
LVL 35

Author Comment

by:Dan Craciun
ID: 39725126
Nope. Plain 2012. Will upgrade probably in March-June. Don't like being an early adopter\beta tester on production servers.

A tricky one to be sure. Still don't know why -Mode Quick did not work.

I even spent about 2 hours in a hex viewer, mapping the vhdx. I could see where the partitions ended, huge 0 filled blocks and some 11 GB of pure 0's at the end of the file, and still compact did not work.

Weird, but at least I found a solution.
0
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 100 total points
ID: 39725495
You have done a great job on narrowing this down.

R2 is typically a stable release. The current build number is 9600 and they will continue to be updated. There are updates made in VHDX resizing in Windows 2012 R2, I would suggest testing in R2 and see if this issue has been resolved.
0
 
LVL 35

Author Closing Comment

by:Dan Craciun
ID: 39734480
Had to do a lot of research to get around what I can only call "a bug" in Hyper-V compacting routines.

Thanks Mazdajai. Will try in R2 to see if the problem is solved.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

751 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