Share via


DiskPart Command-Line Options (Standard 7 SP1)

7/8/2014

DiskPart is a text-mode command interpreter in Windows Embedded Standard 7 that enables you to manage objects, such as disks, partitions, or volumes by using scripts or direct input at a command prompt.

Where to Find DiskPart

DiskPart can be found under the %WINDIR%\System32\ folder. DiskPart is also included in a typical Windows Preinstallation Environment (Windows PE) 3.0 environment. For information on creating a Windows PE boot disk, see Create a Bootable USB Flash Drive.

DiskPart Commands

Before you can use DiskPart commands on a disk, partition, or volume, you must first list and then select the object to give it focus. When an object has the focus, any DiskPart commands that you type act on that object.

You can list the available objects and determine the number or drive letter of an object by using the list disk, list volume, and list partition commands. The list disk and list volume commands display all disks and volumes on the computer. However, the list partition command displays only partitions on the disk that have the focus. When you use the list commands, an asterisk (*) appears next to the object that has the 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 the focus, the related volume (if any) also has the focus. When a volume has the focus, the related disk and partition also have the focus if the volume maps to a single specific partition. If this is not the case, the focus on the disk and partition is lost.

Note

When using the DiskPart command as a part of a script, we recommend that you complete all the DiskPart operations together as part of a single DiskPart script. You can run consecutive DiskPart scripts. However, you must allow for at least 15 seconds between each script for a complete shutdown of the previous execution before you run the DiskPart command again in successive scripts. Otherwise, the successive scripts might fail. You can add a pause between consecutive DiskPart scripts by adding the time-out /t 15 command to your batch file together with your DiskPart scripts.

For more information about using DiskPart in Disk Management, see this Microsoft Web site.

DiskPart Syntax and Parameters

The following table identifies the syntax and parameters of the DiskPart commands.

Command

Syntax

Description

active

active

On basic disks, marks the partition with the focus as active. This informs the basic input/output system (BIOS) or Extensible Firmware Interface (EFI) that the partition or volume is a valid system partition or system volume.

Only partitions can be marked as active.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
DiskPart verifies that only the partition can contain the startup files of an operating system. DiskPart does not check the contents of the partition. If you mark a partition as active and it does not contain the startup files of the operating system, your computer might not start.

add disk

add disk= n [noerr]

Mirrors the simple volume with the focus to the specified disk.

n

Specifies the disk to contain the mirror. You can mirror only simple volumes. The specified disk must have unallocated space at least as large as the size of the simple volume that you intend to mirror.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

assign

assign [{letter=d|mount=path}] [noerr]

Assigns a drive letter or mount point to the volume with the focus. If no drive letter or mount point is specified, the next available drive letter is assigned. If the assigned drive letter or mount point is already being used, an error is generated.

By using the assign command, you can change the drive letter associated with a removable drive.

You cannot assign drive letters to system volumes, boot volumes, or volumes that contain the paging file. You cannot assign a drive letter to an OEM partition or any GPT partition other than a basic data partition.

letter= d

Specifies the drive letter that you intend to assign to the volume.

mount= path

Specifies the mount-point path that you intend to assign to the volume.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

attributes

attributesvolume [{set | clear}] [{hidden | readonly | nodefaultdriveletter | shadowcopy}] [noerr]

volume

Displays the attributes of the selected volume.

set

Sets the specified attribute (hidden, readonly, nodefaultdriveletter, or shadowcopy volume) on the selected volume.

clear

Clears the specified attribute (hidden, readonly, nodefaultdriveletter, or shadowcopy volume) from the selected volume.

hidden

Specifies that the volume is hidden.

readonly

Specifies that the volume is read-only.

nodefaultdriveletter

Specifies that the volume does not receive a drive letter by default.

shadowcopy

Specifies that the volume is a shadow-copy volume.

noerr

For scripting only. When an error is encountered, DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

automount

automount [enable] [disable] [scrub] [noerr]

