resize vhd

jonnyhotchkiss

New member
Member
VIP
Local time
2:20 PM
Messages
260
Hi, I'm trying to reclaim space, after shrinking my (native) V-OS Windows 7 VHD (from 90GB to 30GB, still 3.5 free space)

the (diskpart) shrink worked, leaving me with a nice healthy, active 24g partition... and 75g unallocated.

The consensus seems to be vhdresizehttp://www.howtogeek.com/50399/how-to-resize-a-microsoft-virtual-hard-drive-vhd-file/, but I (currently) have to complete the 'final step' of the resize vhd (file) operation outside the V-OS (it seems... VHDresizer won't
u9aG76f.png
... I'm guessing vhdresizer 's GUIs gonna crashNburn from a pureDOSesque startup/recovery console {currently win7 boot disc is my method, looking for a lightweight boot entry to add to bootmenu, for 'vhd mgmt', ie vhd resizer..}

read all on diskpart, still no clue on 'direct method' on handling unallocated space, ie to enable vhdresize to "finish it's task" (25g VHD "volume" is still actually a 99g VHD file on a 200 gig partition)

Closest I've got is ref to compact command in PowerShell-context, re 'dual-command' to shrink then compact...
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Dell
OS
Windows 7 Ultimate 64bit
CPU
2.2
Memory
8Gb
Graphics Card(s)
NVIDIA
Screen Resolution
1280/762
Mouse
built in pad || iphone || MS wireless
Internet Speed
100MB
Antivirus
Avast
Browser
Chrome, Chrome portable
found this

Steps to Shrinking VHD File
There are a number of steps to shrinking the VHD. The script performs these steps, but for clarity I will list them here as well. You could perform these steps manually as well, if you choose to do so.
Mount the VHD file (Windows Disk Management Console)
Defrag the mounted drive
Optimize / Consolidate the mounted drive – This part is key. Defraging will group file bytes together, which is very helpful. What’s important to note is that consolidation / optimization features will actually move files toward the center of the disk, or in our case to the beginning of the VHD file. Furthermore, some optimizers will zero out bytes on the disk that are not used. This is a necessary component for us to be able to shrink the file.
Detach the VHD
Re-mount the VHD in read only mode – not exactly sure of the reasoning behind this part, but through my testing I’ve found that it makes a difference
Shrink the VHD using DISKPART or Hyper-V Management Console
Detach VHD
Voila, size of file is reduced

PowerShell Script
The following PowerShell script can be used to perform the steps mentioned above. The command is run like so:
PS C:\Users\myers_000\Desktop> .\Shrink_VHD.ps1 -filePath "E:\Hyper-V\Base\Windows7_Ultimate_64\BizTalk 2010.vhd"
...

I have almost zero PS experience: does it work from "windows install boot media's command prompt" (startup console?!)

I've seen diskpart /s enables scriptology - is it a different language of script?

THANKS!
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Dell
OS
Windows 7 Ultimate 64bit
CPU
2.2
Memory
8Gb
Graphics Card(s)
NVIDIA
Screen Resolution
1280/762
Mouse
built in pad || iphone || MS wireless
Internet Speed
100MB
Antivirus
Avast
Browser
Chrome, Chrome portable
Back
Top