diskpart | new in WS2003 |
Manages disks, partitions, and volumes from the command line.
diskpart diskpart /s script
Enters interactive mode and displays the DISKPART> prompt, waiting for you to enter diskpart commands
Specifies a script containing a series of diskpart commands to execute sequentially
The following is a summary of diskpart commands that can be used either interactively or in scripts. Note that each command has its own unique syntax, which is summarized briefly .
Marks the selected basic partition as active.
Adds the specified disk as a mirror to the selected simple volume.
Assigns the specified drive letter or mount point to the selected volume. If assign is used alone, the next available drive letter is used. Does not work with system/boot volumes or volumes where a paging file resides.
Enables and disables automatic mounting of basic volumes. Automounting is enabled by default and should be disabled only for storage area networks.
Breaks a mirror set into two simple volumes and changes the focus to the specified volume so you can assign it a drive letter. The nokeep option causes the mirrored volume to be converted to free space instead.
Deletes the configuration information from the selected disk by overwriting the MBR. The all option sets every sector to zero to delete all data on the disk.
Converts a dynamic disk to basic (must delete all volumes first).
Converts a basic disk to dynamic.
Creates a primary partition of size N megabytes and shifts focus to the new partition (if no size is specified, the partition is as large as possible).
Creates an extended partition of size N megabytes and shifts focus to the new partition (if no size is specified, the partition is as large as possible).
Creates a logical drive of size N megabytes within the extended partition and shifts focus to the new logical drive (if no size is specified, the partition is as large as possible).
Creates a RAID-5 volume from simple volumes of size N megabytes on the specified dynamic disks. If no size is specified, the largest possible volume size is used. After the RAID-5 volume is created, it assumes the focus.
Creates a simple volume of size N megabytes on the specified dynamic disk. If no size is specified, the partition is as large as possible, and if no disk is specified, the currently selected disk is used. After the volume is created, it assumes the focus.
Creates a striped volume from simple volumes of size N megabytes on the specified dynamic disks. If no size is specified, the largest possible volume size will be used. After the striped volume is created, it assumes the focus.
Deletes a missing dynamic disk from the disk list. The override option deletes all simple volumes on the disk but doesn't work if the disk is part of a RAID-5 volume.
Deletes the selected partition on a basic disk. The override option deletes nonstandard partitions.
Deletes the selected volume (won't work for system/boot volumes or volumes containing the pagefile).
Displays properties of disk, partition, or volume.
Exits diskpart when running in interactive mode.
Extends the selected partition on a basic disk using adjacent contiguous free space (if any) from the disk on which the partition resides.
Extends the selected volume on a dynamic disk using contiguous free space on the specified dynamic disk.
Imports every disk that belongs to the foreign disk group to which the currently selected disk belongs.
Marks the current basic partition as inactive.
Lists the disks on the local machine or the partitions/volumes on the currently selected disk. If volume option is used with basic disks, logical volumes are displayed instead.
Brings online a disk that is currently marked offline.
Used to comment scripts.
Removes the specified drive letter or mount point assignment or all drive letters and mount points. The dismount option closes all handles to the partition or volume before dismounting it. Does not work with system/boot volumes or volumes on which the pagefile resides.
Repairs a failed disk on a RAID-5 volume using the specified disk.
Rescans the computer looking for new disks and volumes that may have been added.
Prepares a simple volume to be used as a system/boot volume during unattended Setup.
Changes the focus of diskpart to the specified disk.
Changes the focus of diskpart to the specified partition.
Changes the focus of diskpart to the specified volume.
Run diskpart interactively:
diskpart Microsoft DiskPart version 5.2.3763 Copyright (C) 1999-2001 Microsoft Corporation. On computer: ESRV210D DISKPART>
List the fixed disks on the computer:
list disk Disk ### Status Size Free Dyn Gpt -------- ---------- ------- ------- --- --- Disk 0 Online 37 GB 27 GB
Select disk 0 to give it the focus for further diskpart commands:
select disk=0 Disk 0 is now the selected disk.
List the partitions on the selected basic disk:
list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- Partition 1 Primary 10 GB 32 KB Partition 2 Primary 502 MB 10 GB
List the logical volumes on the selected basic disk:
list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 0 D CD-ROM 0 B Healthy Volume 1 C NTFS Partition 10 GB Healthy System Volume 2 E New Volume NTFS Partition 502 MB Healthy
Note that the CD-ROM drive shows up as a logical volume because it has a drive letter assigned. Note also that volume 1 is the system volume.
Create a new primary partition 2 GB in size:
create partition primary size=2048 DiskPart succeeded in creating the specified partition.
Verify the result:
list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 0 D CD-ROM 0 B Healthy Volume 1 C NTFS Partition 10 GB Healthy System Volume 2 E New Volume NTFS Partition 502 MB Healthy * Volume 3 RAW Partition 2055 MB Healthy
The asterisk beside volume 3 indicates that this newly created volume has the focus. Note also that volume 3 has no drive letter assigned, so let's assign one to it:
assign letter=G DiskPart successfully assigned the drive letter or mount point.
Verify:
list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 0 D CD-ROM 0 B Healthy Volume 1 C NTFS Partition 10 GB Healthy System Volume 2 E New Volume NTFS Partition 502 MB Healthy * Volume 3 G RAW Partition 2055 MB Healthy
Change the focus to volume 2 so it can be deleted:
select volume=2 Volume 2 is the selected volume. delete volume DiskPart successfully deleted the volume.
Verify:
list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 0 D CD-ROM 0 B Healthy Volume 1 C NTFS Partition 10 GB Healthy System Volume 3 G RAW Partition 2055 MB Healthy
Now no volume has the focus, so let's select volume 3 and extend it 1 GB:
select volume 3 Volume 3 is the selected volume. extend size=1024 DiskPart successfully extended the volume.
Verify:
list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 0 D CD-ROM 0 B Healthy Volume 1 C NTFS Partition 10 GB Healthy System * Volume 3 G RAW Partition 3083 MB Healthy
Display properties of selected volume:
detail volume Disk ### Status Size Free Dyn Gpt -------- ---------- ------- ------- --- --- * Disk 0 Online 37 GB 24 GB
Display properties of selected disk:
detail disk MAXTOR 6L040J2 Disk ID: C95AC95A Type : ATA Bus : 0 Target : 0 LUN ID : 0 Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- ----- Volume 1 C NTFS Partition 10 GB Healthy System * Volume 3 G RAW Partition 3083 MB Healthy
Quit diskpart interactive mode:
exit Leaving DiskPart... C:\>
When running diskpart commands from a script, you can redirect the output to a text file to view later by:
diskpart /s script > file.txt
If you use more than one script with diskpart in a batch file, add timeout /t 15 before each diskpart /s script command to ensure the first tasks are completed before the next tasks are begun.
If an error occurs while running a diskpart command, the task stops, and an error code is displayed. If you add a noerr option to the command, the command is processed as if the error never occurred. diskpart error codes are as follows :
No errors. The script ran successfully.
Fatal exception.
Incorrect parameters for the diskpart command.
Unable to open the specified script or output file.
A service has returned an error.
Invalid command syntax.
chkdsk , chkntfs , convert , defrag , Disks , format , label , mountvol