This command line tool enables storage configuration from a script, remote session, or other command prompt. DiskPart augments the Disk Administrator graphical user interface.
DiskPart differs from many command line utilities in that it does not operate in a single line mode. Instead, the utility is invoked and then commands are read from standard IO. Commands can be directed to any disk, partition, or volume.
File Required
DiskPart Topics
DiskPart allows a superset of the actions supported by the Disk Management snap-in. The snap-in prohibits the user from many inadvertent actions, which may result in data loss. Because DiskPart allows explicit control of partitions and volumes, some care is recommended.
DiskPart may be used to convert a basic disk to dynamic. The basic disk may be empty or have primary partitions and/or logical drives. The basic disk may be a data disk or system/boot drive. The basic disk cannot have ftdisk sets such as stripes or mirrors; that conversion must be done from Disk Management on Windows 2000 or prior to upgrade to Windows XP Professional.
DiskPart may be used to convert a dynamic disk to basic. Any dynamic volumes must be explicitly deleted prior to the conversion. Deleting partitions on a dynamic disk is not recommended outside an emergency. The preferred action is to delete all volumes on the drive and then convert the disk to basic. Care must be taken to delete all dynamic data partitions. Never mix basic primary and dynamic partitions on the same drive; to do so may cause the system not to boot.
DiskPart allows creating a partition at an explicit disk offset. The Disk Management snap-in places the partition at the end of any occupied area or the first sufficiently large area. On MBR disks, partition offset and size are rounded to preserve the required cylinder alignment. Offsets are rounded to the closest valid value. Size is always rounded up to the next valid value. DiskPart will not assign a drive letter to a newly created partition. One may use the "ASSIGN" command to assign a mount point or a drive letter.
DiskPart honors the same policy as the snap-in. Dynamic disks can only be created on fixed disks. Removable disks such as 1394 or USB drives cannot be converted to dynamic.
Certain partition deletion operations that are blocked by the snap-in are permitted by DiskPart. For example, DiskPart allows MBR OEM partitions to be deleted; those partitions often contain files which are key to platform operation. DiskPart does block deletion of the current system, boot, or paging volumes and partitions. DiskPart also blocks deletion of the partitions underlying dynamic disks.
DiskPart does not permit partition creation on removable media. Windows 2000 and Windows XP Professional support at most one MBR partition on removable media. If the media is manufactured with an MBR, that MBR cannot be altered, but will be honored even if multiple partitions or logical drives are configured. If the media is manufactured with no MBR, the media will be treated as a "superfloppy" and no partition structure will be written to the media.
The drive letter for a removable drive is associated with the drive and not the media. That drive letter can be changed using DiskPart.
DiskPart causes disk signatures, GPT disk GUIDs, and GPT partition GUIDs to be generated. DiskPart does not allow these to be explicitly set.
Like the snap-in, DiskPart includes support for the new IA64 disk partition scheme called GPT (GUID Partition Table). GPT disks cannot be used on any Windows XP Professional or Windows 2000 for x86 systems. DiskPart allows conversion of GPT partitioning to MBR partitioning only for empty disks.
DiskPart can be used to delete missing dynamic disks. Dynamic disks contain a shared database; all dynamic disks on a machine have knowledge of all other dynamic disks on that machine. As such, when dynamic disks are moved, the original machine considers them "missing".
Drive letters are not automatically assigned when using DiskPart. To ensure that a given partition or volume have a drive letter, a drive letter must be explicitly assigned. The drive letter may be explicitly assigned or the next available drive letter may be allocated.
Most DiskPart commands operate on a specific target disk, partition, or volume. The targeted object is said to have focus. Focus simplifies the common configuration task of creating multiple partitions on the same disk. An object is put into focus by the SELECT command. Commands other than LIST, HELP, REM, EXIT, or HELP require focus.
Focus can be changed explicitly by the SELECT command or implicitly as the result of a command such as CREATE. The disk focus should always be set prior to managing a basic disk. On basic disks, partition focus and volume focus are the same – changing one implicitly changes the other. On dynamic volumes, only the volume focus is important; the previous partition focus is always lost and the disk focus is only important for simple volumes.
Consider the following examples of a system with two disks:
DiskPart supports scripted operations. To invoke a DiskPart script, use: DiskPart /S <SCRIPT.TXT>. DiskPart may be scripted on Windows XP Professional, Windows 2000, RIS unattended install environment, or on Windows PE for OEMs.
By default, DiskPart will quit command processing and return an error code if there is a problem in the script. To continue script execution, include the NOERR parameter on the command. This permits such useful practices as using a single script to delete all partitions on all data drives regardless of the total number of drives.
Not all commands support the NOERR parameter. Regardless of the NOERR parameter, an error will always be returned on command syntax errors.
Error codes for DiskPart:
Error | Description |
---|---|
0 | No error occurred. The entire script ran without failure. |
1 | A fatal exception occurred. There may be a serious problem. |
2 | The arguments specified on a DiskPart command line were incorrect. |
3 | DiskPart was unable to open the specified script or output file. |
4 | One of the services DiskPart uses returned a failure. |
5 | A command syntax error occurred. The script failed because an object was improperly selected or was invalid for use with that command. |
When DiskPart begins execution, the DiskPart version and current system name are displayed.
Microsoft Diskpart version 0.5
Copyright (C) Microsoft Corporation 2000.
On computer: NT_TEST
The SELECT command sets the focus to the specified target. To get a list of focus types, leave the "TYPE" field blank. If no ID is specified, the current focus object is displayed.
SELECT DISK[=<N>]
The SELECT DISK command sets the focus to the disk with the specified Windows NT disk number. If no disk number is specified, the command displays the current in-focus disk.
SELECT PARTITION[=<N>/<L>]
The SELECT PARTITION command sets the focus to the specified partition. If no partition is specified, the command displays the current in-focus partition.
On basic disks, the partition may be specified by index, drive letter or mount point. On dynamic disks only the index may be used.
SELECT VOLUME[=<N>/<L>]
The SELECT VOLUME command sets the focus to the specified volume. If no volume is specified, the command displays the current in-focus volume.
The volume may be specified by index or by drive letter or mount point path. On a basic disk, selecting a volume also puts the corresponding partition in focus.
Summary displays are obtained with the LIST command. Setting the focus and using the DETAIL command displays more information.
The DETAIL DISK command outputs detailed information on the current in-focus disk.
DISKPART>
select disk 3
Disk 3 is now the selected disk.
DISKPART> detail disk
Maxtor 90432D2
Disk ID: F549D151
Type : IDE
Bus : 0
Target : 0
LUN ID : 0
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ------------ ----- ---------------- ------- --------- --------
Volume 0 F My RAID Set NTFS RAID-5 4096 MB Healthy
Volume 1 G FATSTRIPE FAT32 Stripe 6144 MB Healthy
Volume 2 H My Mirror NTFS Mirror 2048 MB Healthy
Volume 3 I My Span NTFS Spanned 9 GB Healthy
The DETAIL PARTITION command outputs detailed information on the current in-focus partition.
DISKPART> select disk 0
Disk 0 is now the selected disk.
DISKPART> select partition 0
Partition 0 is now the selected partition.
DISKPART> detail partition
Partition 0
Type : 07
Hidden: No
Active: Yes
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
* Volume 2 C NTFS Partition 4110 MB Healthy System
The DETAIL VOLUME command outputs detailed information on the current in-focus volume.
DISKPART> select volume 1
Volume 1 is now the selected volume.
DISKPART> detail volume
Disk ### Status Size Free Dyn Gpt
-------- ---------- ------- ------- --- ---
Disk 1 Online 8 GB 0 B *
Disk 2 Online 8 GB 0 B *
Disk 3 Online 8 GB 0 B *
The LIST DISK command outputs summary information on each disk in the system. Note that the disk with the * has the current focus. Only fixed (eg IDE or SCSI) or removable (eg 1394 or USB) disks are listed; removable drives do not appear.
DISKPART> select disk 3
Disk 3 is now the selected disk.
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ---------- ------- ------- --- ---
Disk 0 Online 4118 MB 0 B
Disk 1 Online 8 GB 4002 MB *
Disk 2 Online 8 GB 0 B *
*Disk 3 Online 8 GB 0 B *
Disk M0 Missing 8 GB 0 B *
The LIST PARTITION command outputs information on each partition on the in-focus disk.
DISKPART> select disk 4
Disk 4 is now the selected disk.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 4094 MB 31 KB
Partition 2 Extended 4581 MB 4094 MB
Partition 3 Logical 2047 MB 4094 MB
Partition 4 Logical 2533 MB 6142 MB
All partitions (regardless of type) are displayed.
The LIST VOLUME command outputs information on each volume in the system.
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------------- ------- ---------- --------
Volume 0 F My RAID Set NTFS RAID-5 4096 MB Healthy
Volume 1 G FATSTRIPE FAT32 Stripe 6144 MB Failed
Volume 2 H My Mirror NTFS Mirror 2048 MB Healthy
Volume 3 I My Span NTFS Spanned 9 GB Healthy
Volume 4 D CDFS CD-ROM 0 B
Volume 5 C NTFS Partition 2047 MB Healthy System
Volume 6 E NTFS Partition 2063 MB Healthy Boot
Volume 7 J My Primary NTFS Partition 4095 MB Healthy
Volume 8 K My Logical NTFS Partition 2047 MB Healthy
Volume 9 L My Next Log NTFS Partition 2534 MB Healthy
Basic disk management tasks include creating and deleting partitions and assigning drive letters and mount points. The commands in this section apply ONLY to basic disks. See the following sections for commands valid on dynamic disks or commands to convert between basic and dynamic.
On all MBR disks, the SIZE or OFFSET parameters are rounded up to cylinder alignment. On GPT disks, the SIZE or OFFSET parameters are rounded to sector alignment. If no OFFSET parameter is specified, the partition is placed in the first unoccupied contiguous disk extent that is large enough. If no SIZE is given, the partition may be extended to occupy the determined disk extent up to the size of the entire disk.
When first discovered, all new disks are assumed to be MBR disks. A disk must be explicitly converted to GPT prior to attempting to create a GPT partition. Microsoft strongly recommends creating the MSR as the first partition on every data disk and the second partition (after the ESP) on any system or boot disk. The conversion from MBR to GPT automatically creates the MSR partition on the disk. See the GPT FAQ for details.
After any new partition creation, the newly created partition gains the partition focus. After any partition deletion, the partition focus is lost. The disk focus remains unchanged in all cases.
The ACTIVE command sets the current in-focus partition as active - indicating to the firmware that the partition is a valid system partition. DiskPart does NO validation of the partition contents; use of this command may cause the system to fail to boot.
ASSIGN [[LETTER=<L>]/[MOUNT=<PATH>]] [NOERR]
The ASSIGN command assigns a letter or mount point to the current in-focus partition. If no assignment is specified, then the next available drive letter is assigned. If the letter or mount point is already in use, an error is generated unless NOERR is specified.
The command can be used to change the drive letter associated with a removable drive.
Drive letter assignment is blocked on the system, boot, or paging volumes. This command cannot be used to assign a drive letter to an OEM partition or any GPT partition other than the MSDATA partition.
CREATE PARTITION PRIMARY [SIZE=<N>] [OFFSET=<N>]
[ID=<BYTE/GUID>] [NOERR]
The CREATE PARTITION PRIMARY command creates a primary partition of length SIZE and starting address OFFSET on the current drive.
If no ID byte is specified on an MBR disk, this command creates a partition with type 0x6. Any partition type byte can be specified with the ID parameter. There is NO validity or other checking of the ID byte.
If no ID GUID is specified on a GPT disk, this command creates an MSDATA partition. Any GUID can be specified with the ID parameter. There is NO validity, duplication, or other checking of the GUID. The partition instance GUID is automatically generated.
MBR and GPT partitions are created such that drive letters will not be automatically allocated by Windows. A drive letter must explicitly be ASSIGNed.
CREATE PARTITION EXTENDED [SIZE=<N>] [OFFSET=<N>] [NOERR]
The CREATE PARTITION EXTENDED command creates an extended partition of length SIZE and starting address OFFSET on the current drive. The drive must be an MBR disk.
After the partition creation, the new extended partition gains the focus. One and only one extended partition can be created on a disk. Logical drives can only be created after creating an extended partition.
CREATE PARTITION LOGICAL [SIZE=<N>] [OFFSET=<N>] [NOERR]
The CREATE PARTITION LOGICAL command creates a logical drive of length SIZE and starting address OFFSET within an existing extended partition on the current disk. The drive must be an MBR disk.
If no OFFSET is given, the logical drive is placed in the first unoccupied contiguous disk extent within the extended partition that is large enough. If no SIZE is given, the partition may be extended to occupy the entire extended partition.
After the partition creation, the logical drive gains the partition focus.
CREATE PARTITION MSR [SIZE=<N>] [OFFSET=<N>] [NOERR]
The CREATE PARTITION MSR command is equivalent to CREATE PARTITION with the MSR GUID E3C9E316-0B5C-4DB8-817D-F92DF00215AE.
CREATE PARTITION ESP [SIZE=<N>] [OFFSET=<N>] [NOERR]
The CREATE PARTITION ESP is equivalent to CREATE partition with ESP GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B.
DELETE PARTITION [NOERR] [OVERRIDE]
The DELETE PARTITION command will delete the current in-focus partition.
DiskPart blocks deletion of the current system, boot, or paging volume. To delete an ESP, MSR, or known OEM partition, the OVERRIDE parameter must be specified.
EXTEND [SIZE=<N>][NOERR]
The EXTEND command will cause the current in-focus volume to be extended into contiguous unallocated space. The unallocated space must follow (be of higher sector offset than) the in-focus partition. The intended use of this command is to grow an existing basic data partition into newly created space on an extended hardware RAID LUN.
If the partition was previously formatted with NTFS, the file system is automatically extended to occupy the larger partition and no data loss occurs. If the partition was previously formatted with any file system format other than NTFS, the command fails with no change to the partition.
DiskPart blocks extension of the current system or boot partition only.
REMOVE [[LETTER=<L>]/[MOUNT=<PATH>]/[ALL]] [NOERR]
The REMOVE command removes a letter or mount point from the current in-focus partition. If "ALL" is specified, then all current drive letters and mount points are are removed. If no letter or mount point is specified, then the drive letter will be removed.
The command can be used to change the drive letter associated with a removable drive.
Drive letter removal is blocked on the system, boot, or paging volumes. This command cannot be used to remove a drive letter to an OEM partition, any GPT partition with an unrecognized GUID, or any of the special, non-data, GPT partitions such as the ESP.
Dynamic disk management tasks include creating and deleting volumes, repairing fault tolerant volumes, and importing disks.
SIZE parameters are always rounded up to MB alignment. Specifying an explicit OFFSET is not supported; the volume is always placed in the first unoccupied contiguous disk extent that is large enough. If no SIZE is given, the largest possible volume will be created.
Creating a volume causes the volume focus to be on the newly created volume. The current disk focus will be lost whenever the volume spans disks. The volume focus is lost when a volume is deleted. If there was a valid disk focus prior to deleting the volume, that disk focus remains.
Note
DiskPart does force creation of an MSR partition on any empty disk when that disk is converted to dynamic or GPT.
ACTIVE
The ACTIVE command sets the current in-focus volume as active - indicating to the firmware that the partition is a valid system partition. DiskPart verifies only that the volume is capable of containing an OS bootable image but does NO validation of the partition contents; use of this command may cause the system to fail to boot.
ADD DISK=<N> [NOERR]
The ADD command adds a mirror to the current in-focus volume on the specified disk. Only two mirror plexes are supported. The current in-focus volume must be a simple volume.
ASSIGN [[LETTER=<L>]/[MOUNT=<PATH>]] [NOERR]
The ASSIGN command assigns a letter or mount point to the current in-focus volume. If no assignment is specified, then the next available drive letter is assigned. If the letter or mount point is already in use, an error is generated unless NOERR is specified.
Drive letter assignment is blocked on the system, boot, or paging volumes.
BREAK DISK=<N> [NOKEEP] [NOERR]
The BREAK command breaks the current in-focus mirror.
By default, the contents of both mirror plexes are retained; both plexes become simple volumes. If the NOKEEP parameter is specified, only the specified plex is retained; the other plex is removed and converted to free space.
The original volume retains any and all drive letters or mount points. If the plex is not kept, the focus remains on the retained simple volume on the specified disk. Otherwise, the focus is changed to the specified retained plex on the specified disk. The plex becomes a simple volume, however no drive letter is assigned to the new volume.
CREATE VOLUME SIMPLE [SIZE=<N>] [DISK=<N>] [NOERR]
The CREATE VOLUME SIMPLE command creates a simple volume of length SIZE on the specified disk.
If no SIZE is given, the new volume will take up the remaining contiguous free space on the disk. If no DISK is given, then the current in-focus disk is used.
After the volume has been created, the disk focus is given to the targeted disk.
CREATE VOLUME STRIPE [SIZE=<N>] DISK=<N>[,<N>[,...]]
[NOERR]
The CREATE VOLUME STRIPE command creates a stripe set volume on the specified disks. The total size of the stripe volume is SIZE*number of disks.
If no SIZE is given, the largest possible stripe volume will be created. The disk with the smallest available contiguous free space is determined. The size of that free space determines the SIZE for the stripe volume. The same SIZE is allocated on each disk.
CREATE VOLUME RAID [SIZE=<N>] DISK=<N>[,<N>[,...]]
[NOERR]
The CREATE VOLUME RAID command creates a RAID-5 set volume on the specified disks. An amount of space equal to "SIZE" is allocated on each disk.
If no SIZE is given, the largest possible RAID5 volume will be created. The disk with the smallest available contiguous free space is determined. The size of that free space determines the SIZE for the RAID5 volume and the same SIZE is allocated from each disk. The actual usable size of the volume will be less than SIZE*number of disks as some of the space is used for the parity.
DELETE DISK [NOERR][OVERRIDE]
The DELETE DISK command will delete a missing dynamic disk from the disk list.
If OVERRIDE is specified, all simple volumes contained on the disk are deleted and any mirror plexes are removed. If the disk contributes to a RAID 5 volume, the command fails.
DELETE PARTITION [NOERR] [OVERRIDE]
The DELETE PARTITION command will delete the current in-focus partition.
DiskPart blocks deletion of any partitions used to contain existing online dynamic volumes. Those volumes must be deleted and the disk converted to basic. To delete an ESP, MSR, or known OEM partition, the OVERRIDE parameter must be specified.
Partitions can be deleted from dynamic disks, but cannot be created. For example, it is possible to delete an unrecognized GPT partition on a dynamic GPT disk. Deleting such a partition does not cause the resulting free space to become available. This command is particularly intended to allow reclamation of the space on a corrupted offline dynamic disk in an emergency situation where the CLEAN command cannot be used.
DELETE VOLUME [NOERR]
The DELETE VOLUME command will delete the current in-focus volume. Any and all data are lost.
EXTEND DISK=<N> [SIZE=<N>] [NOERR]
The EXTEND command extends the current simple or extended volume onto the specified disk.
If no SIZE is given, the volume will occupy all free space on the specified disk. Extending a system or boot volume is not supported.
Any existing disk focus is lost.
IMPORT [NOERR]
The IMPORT command will import all disks from a foreign disk group.
Setting focus on any disk in the foreign disk group imports all disks in the group. After import, any existing volume or disk focus is lost.
ONLINE [NOERR]
The ONLINE command brings a disk or volume that had previously been taken offline, and brings it online.
No change in focus occurs.
REMOVE [[LETTER=<L>]/[MOUNT=<PATH>]/[ALL]] [NOERR]
The REMOVE command removes a letter or mount point from the current in-focus volume. If "ALL" is specified, then all current drive letters and mount points are are removed. If no letter or mount point is specified, then the first encountered path is removed.
Drive letter removal is blocked on the system, boot, or paging volumes.
RETAIN
The RETAIN command prepares a dynamic simple volume to be used as a boot or system volume.
On an x86-based computer, RETAIN creates a master boot record (MBR) partition on the dynamic simple volume with focus. To create an MBR partition, the dynamic simple volume must start at a cylinder aligned offset and be an integral number of cylinders in size.
On an Itanium-based computer, RETAIN creates a GUID partition table (GPT) partition on the dynamic simple volume with focus.
CONVERT MBR [NOERR]
The CONVERT MBR command sets the partitioning style of the current disk to MBR. The disk may be basic or dynamic but must not contain any valid data partitions or volumes.
CONVERT GPT [NOERR]
The CONVERT GPT command sets the partitioning style of the current disk to GPT. The disk may be basic or dynamic but must not contain any valid data partitions or volumes. This command is valid only on IA64 systems and will fail on x86.
CONVERT DYNAMIC [NOERR]
The CONVERT DYNAMIC command changes a basic disk into a dynamic disk. The disk may contain valid data partitions.
CONVERT BASIC [NOERR]
The CONVERT BASIC command changes an empty dynamic disk to basic.
EXIT
The EXIT command stops DiskPart, and returns control to the operating system.
CLEAN [ALL]
The CLEAN command removes any and all partition or volume formatting from the current in-focus disk by zeroing sectors. By default, only the MBR or GPT partitioning information and, on MBR disks, any hidden sector information is overwritten. Specifying the ALL parameter causes each and every sector to be zeroed, thus also deleting all data contained on the drive.
REM [...]
The REM command does nothing, and can be used to comment script files.
RESCAN
The RESCAN command rescans all IO buses causing any new disks that have been added to the system to be discovered.
HELP
The HELP command displays a the list of all commands.