Diskpart usage (zt)

Source: Internet
Author: User

Diskpart.exe is a command interpretation in text mode.ProgramIt enables you to manage objects (disks, partitions, or volumes) by using scripts or directly entering them from a command prompt ). Before using the diskpart.exe command on a disk, partition, or volume, you must first list and select the objects to focus on. When an object has focus, any diskpart.exe command you type will apply to this object.

ExploitationList Disk,List volumeAndList PartitionCommand to list available objects and determine the object number or drive letter.List DiskAndList volumeCommand to display all disks and volumes on the computer. WhileList PartitionThe command only displays partitions on the disk with focus. UseListCommand, an asterisk (*) appears next to the object with focus (*). You can select an object by number or drive letter, for example, disk 0, partition 1, Volume 3, or volume C.

When an object is selected, the focus remains on that object until different objects are selected. For example, if you set focus on disk 0 and select volume 8 on Disk 2, the focus is shifted from disk 0 to volume 8 on Disk 2. Some commands automatically change the focus. For example, if a new partition is created, the focus is automatically transferred to the new partition.

You can only set the focus on the partitions on the selected disk. When a partition has focus, the related volume (if any) also has focus. When a volume has focus, if the volume is mapped to a specific partition, the related disk and partition also have focus. Otherwise, the focus on the disk and volume is lost.

Diskpart command

To view the command syntax, click the following command:

Active

On the Basic disk, mark the partition with focus as active. This notifies 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.

Key Points

    • DiskpartVerify that the partition has sufficient space to include the Startup file of the operating system.DiskpartDo not check the partition content. If a partition is marked as "active" by mistake and does not contain the Startup file of the operating system, your computer may fail to start.
Syntax

Active

Add Disk

Mirror a simple volume with focus to a specified disk.

Syntax

Add disk = N[ Noerr]

Parameters
N
Specify the disk to contain this image. You can only mirror simple volumes. The specified disk must have at least the same size as the simple volume to be mirrored.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartIncorrect CodeExit.

Assign

Assign a drive letter or mount point to a volume with focus. If no drive letter or mount point is specified, the next available drive letter is assigned. If the drive letter or mount point is already in use, an error occurs.

UseAssignCommand to change the drive letter associated with a removable drive.

You cannot assign drive letter to system volumes, boot volumes, or volumes that contain page files. In addition, you cannot allocate drive letter to the guid Partition Table (GPT) partition of the original device manufacturer (OEM) partition or any non-basic msdata partition.

Syntax

Assign[{ Letter = D| Mount = Path}] [ Noerr]

Parameters
Letter = D
The drive letter to be allocated to the volume.
Mount = Path
The mount point to be allocated to the volume.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Break Disk

It is only applicable to dynamic disks. The image volumes with focus are divided into two simple volumes. One simple volume retains the drive letter and all the mount points of the mirror volume, and the other simple volume receives the focus, so that one drive letter can be assigned to it.

By default, the content of the image volume is retained. Each part is a simple volume. ExploitationNokeepParameter. Only half of the image can be reserved as a simple volume, and the other half can be deleted and converted to available space. Both volumes do not receive the focus.

Syntax

Break disk = N[ Nokeep] [ Noerr]

Parameters
N
Specify the disk that contains the image volume.
Nokeep
Specify to retain only one mirror volume, and delete another simple volume and convert it to available space. Neither the reserved volume nor the available space receives the focus.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Clean

Delete any partition or volume format from a disk with focus. On the master startup record (MBR) disk, only the MBR partition information and hidden sector information are overwritten. On the guid Partition Table (GPT) disk, overwrite the GPT partition information, including protective MBR. Hidden sector information does not exist.

Syntax

Set All

Parameters
All
The information of all sectors on the specified disk is zero, so that all data on the disk is completely deleted.

Convert basic

Convert a blank Dynamic Disk to a basic disk.

Syntax

Convert basic[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Convert dynamic

Convert a basic disk to a dynamic disk.

Syntax

Convert dynamic[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Convert GPT

On an itanium-based computer, convert a blank basic disk with a master startup record (MBR) Partition style to a basic disk with a guid Partition Table (GPT) Partition style.

Key Points

    • The disk must be an empty disk to convert it to a GPT disk. Back up your data and delete all partitions or volumes before converting the disk.
Syntax

Convert GPT[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Convert MBR

On an itanium-based computer, convert a blank basic disk with a guid Partition Table (GPT) Partition style to a basic disk with a primary startup record (MBR) Partition style.

Key Points

    • The disk must be an empty disk to convert it to an MBR disk. Back up your data and delete all partitions or volumes before converting the disk.
Syntax

Convert MBR[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Create partition EFI

On an itanium-based computer, create a system partition for the extended firmware interface (EFI) on the guid Partition Table (GPT) disk. After a partition is created, the focus is shifted to the new partition.

Syntax

Create partition EFI[ Size = N] [ Offset= N] [ Noerr]

Parameters
Size = N
The partition size (MB ). If the partition size is not given, the partition continues until there is no idle space in the current area.
Offset = N
The Byte offset of the created partition. If no offset is given, the partition is placed in the first disk range with sufficient space to accommodate the partition.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Create partition extended

Create an extended partition on the current drive. After a partition is created, the focus is automatically transferred to the new partition. Only one extended partition can be created on each disk. This command fails if you try to create an extended partition in another extended partition. You must create an extended partition before creating a logical drive.

Syntax

Create partition extended[ Size = N] [ Offset = N] [ Noerr]

Parameters
Size = N
The size of the extended partition (MB ). If the partition size is not given, the partition continues until there is no available space in the region. The size of the extended partition is aligned by the cylinder. It is automatically rounded to the nearest cylindrical boundary. For example, if you specify a partition with a size of 500 mb, the partition is automatically rounded to 504 MB.
Offset = N
Applies only to the master startup record (MBR) disk. The Byte offset of the created extended partition. If no offset is given, the partition starts at the first idle position on the disk. The offset is aligned by the cylinder. The offset is automatically rounded to the nearest cylindrical boundary. For example, if the defined offset is 27 MB and the cylindrical size is 8 Mb, the offset is rounded to 24 MB.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Create partition logical

Create a logical drive in the extended partition. After a partition is created, the focus is automatically transferred to the new logical drive.

Syntax

Create partition logical[ Size = N] [ Offset = N] [ Noerr]

Parameters
Size = N
The size of the logical drive (MB ). If the partition size is not given, the partition continues until there is no idle space in the current area.
Offset = N
Applies only to the master startup record (MBR) disk. The Byte offset of the logical drive. The offset is aligned by the cylinder (that is, the offset is automatically rounded to fully fill the used cylinder size ). If no offset is given, the partition is placed in the first extended disk with sufficient space to accommodate the partition. The partition length must be at least Size = NThe specified number of bytes is the same. To specify the size of the logical drive, it must be smaller than the extended partition.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Create partition MSR

On an itanium-based computer, create a Microsoft retain (MSR) partition on the guid Partition Table (GPT) disk.

Be careful

    • Be careful when usingCreate partition MSRCommand. Because the GPT disk requires a specific partition layout, creating a Microsoft reserved partition will make the disk unreadable. In Windows XP 64-bit Edition On the GPT disk, the EFI system partition is the first partition on the disk, followed by the Microsoft reserved partition. The GPT disk used only to store data does not contain the EFI system partition. Therefore, the Microsoft reserved partition is the first partition.

      Windows XP 64-bit Edition Do not load Microsoft reserved partitions. You cannot store or delete data on them.

 

Create volume simple

Create a simple volume. After a new volume is created, the focus is automatically transferred to the new volume.

Syntax

Create volume simple[ Size = N] [ Disk = N] [ Noerr]

Parameters
Size = N
Volume size (MB ). If the volume size is not specified, the new volume occupies the remaining idle space on the disk.
Disk = N
A dynamic disk used to create a volume. If no disk is specified, the current disk is used.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Create volume stripe

Create a striped volume on the specified disk. After a new volume is created, the focus is automatically transferred to the new volume.

Syntax

Create volume stripe[ Size = N] [ Disk = N[,[ N, Role] [ Noerr]

Parameters
Size = N
The disk space is measured in megabytes (MB). If the size of each disk is not specified, the new volume occupies the minimum available idle space on the disk, and then each disk occupies the same disk space.
Disk = N
A dynamic disk used to create a volume. Size = NThe disk space is allocated to each disk.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Delete Disk

Delete a lost Dynamic Disk from the disk list.

Syntax

Delete Disk[Noerr] [Override]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.
Override
Enable DiskpartYou can delete all simple volumes on a disk. If the disk contains half an image volume, delete the half image from the disk. If the disk is a member of the raid-5 volume Delete disk overrideThe command fails.

Delete Partition

Delete partitions with focus on each basic disk. You cannot delete system partitions, boot partitions, or any partitions that contain active page files or fault dump (memory dump.

Be careful

    • Deleting a partition on a dynamic disk deletes all offline dynamic volumes on the disk, which destroys any data and converts the disk to a basic disk. To delete a dynamic volume, always useDelete volumeCommand.

Partitions can be deleted from a dynamic disk, but cannot be created. For example, you can delete the unrecognized guid Partition Table (GPT) partition on the dynamic GPT disk. Deleting such a partition will not make the resulting idle space available. This command is specially used when it cannot be used.CleanReclaim the damaged offline dynamic disk space in case of an emergency during command execution.

Syntax

Delete Partition[Noerr] [Override]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.
Override
Enable DiskpartYou can delete any partition regardless of its type. Generally, DiskpartOnly partitions with known data can be deleted.

Delete volume

Delete the selected volume. You cannot delete system volumes, boot volumes, or any volumes that contain active page files or Failover (memory dump.

Syntax

Delete volume[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Detail Disk

Displays the attributes of the selected disk and Its volumes.

Syntax

Detail Disk

Detail volume

Displays the disk that stores the current volume.

Syntax

Detail volume

Exit

ExitDiskpartCommand Interpreter.

Syntax

Exit

Extend

Expand the volume with focus to the nearest unallocated space. For basic volumes, unallocated space must be on the same disk and then (the sector offset is greater than) Partitions with focus. Dynamic simple volumes or cross-zone volumes can be expanded to an empty space on any dynamic disk. Use this command to expand an existing volume to a new space.

If the partition was previously formatted using the NTFS file system, the file system will automatically expand to occupy a larger partition. No data is lost. If the partition was previously formatted using a non-NTFS file system format, this command fails without any changes to the partition.

Cannot expand the current system or start the partition.

Syntax

Extend[Size =N] [Disk =N] [Noerr]

Parameters
Size = N
The size of the space (MB) added to the current partition ). If no size is specified, the disk is extended to occupy all the nearest unallocated space.
Disk = N
The dynamic disk used to expand the volume. Size = NDisk Space will be allocated on the disk. If no disk is specified, the volume is extended on the current disk.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Help

Displays a list of available commands.

Syntax

Help

Import

Import the external disk group to the disk group of the local computer.ImportCommand import is the same as that of a disk with a focus.

Syntax

Import[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

List Disk

Displays the disk list and the list of disk information, such as the size, available space, whether the disk is a basic disk or a dynamic disk, and whether the disk uses the master startup record (MBR) or GUID Partition Table (GPT) partition style. A disk marked with an asterisk (*) has a focus.

Syntax

List Disk

List Partition

Displays the partitions listed in the Partition Table of the current partition. On a dynamic disk, these partitions may not correspond to dynamic volumes on the disk. The reason for this deviation is that the dynamic disk contains items in the Partition Table of the current system volume or startup volume on the disk and a partition that occupies the remaining disk space for the dynamic volume.

Syntax

List Partition

List volume

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

Syntax

List volume

Online

Bring offline disks or volumes with focus online.

Syntax

Online[Noerr]

Parameters
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Rem

Provides a method to add comments to a script.

Syntax

Rem

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

Delete the drive letter or mount point from the volume with focus. IfAllTo delete all the current drive letter and mount point. If the drive letter or mount point is not specifiedDiskpartThe first drive letter or mount point it encounters will be deleted.

RemoveCommand to change the drive letter associated with the removable drive. The drive letter of the system volume, start volume, or page volume cannot be deleted. In addition, the drive letter of the following partition cannot be deleted: OEM partition, any GPT partition with an unrecognized guid, or any special, non-data GPT partition (for example, EFI system partition ).

Syntax

Remove[{ Letter = D| Mount = Path[ All]}] [ Noerr]

Parameters
Letter = D
The drive letter to delete.
Mount = Path
The path of the mount point to be deleted.
All
Delete all current drive letters and mount points.
Noerr
Only for scripts. When an error occurs, specify DiskpartContinue to process the command, just as the error does not occur. No NoerrParameter, error will cause DiskpartExit with the error code.

Rescan

Find the new disk that has been added to the computer.

Syntax

Rescan

Retain

Prepare an existing dynamic simple volume for use as the start volume or system volume.

On an x86 computer, create a partition item in the master startup record (MBR) of a dynamic simple volume with focus. To create an MBR partition, the dynamic simple volume must start from the offset aligned by the cylindrical and its size is an integer of the cylindrical.

On an itanium-based computer, create a partition item in the guid Partition Table (GPT) on a dynamic simple volume with focus.

Note:

    • RetainCommands are used only during "unattended installation" or by the original device manufacturer (OEM.
Syntax

Retain

Select Disk

Select a disk and move the focus to the disk.

Syntax

Select disk =[ N]

Parameters
N
The disk Number of the disk to receive the focus. If no disk number is specified, SelectCommand to list the current disk with focus. Use List DiskCommand to view the numbers of all disks on the computer.

Select Partition

Select the specified partition and give it focus. If no partition is specified,SelectThe command will list the current partition with focus. UseList PartitionCommand to view the number of all partitions on the current disk.

Syntax

Select partition =[{ N| D}]

Parameters
N
ID of the partition to receive the focus.
D
The drive letter or mount point path of the partition to receive focus.

Select volume

Select a volume and move the focus to the volume. If no volume is specified,SelectThe command will list the current volume with focus. You can specify the volume by number, drive letter, or mount point path. On the Basic disk, selecting a volume also gives the corresponding partition focus. UseList volumeCommand to view the numbers of all volumes on the computer.

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

ExploitationDiskpartYou can create a script to automatically execute disk-related tasks (such as creating a volume or converting a disk to a dynamic disk. Deploy with "unattended installation" or sysprep (they do not support creating volumes not starting volumes) Windows To create scripts for these tasks.

To startDiskpartScript, enter:

Diskpart/s Scriptname.txt

Where,Scriptname.txtIs the name of the text file containing the script.

To redirectDiskpartFor the Script output of a file, type:

Diskpart/s Scriptname.txt>Logfile.txt

Where,Logfile.txtYesDiskpartName of the text file written to its output.

WhenDiskpartAt startup,DiskpartThe version and computer name are displayed at the command prompt. By default, ifDiskpartAn error occurred while trying to execute the script task,DiskpartIt stops processing the script and displays an error code (unlessNoerrParameters ). However,DiskpartErrors are always returned when syntax errors occur, regardless of whether or not they are used.NoerrParameters.NoerrParameters enable you to execute many useful tasks. For example, you can use a single script to delete all partitions on all disks, regardless of the number of disks.

The following table listsDiskpartError code:

& Lt; table width = "100%" & gt; The parameter specified for the
error description
0 no error occurred. Run the entire script.
1 a fatal exception event occurs. Serious problems may occur.
2 diskpart command is incorrect.
3 diskpart cannot open the specified script or output file.
4 one of the tasks used by diskpart fails to be returned.
5 A command syntax error occurs. The script fails because the object is incorrectly selected or is invalid when used with this command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.