[FW] DISKPART Command

Copied from Learn how to master the DISKPART command by TechyGuy. Used as a quick reference for myself.

Commands Focus (Select/List)

The DISKPART command uses mainly two types of commands: 

– Those which specify the target or the scope of action: List, Help, Rem, Select, Exit 
– Those that apply directly to the pre element: Active, Assign, Create, Extend, Shrink … 

Most commands work on the pre element, in other words, the element that has the focus. It is, in the controls, the selected disk, the volume selected, the selected partition. 

The LIST command 

They enable the list of disks, partitions and volumes: 

LIST DISK 
Gives the list of drives recognized by the system. The disc preceded by a "*" is the disk that currently has the Focus Diskpart. 

LIST PARTITION 
Gives a list of partitions on the disk that has the Focus 

LIST VOLUME 
Provides a list of all volumes (unit disc) declared in the system 

The SELECT 

They can change the "Focus" (ie the selected item). 

SELECT DISK n 
Select the disk that has the focus. The "n" is the disk number as given by the LIST DISK command. 

SELECT PARTITION n 
Select the partition that has the focus. The "n" is the partition number on the disk that has the focus and as indicated by the LIST PARTITION command 

SELECT VOLUME l 
Select the volume designated for a Focus. The parameter "l" is the letter assigned to the unit disc. 

The capture demonstrates the combined use of the command LIST and SELECT. 

Erase and repartition

The DISKPART commands make it possible to create and delete partitions. To do so, mainly 6 commands:

CLEAN 
One of the most practical and most dangerous: it removes at once all the partitions on the selected disk. 

CLEAN ALL 
Equally dangerous, this command removes all of a sudden the selected disk partitions but also writes zero byte and every sector of the disk. Easy to completely erase a disk. 

CREATE PARTITION PRIMARY size = n 
Creates a primary partition the size defined by the "n". 

CREATE EXTENDED PARTITION size = n 
Creates an extended partition to the size defined by the "n". 

CREATE PARTITION LOGICAL size = n 
Creates a logical partition in the extended partition to the size defined by the "n". 

DELETE PARTITION 
Clears the partition that has the focus (be careful to check which partition is selected by a List Partition before running this command). 

Example of implementation

If you have a USB drive (we assume here Disc No. 3), you can have fun with the following sequence to erase everything and re-partitioning a primary partition of 1GB and a secondary logical partition on the rest of space disk: 

LIST DISK 
SELECT DISK 3 
CLEAN 
CREATE PARTITION PRIMARY size = 1000 
CREATE PARTITION EXTENDED 
CREATE PARTITION LOGICAL 
RESCAN
LIST PARTITION 

Quote:

Note in passing the command RESCAN who force DISKPART to refresh the data and take into account the creation of disk partitions and previously realized.


Assign and resize volumes


DISKPART can assign letters to partitions of volumes, but also to remove those letters (which is to hide the Windows partition). 

But above all DISKPART (Windows Vista and Windows 7) is used to resize partitions. 

The instructions to know are: 

ASSIGN LETTER = l 
Assign selected volume (which has the focus) the letter indicated by the "l" 

REMOVE LETTER = l 
Remove the drive letter associated with the disk volume that has the focus. The command REMOVE/ALL deletes all the letters of all volumes (dangerous). 

EXTEND Size=n
Extends the selected volume (the one that has the focus) by adding the size indicated by "n". The command only works on NTFS volumes 

SHRINK QUERYMAX 
Indicates how many megabytes the currently selected NTFS volume can be reduced (depending on its defragmentation and not his occupation) 

SHRINK DESIRED MINIMUM = x = y 
Reduces the disk at least the value "y", while trying to reach the value "x" if possible. 

Example of use of commands 

LIST DISK 
SELECT DISK 3 
CLEAN 
CREATE PARTITION PRIMARY size = 1000 
ASSIGN LETTER = G 
FORMAT FS = NTFS QUICK 
LIST VOLUME
SELECT VOLUME G 
E
XTEND size = 500 
SHRINK QUERYMAX 
SHRINK MINIMUM=500 DESIRED=800
LIST VOLUME

Quote:

Note in passing the command FORMAT which can format a partition.


Conversions and Details

DiskPart allows for all sorts of conversions volumes not always feasible since the Windows interface. 

Orders for conversion 

CONVERT MBR 
Converts a basic GPT disk or dynamic to MBR classic disk

CONVERT GPT 
Only 64 bits. Converts the selected MBR disk to GPT disk 

CONVERT DYNAMIC 
Convert a basic disk to dynamic disk (useful on servers in particular) without losing data 

CONVERT BASIC 
Convert a dynamic disk into basic disk. Beware, the disc must be empty of all data. 

Ordering information 

These commands display additional details on the disks, partitions and volumes. 

DETAIL DISK 
Detailed information of the disk that has the focus 

DETAIL PARTITION 
Detailed information of the partition that has the focus 

DETAIL VOLUME 
Detailed information of the volume that has the focus 

Example

LIST DISK 
SELECT DISK 0 
DETAIL DISK 
SELECT PARTITION 1 
DETAIL PARTITION 
SELECT VOLUME C 
DETAIL VOLUME 


Other useful commands

Here are other commands to know: 

? 
Provides a list of all commands 

HELP command 
Explains the parameters of a command (example: HELP SHRINK

EXIT 
Quits DISKPART and returns to the command prompt classic 

OFFLINE DISK 
Met "offline" the current disc 

ONLINE DISK 
Reconnect the disk placed OFFLINE 

ACTIVE 
Because of the partition that has the Focus, the new boot partition (Active Partition) 


Scripting

Diskpart supports scripted operations. To initiate a Diskpart script, use the diskpart /s script.txt command. You can script Diskpart on Windows XP, Windows 2000, Remote Installation Services (RIS) unattended install environments, or on the Windows Preinstall Environment (PE) for OEMs.

By default, Diskpart can quit command processing and return an error code if there is a problem in the script. To continue to run a script in this scenario, include the noerr parameter on the command. This parameter allows you to use a single script to delete all partitions on all data drives, regardless of the total number of drives. However, not all commands support the noerr parameter. Even if you use the noerr parameter, an error is always returned on command syntax errors.

The following list describes the error codes for Diskpart:

  • 0 - No error occurred. The entire script ran without failure.
  • 1 - A fatal exception occurred. There may be a serious problem.
  • 2 - The arguments specified on a Diskpart command line were incorrect.
  • 3 - Diskpart was unable to open the specified script or output file.
  • 4 - One of the services Diskpart uses returned a failure.
  • 5 - A command syntax error occurred. The script failed because an object was improperly selected or was invalid for use with that command.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s