When it is enabled (the default), Standard 7 automatically mounts the file system for a new basic volume when it is added to the system, and then assigns a drive letter to the volume. In system area network configurations, disabling automount prevents Standard 7 from automatically mounting or assigning drive letters to any new basic volumes added to the system.

enable

Enables Standard 7 to automatically mount new basic volumes added to the system and to assign them drive letters.

disable

Prevents Standard 7 from automatically mounting any new basic volumes that are added to the system.

scrub

Removes mounted folder path names, drive letters, mounted folder directories, volume mount point directories, and registry settings for volumes that are no longer in the system. This prevents volumes that were previously in the system from being automatically mounted and given their former volume mount point(s) when they are added back to the system.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

break disk

break disk= n [nokeep] [noerr]

Applies to dynamic disks only. Breaks the mirrored volume with the focus into two simple volumes. One simple volume retains the drive letter and any mount points of the mirrored volume, while the other simple volume receives the focus so that you can assign it a drive letter.

By default, the contents of both halves of the mirror are retained; each half becomes a simple volume. If you use the nokeep parameter, only one-half of the mirror is retained as a simple volume, while the other half is deleted and converted to free space. Neither volume receives the focus.

n

Specifies the disk that contains the mirrored volume.

nokeep

Specifies that only one copy of the mirrored volumes is retained. The other simple volume is deleted and converted to free space. Neither volume receives the focus.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

clean

clean [all]

Removes any partition or volume formatting from the disk that has the focus. On master boot record (MBR) disks, only the MBR partitioning information and hidden-sector information are overwritten. On GUID partition table (GPT) disks, the GPT partitioning information is also overwritten. This includes the Protective MBR, which is overwritten. There is no hidden sector information.

all

Specifies that each sector on the disk is zeroed, that is, it completely deletes all data that is contained on the disk.

convert basic

convert basic [noerr]

Converts an empty dynamic disk into a basic disk.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
The disk must be empty to convert it to a basic disk. Back up your data, and then delete all partitions or volumes before converting the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert dynamic

convert dynamic [noerr]

Converts a basic disk into a dynamic disk. Any existing partitions on the disk become simple volumes.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert gpt

convert gpt [noerr]

On Itanium-based computers, converts an empty basic disk that has the master boot record (MBR) partition style into a basic disk that has the GUID partition table (GPT) partition style.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
The disk must be empty to convert it to a GPT disk. Back up your data and then delete all partitions or volumes before converting the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert mbr

convert mbr [noerr]

On Itanium-based computers, converts an empty basic disk that has the GUID Partition Table (GPT) partition style to a basic disk that has the master boot record (MBR) partition style.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
The disk must be empty to convert it to an MBR disk. Back up your data and then delete all partitions or volumes before converting the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition efi

create partition efi [size=n] [offset=n] [noerr]

On Itanium-based computers, creates an Extensible Firmware Interface (EFI) system partition on a GUID partition table (GPT) disk. After the partition has been created, the focus is given to the new partition.

size=n

Specifies the size of the partition in megabytes (MB). If no size is given, the partition continues until there is no more free space in the current region.

offset= n

Specifies the byte offset at which to create the partition. If no offset is given, the partition is put in the first disk that is large enough to hold it.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition extended

create partition extended [size=n] [offset=n] [align=n][noerr]

Creates an extended partition on the current drive. After the partition has been created, the focus automatically shifts to the new partition. Only one extended partition can be created per disk. This command fails if you try to create an extended partition within another extended partition. You must create an extended partition before you can create logical drives.

size= n

Specifies the size of the extended partition in megabytes (MB). If no size is given, the partition continues until there is no more free space in the region. The size is cylinder snapped; that is, the size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition size rounds up to 504 MB.

offset= n

