RADIO ONLINE (Click radio icon to listen)

Thursday 22 January 2015

Title: List of DISKPART commands

List of DISKPART commands

List of DISKPART commands
List of DISKPART commands


DiskPart is one of the most powerful Windows commands. It allows you to accurately manage the partitions, resizing them, their assignment and their formatting. It can be incorporated into a script, and most importantly, may itself execute scripts. It is essential to restructure the USB key and is a formidable weapon to automate deployment of Windows on parking machines.


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 focus, any DiskPart 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 displays only partitions on the disk that have 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.

Warning

The DISKPART command is for an informed public that already have a minimum knowledge about partitioning and formatting disks and the use of command-mode "command prompt". 

Misuse of this command can cause the loss of your data on your disks. We do not recommend beginners to use DISKPART. Most DiskPart functions are available as user-friendly Windows interface by clicking the right button on "My Computer" (or "Computer" on Vista) and selecting "Manage from the context menu" before selecting the module "Disk Management". 

DISKPART is present in XP, Vista and Windows 7. However, the XP version is more limited because it does not offer advanced features for resizing partitions, for example.

To start DISKPART, do the following:

- On Windows XP 
Go to Start> All Programs> Accessories 
Click Command Prompt. 

- For Windows Vista/Windows 7 
Go to Start> All Programs> Accessories 
Right click on the Command Prompt icon 
Select Run as administrator from the context menu.




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






It is true that running diskpart /s script.txt usually exits when errors occur and not all commands support the noerr parameter.
The workaround for this , as usually, is simple :
just run diskpart as follows: diskpart <script.txt
ét voila. Errors are ignored and script continues on next line.
I use it this way to make sure the CDROM drive (usually volume 0) gets assigned another drive letter than D , but on some hardware here, assigning it to letter "E:" gives an error about the disk not being empty or something.
I made the script do:


select volume 0
assign letter g
assign letter f
assign letter e


so it gets the lowest driveletter without erroring out....




If you like this post, kindly linkback to this post entry by copying one of the codes below..

URL Of Post: Paste This HTML Code On Your Page:

1 comment: