Saturday, March 17, 2012

How to reduce VHD size by using Diskpart.exe and VHDResizer

 I've used Diskpart.exe to reduce my virtual pc size from 234GB to 108GB.
Virtual PC Name = QAServer
-------------------------------------------------------------------------------------------------------------
Microsoft DiskPart version 6.1.7600
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: Yumar-NB


DISKPART> select vdisk file=f:\virtualpc\qaserver\qaserver.vhd

DiskPart successfully selected the virtual disk file.

DISKPART> attach vdisk

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     E                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C   System       NTFS   Partition    137 GB  Healthy    Boot
  Volume 3     D   Data1        NTFS   Partition    102 GB  Healthy
  Volume 4     G   Data2        NTFS   Partition     36 GB  Healthy
  Volume 5     F   CathY        NTFS   Partition    465 GB  Healthy
  Volume 6     H   QAServer     NTFS   Partition    234 GB  Healthy

DISKPART> select volume 6
Volume 6 is the selected volume.

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     E                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C   System       NTFS   Partition    137 GB  Healthy    Boot
  Volume 3     D   Data1        NTFS   Partition    102 GB  Healthy
  Volume 4     G   Data2        NTFS   Partition     36 GB  Healthy
  Volume 5     F   CathY        NTFS   Partition    465 GB  Healthy
* Volume 6     H   QAServer     NTFS   Partition    234 GB  Healthy

DISKPART> shrink querymax
The maximum number of reclaimable bytes is:  195 GB (200196 MB)

DISKPART> shrink desired=130000
DiskPart successfully shrunk the volume by:  126 GB

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     E                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C   System       NTFS   Partition    137 GB  Healthy    Boot
  Volume 3     D   Data1        NTFS   Partition    102 GB  Healthy
  Volume 4     G   Data2        NTFS   Partition     36 GB  Healthy
  Volume 5     F   CathY        NTFS   Partition    465 GB  Healthy
* Volume 6     H   QAServer     NTFS   Partition    108 GB  Healthy

DISKPART> detach vdisk
DiskPart successfully detached the virtual disk file.

DISKPART> exit
---------------------------------------------------------------------------------------------------------
Once, the volume is reduced, I used VHDResizer to reduce VHD to below 127GB.
Viola! The vhd file is ready for use.
 

No comments:

Post a Comment