Applies to master boot record (MBR) disks only. Specifies the byte offset at which to create the extended partition. If no offset is given, the partition starts at the beginning of the first free space on the disk. The offset is cylinder snapped; that is, the offset is rounded to the closest cylinder boundary. For example, if you specify an offset that is 27 MB and the cylinder size is 8 MB, the offset is rounded to the 24-MB boundary.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance. The partition offset will be a multiple of (N). If the OFFSET parameter is specified, it will be rounded to the closest multiple of (N).

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition logical

create partition logical [size=n] [offset=n] [align=n][noerr]

Creates a logical drive in the extended partition. After the partition has been created, the focus automatically shifts to the new logical drive.

size= n

The size of the logical drive in megabytes (MB). If no size is given, the partition continues until there is no more free space in the current region.

offset= n

Applies to master boot record (MBR) disks only. Specifies the byte offset at which to create the logical drive. The offset is cylinder snapped; that is, the offset rounds up to completely fill whatever cylinder size is used. If no offset is given, the partition is put in the first disk that is large enough to hold it. The partition is at least as long in bytes as the number that is specified by size= n. If you specify a size for the logical drive, it must be smaller than the extended partition.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance. The partition offset will be a multiple of (N). If the OFFSET parameter is specified, it will be rounded to the closest multiple of (N).

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition msr

create partition msr [size=n] [offset=n] [noerr]

On Itanium-based computers, creates a Microsoft reserved (MSR) partition on a GUID partition table (GPT) disk.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
Be very careful when you use the create partition msr command. GPT disks require a specific partition layout, and so creating Microsoft reserved partitions can cause the disk to become unreadable. On GPT disks that are used to start Windows XP 64-Bit Edition or the 64-bit versions of the Windows Server 2003 family, the EFI system partition is the first partition on the disk, followed by the Microsoft reserved partition. GPT disks used only for data storage do not have an EFI system partition. The Microsoft reserved partition is the first partition.

Windows XP and the Windows Server 2003 family do not mount Microsoft reserved partitions. You cannot store data on them and you cannot delete them.

size= n

Specifies the size of the partition in megabytes (MB). The partition is at least as long in bytes as the number that is specified by size= n. If no size is given, the partition continues until there is no more free space in the current region.

offset= n

Specifies the byte offset at which to create the partition. The partition starts at the byte offset specified by offset= n. It is sector-snapped; that is, the offset rounds up to completely fill whatever sector size is used. If no offset is given, the partition is put in the first disk extent that is large enough to hold it.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

createpartitionprimary

createpartitionprimary [size=n] [offset=n] [ID={byte|GUID}] [align=n][noerr]

Creates a primary partition on the current basic disk. After you create the partition, the focus automatically shifts to the new partition. The partition does not receive a drive letter. You must use the assign command to assign a drive letter to the partition.

size= n

Specifies the size of the partition in megabytes (MB). If no size is given, the partition continues until there is no more unallocated space in the current region. The size is cylinder snapped; that is, the size rounds to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition size rounds up to 504 MB.

offset= n

Specifies the byte offset at which to create the partition. If no offset is given, the partition starts at the beginning of the first free space on the disk. For master boot record (MBR) disks, the offset is cylinder snapped; that is, the offset rounds to the closest cylinder boundary. For example, if you specify an offset that is 27 MB and the cylinder size is 8 MB, the offset rounds to the 24-MB boundary.

ID={byte|GUID}

Intended for OEM use only.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
Creating partitions with this parameter could cause your computer to crash or be unable to start. Unless you are an OEM or an IT professional experienced with GPT disks, do not create partitions on GPT disks by using the ID={byte|GUID} parameter. Instead, always use the create partition efi command to create EFI system partitions, the create partitionmsr command to create Microsoft reserved partitions, and the create partition primary command (without the ID={byte|GUID} parameter) to create primary partitions on GPT disks.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance when the logical units (LUs) are not cylinder aligned. Aligns a primary partition that is not cylinder aligned at the beginning of a disk and rounds the offset to the closest alignment boundary, where n is the number of kilobytes (KB) from the beginning of the disk to the closest alignment boundary. The align= n command fails if the primary partition is not at the beginning of the disk. If you use it with offset= n, the offset is within the first usable cylinder on the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

