How to use Diskpart command line to convert/resize/delete partitions?

What is diskpart?

DiskPart.exe is a text-mode command line tool interpreter which enables storage objects such as disks, partitions or volumes configuration and management from a script, remote session, or direct input from a command prompt. Diskpart is actually the underlying utility that augments the Disk Administrator graphical user interface and enables a superset of the actions that are supported by the Disk Management snap-in. The Disk Management snap-in prohibits you from inadvertently performing actions that may result in data loss, sometimes it is recommended that DiskPart is used to enable explicit control of partitions and volumes.

What is Windows Disk Management?

Disk Management under Computer Management in Administrator Tools is a GUI (Graphical User Interface) based disk partitioning utility that allows Windows 2000, Windows 2003 Windows XP, Windows Vista, Windows 7 users to set active partition, change drive letter and paths, extend volume, shrink volume, delete volume, and format the drives. However, Disk Management extension in Microsoft Management Console (MMC) does not always work properly. Problems faced by users including random grayed out or disabled of Extend Volume and Shrink Volume options, as Disk Management snap-in prohibits you from inadvertently performing actions that may result in data loss.

If you’re getting frustrated with Disk Management, try out DiskPart utility, a text-mode command line interpreter based on scripts to manage, create, delete and resize objects such as disks, partitions and volumes in Windows 7, Windows Vista, XP, 2003 and 2000. (Later 3 operating systems do not install with DiskPart.exe by default, so users need to download and install DiskPart manually). As DiskPart is a command line utility, users will have to use various commands to instruct DiskPart to perform a disk related task. Users can use HELP command to list out all available commands for DiskPart. For various options for a command, append the command name to HELP, i.e. HELP [command], or simply type the command name itself only. For detailed explanation and guide to use the command, append the full command syntax to the HELP, i.e. HELP [full command syntax with option].

Diskpart

For easy reference and getting start guide, here’s some simple operation that you can perform on your partition or volume with DiskPart. But before you continue, make sure that you backup important files and programs in case of any failure.

How to use diskpart command line?

  1. Start and Run DiskPart To run DiskPart, type DiskPart.exe in Start Search in Windows Vista, or in Run command text box in Windows 2000, 2003 and XP finished off by Enter key. A command prompt window with DISKPART shell is loaded.
  2. List all disks on system in DiskPart To all your available installed hard disks on the system, simply type list disk, and hit Enter.
  3. Select and set target disk to use in Disk PartTo set and select a disk which you want to work with in DiskPart, use the following command syntax:select disk <disk number (###)>The disk number is retrieved from “list disk” command.
  4. Create a partition with DiskPartIf the hard disk is empty without any partition or still has unallocated space, a partition can be created on it with the following command syntax:create partition <partition type> [size=<n>] [offset=<n>] [id={<byte> | <guid>}] [align=<n>] [noerr]The partition types that are supported are primary partition (the only bootable type, but limited to four per hard disk), extended partition (also limited to four per hard disk to supplement those need more than 4 primary partitions), logical drive (to define within extended partition to allow many volumes to be created), EFI system partition and MSR (Microsoft Reserved partition). Note that not all options are available for all partition type.Example: create partition primary size=1000 (Create a primary partition with the size of 10GB.)
  5. DiskPart allows user to create RAID (RAID-5) volume using three or more specified dynamic disks, simple volume or striped volume using two or more specified dynamic disks. The syntax for the command is:create volume <volume type> [size=<n>] disk=<n>,<N>,<n>[,<n>[,...]] [align=<n>] [noerr]Example: create volume raid size=1000 disk=1,2,3 (Create a RAID-5 array volume with 1 GB (1000MB) using disk 1, 2 and 3.)
  6. List all volumes in DiskPartUse the following command to list all volumes in order to check which number is associated with the volume we want to work with:list volume
  7. Select a volume to manage in DiskPartUse the following command to select a volume in order to manage (shrink, extend, delete format) the volume:select volume <number>The number for the volume is retrieved from “list volume” command.
  8. List all partitions in DiskPartUse the following command to list all partitions in order to check which number is associated with the partition we want to work with:list partition
  9. Select a partition to manage in DiskPartUse the following command to select a volume in order to manage (shrink, extend, delete format) the partition:select partiton <number>The number for the partiton is retrieved from “list partition” command.
  10. Shrink a volume (reduce size of partition) in DiskPartTo reduce 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, use following command syntax:shrink [desired=<n>] [minimum=<N>] [nowait] [noerr]Example: shrink desired=500 minimum=250 (Shrink volume by 500 MB, with 250 MB as minimum size to be freed if not possible.)To check and determine how much is the maximum number of bytes that a volume can be reduced by (the free space that is available on the volume), use following command:shrink querymax [noerr]
  11. Extends the volume or partition (increase size) in DiskPartTo extend the volume or partition with focus and its file system into free (unallocated) space which can be used to store data on a disk, use following command syntax:extend [size=<n>] [disk=<n>] [noerr]The above command works on when both volume or partition is selected.Example: extend size=500 (Increase the size of current partition or volume selected by 500MB.)
  12. Delete partition or volume with DiskPartNote that system, boot or any volume/partition that contains the active paging file or crash dump (memory dump) cannot be deleted. And users must select a partition or volume before start deletion operation. Dynamic disks should be removed by using “delete volume” command.delete partitiondelete volume
  13. Format a volume or partition in DiskPart Simply select a partition or volume, and then type Format.

For Windows Server 2003, please refer another step by step tutorial how to extend partition with Diskpart for Server 2003.

Disadvantages of Diskpart commands line

Though DiskPart is free and provides by Microsoft, it is not a good utility to extend or resize partition.

  1. The system volume can only be extended by running Diskpart.exe from a command line by bootable CD.
  2. Only when you delete a data partition and get some Unallocated space, you can extend the system C drive.
  3. It works by command line and hard to use for many users.
  4. Incorrect operations lead to data loss and the operations cannot be undone.
  5. Stop the PC or Server running for a long time.

It is extremely easy to extend, resize partition with third party partition software. You just need to drag and move on the disk map to resize and extend partition, all operations can be previewed and cancelled. You can even extend system partition without reboot if it is NTFS.

Windows Vista/7 and Server 2008 provides more features under Disk Management that older versions. You can shrink and extend partitions with the guide under Disk Management. For detailed steps, please refer how to shrink and extend partition under Server 2008 (the same with Windows Vista/7).

To better resize, extend and manage your disk partition, you’d better run third-party partition software.

For Windows XP/Vista/7 uers, please refer professional partition software.

For Windows Server 2000/2003/2008 users, please refer Partition Magic Server Edition.

5 thoughts on “How to use Diskpart command line to convert/resize/delete partitions?

  1. GREAT SITE,
    thanks guys i have been trying to find this information for days and was unsuccessful.i treid some techspot forums u can still my post there no one knew..
    gr8 site and whoever has posted this article
    thank you so much!!

    I appreciate it sir!!

  2. Hi Guys,
    I was working on a project having 2 external devices online and by mistake used DISKPAT’s REMOVE command on a wrong disk :-(
    Now it shows empty.
    Is it possible to recover the data?
    BTW, it is Widows 7 Ultimate

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>