Monday, February 27, 2012

Shrinking the system partition by using the command line

1. Click Start and type CMD, then press Enter. It is best to run the Command Prompt as an Administrator. To do so, right-click CMD and select "Run as Administrator".
BTW, you can also hover over the CMD line and press CTRL + SHIFT + ENTER to invoke the "Run as Administrator" shortcut.
2. In the command prompt type
Diskpart
3. Select the right disk drive and partition to work on. Typically, in Windows 7, this should be disk 0 and partition 2, but please make sure you do select the right disk and partition before continuing. You can do so by performing a LIST operation to view your existing disks and partitions BEFORE attempting to expand the wrong partition.
List disk
Select disk 0
List partition
Select partition 2

4. When the right disk and partitions were selected, run the SHRINK command which reduces the size of the volume with focus by the specified amount, and makes free disk space available from unused space at the end of the volume.
SHRINK has some parameters we need to talk about:
DESIRED=<N> - Specifies the desired amount of space in megabytes (MB) to reduce the size of the volume by. If a desired amount is not specified, the volume will be reduced by the maximum amount of free space available on the volume.
MINIMUM=<N> - Specifies the minimum amount of space in MB to reduce the size of the volume by.
QUERYMAX - Returns the maximum number of bytes that the volume can be reduced by (the free space available on the volume). This value may change if applications are currently accessing the volume.
If a MINIMUM amount is not specified, the volume will be reduced by either the DESIRED amount (if specified), or by the maximum amount of free space available on the volume. If a MINIMUM amount is specified but not enough free space is available, the command will fail. This command works on basic volumes, and on simple or spanned dynamic volumes. You can reduce the size of a volume only if it is formatted using the NTFS file system or if it does not have a file system.

For example:
Shrink QUERYMAX
The above command will return the maximum number of bytes that the volume can be reduced.

shrink DESIRED=500 MINIMUM=250
Will shrink the partition by 500 MB, if possible, and if it cannot shrink by 500 MB, it will at least attempt to shrink it by 250 MB.
shrink DESIRED=10000
Will shrink the partition by 10000 MB.

5. You may check the new partition size by running the list command, again.
List partition

6. You must now exit DISKPART by using the Exit command.
Exit