Link to home
Start Free TrialLog in
Avatar of Mr.X
Mr.X

asked on

reclaim unallocated space from vm to hyperv

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.
User generated image
Avatar of Member_2_231077
Member_2_231077

Is it thin or fixed provisioned virtual disk?
Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Create a new VM of correct size, and CLONE it to the new disk!
Avatar of Mr.X

ASKER

Hi,
How do I find is it thin or fixed ?
Avatar of Mr.X

ASKER

Type- dynamically expanding virtual harddisk
ASKER CERTIFIED SOLUTION
Avatar of Member_2_231077
Member_2_231077

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr.X

ASKER

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.
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.
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.
Avatar of Mr.X

ASKER

Ok. I will give it. A try and will let you in few hours how it goes .
Thank you for this idea
Avatar of Mr.X

ASKER

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 ?
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.
Avatar of Mr.X

ASKER

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
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.
Avatar of Mr.X

ASKER

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
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.
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.
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