Comments

To partition a GPT disk that has an OEM partition, generate an OEM-GUID.

Use the following command to create an EFI partition:

create partition efi size= n

Use the following command to create a primary partition:

create partition primary size= nID={byte|GUID}

Use the following command to create an MSR partition:

createpartitionMSRsize= n

Ff794606.note(en-US,WinEmbedded.60).gifNote:
You must create the OEM partition between the EFI and MSR partitions.

Never create the LDM metadata or LDM data partitions explicitly as partitions. Instead, convert the disk to dynamic.

For master boot record (MBR) disks, you can specify a partition type byte, in hexadecimal form, for the partition. If you do not specify a partition type byte on an MBR disk, the createpartitionprimary command creates a partition of type 0x6. Any partition type byte can be specified with the ID={byte|GUID} parameter. DiskPart does not verify the validity of the partition type, nor does it verify the ID parameter.

  • For GPT disks, you can specify a partition type GUID for the partition that you create.
  • EFI system partition: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
  • Microsoft reserved partition: e3c9e316-0b5c-4db8-817d-f92df00215ae
  • Basic data partition: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
  • LDM metadata partition on a dynamic disk: 5808c8aa-7e8f-42e0-85d2-e1e90434cfb3
  • LDM data partition on a dynamic disk: af9b60a0-1431-4f62-bc68-3311714a69ad

If you do not specify a partition type GUID, the createpartitionprimary command creates a basic data partition. Any partition type can be specified with the ID={byte|GUID} parameter. DiskPart does not verify the validity of the partition GUID, nor does it verify the ID parameter.

createvolumeraid

createvolumeraid [size=n] [disk=n,n,n[,n,…]] [align=n] [noerr]

Creates a RAID-5 volume on three or more specified dynamic disks. After you create the volume, the focus automatically shifts to the new volume.

size= n

Specifies the disk space, in megabytes (MB), that the volume occupies on each disk. If no size is given, the largest possible RAID-5 volume is created. The disk that has the smallest available contiguous free space determines the size for the RAID-5 volume, and the same amount of space is allocated from each disk. The actual amount of usable disk space in the RAID-5 volume is less than the combined amount of disk space because some disk space is required for parity.

disk= n , n , n[,n,…]

Specifies the dynamic disks on which to create the volume. You must have at least three dynamic disks in order to create a RAID-5 volume. An amount of space equal to size= n is allocated on each disk.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance when the logical units (LUs) are not cylinder aligned. Aligns a primary partition that is not cylinder aligned at the beginning of a disk and rounds the offset to the closest alignment boundary, where n is the number of kilobytes (KB) from the beginning of the disk to the closest alignment boundary. The align= n command fails if the primary partition is not at the beginning of the disk. If you use it with offset= n, the offset is within the first usable cylinder on the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

createvolumesimple

createvolumesimple [size=n] [disk=n] [align=n] [noerr]

Creates a simple volume. After you create the volume, the focus automatically shifts to the new volume.

size= n

Specifies the size of the volume in megabytes (MB). If no size is given, the new volume uses the remaining free space on the disk.

disk= n

Specifies the dynamic disk on which to create the volume. If no disk is given, the current disk is used.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance when the logical units (LUs) are not cylinder aligned. Aligns a primary partition that is not cylinder aligned at the beginning of a disk and rounds the offset to the closest alignment boundary, where n is the number of kilobytes (KB) from the beginning of the disk to the closest alignment boundary. The align= n command fails if the primary partition is not at the beginning of the disk. If you use it with offset= n, the offset is within the first usable cylinder on the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

createvolumestripe

createvolumestripe [size=n] [disk=n,n[,n,…]] [align=n] [noerr]

Creates a striped volume by using two or more specified dynamic disks. After you create the volume, the focus automatically shifts to the new volume.

size= n

Specifies the disk space, in megabytes (MB), that the volume occupies on each disk. If no size is given, the new volume uses the remaining free space on the smallest disk and an equal amount of space on each the next disk.

disk= n , n[,n,…]

Specifies the dynamic disks on which to create the volume. You must have at least two dynamic disks to create a striped volume. An amount of space equal to size= n is allocated on each disk.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance when the logical units (LUs) are not cylinder aligned. Aligns a primary partition that is not cylinder aligned at the beginning of a disk and rounds the offset to the closest alignment boundary, where n is the number of kilobytes (KB) from the beginning of the disk to the closest alignment boundary. The align= n command fails if the primary partition is not at the beginning of the disk. If you use it with offset= n, the offset is within the first usable cylinder on the disk.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

deletedisk

deletedisk [noerr] [override]

Deletes a missing dynamic disk from the disk list.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

override

Enables DiskPart to delete all simple volumes on the disk. If the disk contains half of a mirrored volume, the half of the mirror on the disk is deleted. The delete disk override command fails if the disk is a member of a RAID-5 volume.

deletepartition

deletepartition [noerr] [override]

On a basic disk, deletes the partition with the focus. You cannot delete the system partition, boot partition, or any partition that contains the active paging file or crash dump (memory dump).

Ff794606.note(en-US,WinEmbedded.60).gifNote:
Deleting a partition on a dynamic disk can delete all dynamic volumes on the disk, therefore destroying any data and leaving the disk in a corrupted state. To delete a dynamic volume, always use the delete volume command instead.

You can delete partitions from dynamic disks. However, you must not create them. For example, you can delete an unrecognized GUID partition table (GPT) partition on a dynamic GPT disk. However, deleting such a partition does not cause the resulting free space to become available. This command is intended to enable space reclamation on a corrupted, offline dynamic disk in an emergency where the clean command cannot be used.

noerr

For scripting only. When an error occurs, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

override

Enables DiskPart to delete any partition regardless of type. Usually, DiskPart enables you to delete only known data partitions.

deletevolume

deletevolume [noerr]

Deletes the selected volume. You cannot delete the system volume, boot volume, or any volume that contains the active paging file or crash dump (memory dump).

noerr

For scripting only. When an error occurs, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

detaildisk

detaildisk

Displays the properties of the selected disk and the volumes on that disk.

detailpartition

detailpartition

Displays the properties of the selected partition.

detailvolume

detailvolume

Displays the disks on which the current volume resides.

exit

exit

Exits the DiskPart command interpreter.

extend

extend [size=n] [disk=n] [filesystem][noerr]

Extends the volume with the focus into the next contiguous unallocated space. For basic volumes, the unallocated space must be on the same disk as, and must follow (have a larger sector offset number than) the partition with the focus. A dynamic, simple, or spanned volume can be extended to any empty area on any dynamic disk. By using this command, you can extend an existing volume into newly created space.

If the partition was previously formatted with the NTFS file system, the file system is automatically extended to occupy the larger partition. No data loss occurs. If the partition was previously formatted with any file-system format other than NTFS, the command fails without a change to the partition.

You cannot extend the current system or boot partitions.

filesystem

Extends the file system of the volume with focus to cover the entire volume. For use only on volumes where the file system was not extended with the volume.

size= n

Specifies the space, in megabytes (MB), to add to the current partition. If you do not specify a size, the disk is extended to use all the next contiguous unallocated space.

disk= n

Specifies the dynamic disk on which to extend the volume. An amount of space equal to size= n is allocated on the disk. If no disk is specified, the volume is extended on the current disk.

noerr

For scripting only. When an error occurs, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

gptattributes

gptattributes= n

On basic GPT disks, assigns the GPT attribute(s) to the partition with the focus. GPT partition attributes give additional information about how to use the partition. Some attributes are specific to the partition type GUID.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
Changing the GPT attributes could cause basic data volumes to be unmountable or not be assigned drive letters. Unless you are an OEM or an IT professional experienced with GPT disks, do not change GPT attributes.

n

The hexadecimal that applies to the attribute that you intend to apply to the partition with the focus. The GPT attribute field is a 64-bit field that contains two subfields. The larger field is interpreted only in the context of the partition ID, while the earlier field is common to all partition IDs.

All partitions have the following attribute:

  • 0x000000000000001 marks the partition as required. This indicates to all disk-management tools that the partition must not be deleted. The EFI system partition contains only those binaries necessary to start the operating system. This makes it easy for OEM- or operating system-specific binaries to be put in other partitions.

For basic data partitions, the following attribute is defined:

  • 0x8000000000000000 prevents the partition from having a drive letter automatically assigned. By default, each partition is assigned a new drive letter. Setting this attribute guarantees that, when a disk is moved to a new computer, a new drive letter is not automatically generated. Instead, the user can manually assign drive letters.
Ff794606.note(en-US,WinEmbedded.60).gifNote:
Other attributes can be added at any time.

help

help

Displays a list of the available commands.

import

import [noerr]

Imports a foreign-disk group into the local computer's disk group. The import command imports every disk that is in the same group as the disk that has the focus.

noerr

For scripting only. When an error occurs, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

inactive

inactive

On basic master boot record (MBR) disks, marks the system partition or boot partition with the focus as inactive. The computer starts from the next option that is specified in the BIOS, such as the CD Drive or a Pre-Boot Execution Environment (PXE)-based boot environment (such as Remote Installation Services (RIS)), when you restart the computer.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
Your computer might not start without an active partition. Do not mark a system or boot partition as inactive unless you are an experienced user who has a thorough understanding of the Windows Server 2003 family.

listdisk

listdisk

Displays a list of disks and information about them, such as their size, amount of available free space, whether the disk is a basic or dynamic disk, and whether the disk uses the master boot record (MBR) or GUID partition table (GPT) partition style. The disk marked with an asterisk (*) has the focus.

listpartition

listpartition

Displays the partitions listed in the partition table of the current disk. On dynamic disks, these partitions might not correspond to the dynamic volumes on the disk. This difference occurs because dynamic disks contain entries in the partition table for the system volume or boot volume (if present on the disk). Dynamic disks also contain a partition that occupies the rest of the disk and reserves space for use by dynamic volumes.

listvolume

listvolume

Displays a list of basic and dynamic volumes on all disks.

online

online

Brings an offline disk or volume with the focus online. Resynchronizes the mirrored or RAID-5 volume with the focus.

rem

rem

Lets you add comments to a script; for example:

rem These commands set up 3 drives. 
create partition primary size=2048 
assign d: 
create partition extend 
create partition logical size=2048 
assign e: 
create partition logical 
assign f: 

remove

remove [{letter=d|mount=path|[all]}] [dismount][noerr]

Removes a drive letter or mount point from the volume with the focus. If the all parameter is used, all current drive letters and mount points are removed. If you do not specify a drive letter or mount point, DiskPart removes the first drive letter or mount point that it encounters.

You can use the remove command to change the drive letter associated with a removable drive. You cannot remove the drive letters on system, boot, or paging volumes. In addition, you cannot remove the drive letter for an OEM partition, any GPT partition with an unrecognized GUID, or any of the special, non-data, GPT partitions such as the EFI system partition.

letter= d

Specifies the drive letter to remove.

mount= path

Specifies the mount point path of remove.

all

Removes all current drive letters and mount points.

dismount

Dismounts the basic volume, when all drive letters and mount points have been removed from the volume, and takes the basic volume offline. It makes it unmountable. If other processes are using the volume, DiskPart closes any open handles before dismounting the volume. You can make the volume mountable by assigning it a drive letter or by creating a mount point path to the volume. Dismount fails if you use it on a volume that has any remaining drive letters or mount points. For scripting, we recommend that you use removealldismount.

