We help IT Professionals succeed at work.

reclaim unallocated space from vm to hyperv

208 Views
Last Modified: 2020-10-11
hi got a sbs2011 as virtual machine.  i got 17gb space as unallocated in that vm.
if i want to reclaim that space back to my hyperv volume. how do i do it ?
i tried, shutting down my virtual machine. from hyperv manager, on that vm, went settings and did compact on the disk. but it does not seem to be doing anything. could not reclaim that space back.
unallocated.PNG
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Is it thin or fixed provisioned virtual disk?
Andrew Hancock (VMware vExpert PRO / EE Fellow)VMware and Virtualization Consultant
CERTIFIED EXPERT
Fellow
Expert of the Year 2017

Commented:
Create a new VM of correct size, and CLONE it to the new disk!

Author

Commented:
Hi,
How do I find is it thin or fixed ?
Andrew Hancock (VMware vExpert PRO / EE Fellow)VMware and Virtualization Consultant
CERTIFIED EXPERT
Fellow
Expert of the Year 2017

Commented:
look at disk settings

Author

Commented:
Type- dynamically expanding virtual harddisk
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Ok.
My problem is
Volume in hyper v- got 22.1 gb free of 600gb(has only vhdx file for this particular vm)
If I go into virtual machine - it shows 143gb free of 582 and 17gb is unallocated

It tried compacting, hyper v did not reflex the same free space as vm says. Tried shrink, and got 17 gb as unallocated.
Now how do i bring back remaining free space from vm to hyperv ???
Tried defrag- it started reducing the space in hyperv drastically, so had to stop it in middle.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You can use sdelete on the virtual machine to zero-fill any unused space, then Hyper-V can claim it back by compacting. When you create a file and then delete it again the space is still filled with data, Windows only deletes the file entry from the file allocation tables.

https://redmondmag.com/articles/2017/08/30/shrink-hyperv-virtual-machine-volumes.aspx

Alternatively if you do not need to create another VM you can just leave it, the VM knows it has lots of space even if it is not zero-filled.
Never defrag a thin provisioned disk, as you have seen it fills it up.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
BTW, the 17GB also has "data" on it still, to get that back you create D: on it and run sdelete on that to zero-fill it so Hyper-V knows it is unused.

Author

Commented:
Ok. I will give it. A try and will let you in few hours how it goes .
Thank you for this idea

Author

Commented:
Hi,
Am using the sdelete-z c:
It had 145 gb free in my c drive in vm
But it finished 75% and c drive came to 45gb free. I thought it will increase free space, but it's decreasing it. Am afraid it will run out of space before it completes  100%
Or is this normal ?
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
sdelete/sdelete64 creates a gigantic file full of zeroes, then deletes it. as far as the VM is concerned it fills the entire hard disk but since it is just zeroes it takes no extra space on the hyper-V virtual disk. I think the path to the temporary file is c:\users\<name>\appdata\local\temp\sdeltemp1 so you can just delete that file on the VM if you stopped it part way through.

Author

Commented:
Ya. Actually when the process got over, the vm got close to 200 gb free space, but the hyperv volume got only 22gb.
I tried compacting as well, it did not bring back any free space
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You have to clear down the 17GB unallocated by assigning a drive letter D: to that and running sdelet64 on D: to zero that out as Hyper-V still sees that as data.

Author

Commented:
ya i will try that now in next few mins.
but still c drive in vm shows approx 200gb free after running sdelete, but still when i try to shrink, it comes as 0mb to shrink. and even if i try to compact from hyperv, it does not bring any free space to hyperv volume.

i tried as u told, had 17gb as unallocated. assigned letter"d" . ran sdelete. now if i shrink, it gives 15gb as unallocated. got 2gb as drive"d"(before doing this process, i had 17gb as unallocated, ) anyway. evern after doing that. if i do compact from hyperv, no change, still hyperv volume in is same 20gb free space
Philip ElderTechnical Architect - HA/Compute/Storage
CERTIFIED EXPERT

Commented:
With the 17GB of free space shut the VM down and use Hyper-V Manager to EDIT the disk. It should allow you to shrink the VHDX file by at least a portion of that amount

The other alternative is to use the backup to restore the VM to a new VHDX file that is dynamic.

Just don't over provision the host's storage.

EDIT: Oh, and don't forget to have a known-good backup before touching the virtual hard disk.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Windows shrink isn't that clever, if you use an offline tool such as BootitBM or gparted from a virtual CD (or even another Windows instance with this mounted as additional drives) you can really shrink C: properly because it is offline and no files are locked open and unmovable.
Seth SimmonsLead Systems Administrator
CERTIFIED EXPERT

Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: 'andyalder' (https:#a42867131)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions