Поделиться через


DiskPart

DiskPart.exe is a text-mode command interpreter that enables you to manage objects (disks, partitions, or volumes) by using scripts or direct input from a command prompt. Before you can use DiskPart.exe commands on a disk, partition, or volume, you must first list and then select the object to give it focus. When an object has focus, any DiskPart.exe commands that you type act on that 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 on the computer. However, the list partition command only displays partitions on the disk that has 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 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 switches to the new partition.

You can only give focus to a partition on the selected disk. When a partition has focus, the related volume (if any) also has 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 commands

To view the command syntax, click a command:

active

On basic disks, marks the partition with 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.

 Important

  • DiskPart verifies only that the partition is capable of containing an operating system's startup files. DiskPart does not check the contents of the partition. If you mistakenly mark a partition as "active" and it does not contain the operating system's startup files, your computer might not start.

Syntax

active

add disk

Mirrors the simple volume with focus to the specified disk.

Syntax

add disk= n [noerr]

Parameters

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 you want to mirror.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

Assigns a drive letter or mount point to the volume with focus. If no drive letter or mount point is specified, then the next available drive letter is assigned. If the drive letter or mount point is already in use, 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. In addition, you cannot assign a drive letter to an Original Equipment Manufacturer (OEM) partition or any GUID Partition Table (GPT) partition other than a basic MSDATA partition.

Syntax

assign [{**letter=**d|**mount=**Path}] [noerr]

Parameters

letter= d   : The drive letter you want to assign to the volume.

mount= Path   : The mount point path you want to assign to the volume.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

Applies to dynamic disks only. Breaks the mirrored volume with 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 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. By using the nokeep parameter, you retain only one half of the mirror as a simple volume, while the other half is deleted and converted to free space. Neither volume receives the focus.

Syntax

break disk= n [nokeep] [noerr]

Parameters

n   : Specifies the disk that contains the mirrored volume.

nokeep   : Specifies that only one of the mirrored volumes is retained; the other simple volume is deleted and converted to free space. Neither the volume nor the free space receive the focus.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

Removes any and all partition or volume formatting from the disk with 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, including the Protective MBR, is overwritten. There is no hidden sector information.

Syntax

clean [all]

Parameter

all   : Specifies that each and every sector on the disk is zeroed, which completely deletes all data contained on the disk.

convert basic

Converts an empty dynamic disk into a basic disk

Syntax

convert basic [noerr]

Parameter

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

Converts a basic disk into a dynamic disk

Syntax

convert dynamic [noerr]

Parameter

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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

 Important

  • 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.

Syntax

convert gpt [noerr]

Parameter

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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

 Important

  • 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.

Syntax

convert mbr [noerr]

Parameter

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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.

Syntax

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

Parameters

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

offset = n   : The byte offset at which to create the partition. If no offset is given, the partition is placed in the first disk extent that is large enough to hold it.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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 attempt to create an extended partition within another extended partition. You must create an extended partition before you can create logical drives.

Syntax

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

Parameters

size= n   : The size of the extended partition in megabytes (MB). If no size is given, then the partition continues until there is no more free space in the region. The size is cylinder snapped. The size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition would be rounded up to 504 MB.

offset= n   : Applies to master boot record (MBR) disks only. The byte offset at which to create the extended partition If no offset is given, the partition will start at the beginning of the first free space on the disk. The offset is cylinder snapped. 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.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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

Syntax

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

Parameters

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

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

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

On Itanium-based computers, creates a Microsoft Reserved (MSR) partition on a GUID Partition Table (GPT) disk.

 Caution

  • Be very careful when using the create partition msr command. Because GPT disks require a specific partition layout, creating Microsoft reserved partitions could cause the disk to become unreadable. On GPT disks that are used to start Windows XP 64-Bit Edition, 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 64-Bit Edition does not mount Microsoft reserved partitions. You cannot store data on them and you cannot delete them.

Syntax

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

Parameters

size= n   : The size of the partition in megabytes (MB). The partition is at least as long in bytes as the number 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   : 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 is rounded up to completely fill whatever sector size is being used. If no offset is given, then the partition is placed in the first disk extent that is large enough to hold it.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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 primary

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.

Syntax

create partition primary [**size=**n] [**offset=**n] [ID={byte|GUID}] [noerr]

Parameters

size= n 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. The size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition would be rounded up to 504 MB. **offset=**n The byte offset at which to create the partition. If no offset is given, the partition will start at the beginning of the first free space on the disk. For master boot record (MBR) disks, the offset is cylinder snapped. 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. ID={byte|GUID} Intended for Original Equipment Manufacturer (OEM) use only.

 Caution

  • Creating partitions with this parameter might cause your computer to crash or be unable to start up. Unless you are an OEM or an IT professional experienced with GPT disks, do not create partitions on GPT disks using the **ID=**byte | GUID parameter. Instead, always use the create partition efi command to create EFI System partitions, the create partition msr 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.

For MBR disks, you can specify a partition type byte, in hexadecimal form, for the partition. If no partition type byte is specified on an MBR disk, the create partition primary command creates a partition of type 0x6. Any partition type byte can be specified with the **ID=**byte | GUID parameter. DiskPart does not check the partition type byte for validity, nor does it perform any other checking of the ID parameter.

For GPT disks you can specify a partition type GUID for the partition you want to create:

  • EFI System partition: c12a7328-f81f-11d2-ba4b-00a0c93ec93b

  • Microsoft reserved partition: e3c9e316-0b5c-4db8-817d-f92df00215ae

  • MSDATA 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 no partition type GUID is specified, the create partition primary command creates an MSDATA partition. Any partition type can be specified with the ID={byte | GUID} parameter. DiskPart does not check the partition GUID for validity, nor does it perform any other checking of the ID parameter.

noerr For scripting only. When an error is encountered, specifies that DiskPart continue 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 volume raid

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

Syntax

create volume raid [**size=**n] [**disk=**n[,[n,]] [noerr]

Parameters

size= n   : The amount of disk space, in megabytes (MB), that the volume will occupy on each disk. If no size is given, the largest possible RAID-5 volume will be created. The disk with 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 of the disk space is required for parity.

disk= n   : The dynamic disks on which to create the volume. An amount of space equal to **size=**n is allocated on each disk.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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 volume simple

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

Syntax

create volume simple [**size=**n] [**disk=**n] [noerr]

Parameters

size= n/i>   : The size of the volume in megabytes (MB). If no size is given, the new volume takes up the remaining free space on the disk.

disk= n   : The dynamic disk on which to create the volume. If no disk is given, the current disk is used.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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 volume stripe

Creates a striped volume on the specified disks. After you create the volume, the focus automatically shifts to the new volume.

Syntax

create volume stripe [**size=**n] [**disk=**n[,[n,]] [noerr]

Parameters

size= n   : The amount of disk space, in megabytes (MB), that the volume will occupy on each disk. If no size is given, the new volume takes up the remaining free space on the smallest disk and an equal amount of space on each subsequent disk.

disk= n   : The dynamic disks on which to create the volume. An amount of space equal to **size=**n is allocated on each disk.

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

delete disk

Deletes a missing dynamic disk from the disk list.

Syntax

delete disk [noerr] [override]

Parameters

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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.

delete partition

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

 Caution

  • Deleting a partition on a dynamic disk can delete all offline dynamic volumes on the disk, thus destroying any data and converting the disk to a basic disk. To delete a dynamic volume, always use the delete volume command instead.

Partitions can be deleted from dynamic disks, but they should not be created. For example, it is possible to delete an unrecognized GUID Partition Table (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.

Syntax

delete partition [noerr] [override]

Parameters

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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. Typically, DiskPart only allows you to delete known data partitions.

delete volume

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).

Syntax

delete volume [noerr]

Parameter

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

detail disk

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

Syntax

detail disk

detail volume

Displays the disks on which the current volume resides.

Syntax

detail volume

exit

Exits the DiskPart command interpreter.

Syntax

exit

extend

Extends the volume with focus into next contiguous unallocated space. For basic volumes, the unallocated space must be on the same disk as, and must follow (be of higher sector offset than) the partition with focus. A dynamic simple or spanned volume can be extended to any empty space on any dynamic disk 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 with no change to the partition.

You cannot extend the current system or boot partitions.

Syntax

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

Parameters

size= n   : The amount of space, in megabytes (MB), to add to the current partition. If you do not specify a size, the disk is extended to take up all of the next contiguous unallocated space.

disk= n   : 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 is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

help

Displays a list of the available commands.

Syntax

help

import

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 focus.

Syntax

import [noerr]

Parameter

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

list disk

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 focus.

Syntax

list disk

list partition

Displays the partitions listed in the partition table of the current disk. On dynamic disks, these partitions may not correspond to the dynamic volumes on the disk. This discrepancy occurs because dynamic disks contain entries in the partition table for the system volume or boot volume (if present on the disk) and a partition that occupies the remainder of the disk in order to reserve the space for use by dynamic volumes.

Syntax

list partition

list volume

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

Syntax

list volume

online

Brings an offline disk or volume with focus online.

Syntax

online [noerr]

Parameter

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

rem

Provides a way to add comments to a script.

Syntax

rem

Examples

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

Removes a drive letter or mount point from the volume with focus. If the all parameter is used, all current drive letters and mount points are removed. If no drive letter or mount point is specified, then DiskPart removes the first drive letter or mount point it encounters.

The remove command can be used 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.

Syntax

remove [{**letter=**d|**mount=**Path [all]}] [noerr]

Parameters

letter= d   : The drive letter to be removed.

mount= Path   : The mount point path to be removed.

all   : Removes all current drive letters and mount points.

noerr   : For scripting only. When an error is encountered, specifies that DiskPart continue 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

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

Syntax

rescan

retain

Prepares an existing dynamic simple volume to be used 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 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, creates a partition entry in the GUID partition table (GPT) on the dynamic simple volume with focus.

Note

  • The retain command is intended for use only during Unattended Setup or by Original Equipment Manufacturers (OEMs).

Syntax

retain

select disk

Selects the specified disk and shifts the focus to it.

Syntax

select disk=[n]

Parameters

n   : The disk number of the disk to receive focus. If no disk number is specified, 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 list disk command.

select partition

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

Syntax

select partition=[{n|d}]

Parameters

n   : The number of the partition to receive the focus.

d   : The drive letter or mount point path of the partition to receive the focus.

select volume

Selects the specified volume and shifts the focus to it. If no volume is specified, the select command lists the current volume with 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 list volume command.

Syntax

select volume=[{n|d}]

Parameters

n   : The number of the volume to receive the focus.

d   : The drive letter or mount point path of the volume to receive the focus.

DiskPart scripting

Using DiskPart, you can create scripts to automate disk-related tasks, such as creating volumes or converting disks to dynamic. Scripting these tasks is useful if you are deploying Windows by using Unattended Setup or Sysprep, which do not support creating volumes other than the boot volume

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

DiskPart /S scriptname.txt

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

To redirect DiskPart's scripting output to a file, type:

DiskPart /S scriptname.txt > logfile.txt

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

When DiskPart starts, the DiskPart version and computer name are displayed at the command prompt. By default, if DiskPart encounters an error while attempting 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 entire script ran without failure.

1

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

2

The parameters specified for a DiskPart command 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.

Command-line reference A-Z

Disk Management overview