noerr

For scripting only. When an error occurs, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

repairdisk

repairdisk= n [align=n][noerr]

Repairs the RAID-5 volume with the focus by replacing the failed RAID-5 member with the specified dynamic disk. The specified dynamic disk must have free space larger than or equal to the total size of the failed RAID-5 member.

n

Specifies the dynamic disk that replaces the failed RAID-5 member. The specified disk must have free space equal to or larger than the total size of the failed RAID-5 member.

align= n

Typically used with hardware RAID Logical Unit Number (LUN) arrays to improve performance when the logical units (LUs) are not cylinder aligned. Aligns a primary partition that is not cylinder aligned at the beginning of a disk and rounds the offset to the closest alignment boundary, where n is the number of kilobytes (KB) from the beginning of the disk to the closest alignment boundary. The align= n command fails if the primary partition is not at the beginning of the disk. If you use it with offset= n, the offset is within the first usable cylinder on the disk.

noerr

For scripting only. When an error occurs, DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

rescan

rescan

Locates new disks that might have been added to the computer.

retain

retain

Prepares an existing dynamic simple volume to use as a boot or system volume.

On an x86-based computer, creates a partition entry in the master boot record (MBR) on the dynamic simple volume with the focus. To create an MBR partition, the dynamic simple volume must start at a cylinder-aligned offset and be an integral number of cylinders.

On an Itanium-based computer, creates a partition entry in the GUID partition table (GPT) on the dynamic simple volume with the focus.

Ff794606.note(en-US,WinEmbedded.60).gifNote:
The retain command is intended for use only during unattended Setup or by OEMs.

selectdisk

selectdisk=[n]

Selects the specified disk and shifts the focus to it.

n

Specifies the disk number of the disk to receive the focus. If you do not specify a disk number, the select command lists the disk that currently has the focus. You can view the numbers for all disks on the computer by using the listdisk command.

selectpartition

selectpartition=[{n|d}]

Selects the specified partition and gives it focus. If you do not specify a partition, the select command lists the current partition with the focus. You can view the numbers of all partitions on the current disk by using the list partition command.

n

Specifies the number of the partition to receive the focus.

d

Specifies the drive letter or mount point path of the partition to receive the focus.

selectvolume

selectvolume=[{n|d}]

Selects the specified volume and shifts the focus to it. If you do not specify a volume, the select command lists the current volume with the focus. You can specify the volume by number, drive letter, or mount-point path. On a basic disk, selecting a volume also gives the corresponding partition focus. You can view the numbers of all volumes on the computer by using the listvolume command.

n

Specifies the number of the volume to receive the focus.

d

Specifies the drive letter or mount-point path of the volume to receive the focus.

DiskPart Scripting

By using the DiskPart 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 Standard 7 by using Image Builder in unattended mode, or when using the Sysprep tool. They do not support creating volumes other than the boot volume.

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

diskpart /s scriptname .txt

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

To redirect the DiskPart scripting output to a file, type the following:

diskpart /s scriptname .txt > logfile .txt

Where logfile is the name of the text file where DiskPart writes its output.

When DiskPart starts, the DiskPart version and computer name display at the command prompt. By default, if DiskPart encounters an error when it tries to perform a scripted task, DiskPart stops processing the script and displays an error code (unless you specified the noerr parameter). However, DiskPart always returns errors when it encounters syntax errors, regardless of whether you used the noerr parameter. The noerr parameter enables you to perform useful tasks such as using a single script to delete all partitions on all disks regardless of the total number of disks.

The following table lists the DiskPart error codes.

Error

Description

0

No errors occurred. The script ran without failure.

1

A fatal exception occurred. There might be a serious problem.

2

The parameters specified for a DiskPart command are incorrect.

3

DiskPart was unable to open the specified script or output file.

4

One of the services that DiskPart uses returned a failure.

5

A command syntax error occurred. The script failed because an object was incorrectly selected or was invalid for use with that command.