Disk Manager (DiskPart)

DiskPart is a text-mode command interpreter. This tool enables you to manage objects (disks, partitions, or volumes) by using scripts or direct input at a command prompt.

DiskPart enables a superset of the actions that are supported by the Disk Management Control Panel snap-in. The Disk Management snap-in prohibits you from inadvertently performing actions that may result in data loss. It is recommended that you use the DiskPart utility cautiously because DiskPart enables explicit control of partitions and volumes.

You can use DiskPart to convert a basic disk to a dynamic disk and backward. The basic disk can either be empty or contain either primary partitions or logical drives. The basic disk can be a data disk or system or boot drive.

You can use DiskPart to create a partition at an explicit disk offset. The Disk Management snap-in places the partition at the end of any occupied area or on the first sufficiently large area. On master boot record (MBR) disks, the partition offset and the size are rounded to preserve the required cylinder alignment. Offsets are rounded to the closest valid value, and the size is always rounded up to the next valid value. DiskPart does not assign a drive letter to a newly created partition. Use the assign command to assign either a mount point or a drive letter.

DiskPart permits certain partition deletion operations that are blocked by the snap-in. For example, you can use DiskPart to delete MBR OEM partitions. However, these partitions often contain files that are important to the platform operation. DiskPart blocks the deletion of the current system, boot, or paging volumes and partitions. Also, DiskPart blocks deletion of the partitions that underlie dynamic disks.

DiskPart causes disk signatures, GUID partition table (GPT) disk globally unique identifiers (GUIDs), and GPT partition GUIDs to be generated.

The DiskPart utility includes support for the new disk partition scheme called GPT. You cannot use GPT disks on any x86-based Windows XP-based or Windows 2000-based computers. DiskPart enables the conversion of GPT partitioning to MBR partitioning only for empty disks.

You can use DiskPart to delete missing dynamic disks. Dynamic disks contain a shared database; all of the dynamic disks on a computer have knowledge of all other dynamic disks on that computer. When dynamic disks are moved, the original computer considers these disks as "missing".

Drive letters are not automatically assigned when you use DiskPart. To ensure that a given partition or volume has a drive letter, you must explicitly assign a drive letter. You can either assign the drive letter or allow the next available drive letter to be allocated.

DiskPart commands

Before you can use DiskPart commands on a disk, partition, or volume, you must first list and then select an object to give it focus. When an object has focus, any DiskPart command that you input will affect that particular object.

You can list the available objects and determine an object's number or drive letter by using the list disk, list volume, and list partition commands. The list disk and list volume commands display all disks and volumes in the computer. However, the list partition command displays only partitions on the disk that have focus. When you use the list commands, an asterisk (*) appears next to the object with focus. You select an object by its number or drive letter, such as disk 0, partition 1, volume 3, or volume C.

When you select an object, the focus remains on that object until you select a different object. For example, if the focus is set on disk 0, and you select volume 8 as on disk 2, the focus shifts from disk 0 to disk 2, volume 8. Some commands automatically change the focus. For example, when you create a new partition, the focus automatically changes to the new partition.

You can give focus only to a partition on the selected disk. When a partition has focus, the related volume (if any) will also have focus. When a volume has focus, the related disk and partition also have focus if the volume maps to a single specific partition. If this is not the case, then focus on the disk and partition is lost.


DiskPart.exe ?

to see all DiskPart commands and syntax.

DiskPart Scripting

By using the DiskPart Command-Line Options command-line tool, you can create scripts to automate disk-related tasks, such as creating volumes or converting disks to dynamic disks. Scripting these tasks is useful if you deploy Windows by using unattended Setup or the Sysprep tool, which do not support creating volumes other than the boot volume.

To start a DiskPart script, at the command prompt, type:

DiskPart.exe /s scriptname.txt 

…where scriptname is the name of the text file that contains your script.

Read here more detailed information on DiskPart usage.