Follow Us

We use cookies to provide you with a better experience. If you continue to use this site, we'll assume you're happy with this. Alternatively, click here to find out how to manage these cookies

hide cookie message

How to... manage disks with Windows Server 2003

Disk management from the command line.

Article comments
The new DISKPART command provides command line functionality equivalent to the features of the Logical Disk Manager (Disk Management in Computer Management). This now means you can use a command prompt to list, create, modify and delete the disks and volumes on your system. Diskpart commands can be incorporated into scripts, so disk and volume operations can be automated. Figure 1 shows the output from a simple list command. To get started, issue the diskpart command. This opens the command shell from which subcommands can be entered.
C:\>diskpart

Microsoft DiskPart version 5.2.3790
Copyright (C) 1999-2001 Microsoft Corporation.
On computer: BART

DISKPART> list disk

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
  Disk 0    Online       112 GB    77 GB

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   NRMEFPP_EN   CDFS   DVD-ROM      543 MB  Healthy
  Volume 1     E                NTFS   Partition   6001 MB  Healthy    System
  Volume 2     P   Business     NTFS   Partition     29 GB  Healthy
  Volume 3     C   ZIP-100      FAT32  Removeable    96 MB  Healthy

DISKPART>
Figure 1: Starting Diskpart Diskpart actions (such as create and delete) operate on objects that have the current focus. The object in focus can be chosen with the select subcommand, figure 2 shows the selection of a specific disk and volume.
DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list disk

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
* Disk 0    Online       112 GB    77 GB

DISKPART> select volume 2

Volume 2 is the selected volume.

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   NRMEFPP_EN   CDFS   DVD-ROM      543 MB  Healthy
  Volume 1     E                NTFS   Partition   6001 MB  Healthy    System
* Volume 2     P   Business     NTFS   Partition     29 GB  Healthy
  Volume 3     C   ZIP-100      FAT32  Removeable    96 MB  Healthy

DISKPART>
Figure 2: Example output Note how the object that has the current focus is marked with an asterisk ("*").

Now that we have the basic concepts established, we can try something more useful. Here in figure 3, we create a new partition, display it, then delete it. Note how the new partition immediately gains the focus on creation.
DISKPART> create partition extended

DiskPart succeeded in creating the specified partition.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary           6001 MB    32 KB
  Partition 2    Primary             29 GB  6001 MB
* Partition 3    Extended            77 GB    35 GB

DISKPART> delete partition

DiskPart successfully deleted the selected partition.

DISKPART>
Figure 3: creating and deleting a partition. A note of caution is required at this point. You will see that no warning is given before attempting to delete the partition that was just created. This applies equally to a partition or volume that is formatted and contains active data. You need to be very careful that you are sure you have selected the partition or volume you intend to delete. There are plenty of other commands:
Command Description
active On basic disks, marks the partition with focus as active.
add disk Mirrors the simple volume with focus to a specified disk.
assign Assigns a drive letter to the volume with focus.
automount Enables the automatic mounting of new basic volumes.
break disk Breaks the mirrored volume with focus into simple volumes.
clean Deletes all data on a disk, setting all sectors to zero.
convert basic Converts an empty dynamic disk to a basic disk.
create partition extended Creates an extended partition on the current drive.
create partition logical Creates a logical drive on the current partition.
create partition primary Creates a primary partition on the current basic disk.
create volume raid Creates RAID-5 volume.
create volume simple Creates a simple volume.
create volume stripe Creates a striped volume.
delete disk Deletes a dynamic disk.
delete partition Deletes the partition with focus.
delete volume Deletes the volume with focus.
detail disk Displays detailed information on the disk with focus.
detail partition Displays detailed information on the partition with focus.
detail volume Displays detailed information on the volume with focus.
extend Extends the volume with focus.
import Imports a foreign disk group.
inactive Marks a disk that has the MBR as inactive.
list disk Display a list of disks.
list partition Display a list of partitions.
list volume Display a list of volumes.
online Brings an offline disk online.
remove Removes a drive letter or mount point from the volume with focus
repair Repairs a RAID-5 volume
rescan Locates new disks that have been added to the computer.
select disk Selects a disk as the focus.
select partition Selects a partition as the focus.
select volume Selects a volume as the focus.
Scripting Commands
Diskpart commands can be written into script files. The syntax for the command is as follows: diskpart /s scriptfile.txt The output from the command can be redirected to a log file as follows: diskpart /s scriptfile.txt > log.txt Figure 4 shows a test script, with the output in figure 5.
list volume
select disk 0
create partition extended
create partition logical
list partition
delete partition
exit
Figure 4: test Script
E:\>diskpart /s testdiskpart.txt

Microsoft DiskPart version 5.2.3790
Copyright (C) 1999-2001 Microsoft Corporation.
On computer: BART

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   NRMEFPP_EN   CDFS   DVD-ROM      543 MB  Healthy
  Volume 1     E                NTFS   Partition   6001 MB  Healthy    System
  Volume 2     B   Business     NTFS   Partition     29 GB  Healthy
  Volume 3     C   ZIP-100      FAT32  Removeable    96 MB  Healthy

Disk 0 is now the selected disk.

DiskPart succeeded in creating the specified partition.

DiskPart succeeded in creating the specified partition.

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary           6001 MB    32 KB
  Partition 2    Primary             29 GB  6001 MB
  Partition 3    Extended            77 GB    35 GB
* Partition 4    Logical             77 GB    35 GB

DiskPart successfully deleted the selected partition.

Leaving DiskPart...

E:\>
Figure 5: test script output Two useful things to bear in mind with scripts; firstly, you can test the success of each diskpart command based on the return code. The list of possible codes is shown below:
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.
The second point to remember is that you should try and keep as many of your diskpart commands within the same script to ensure your commands run sequentially. If required, the timeout command can be used to create a delay between commands, for example timeout /t 20 will introduce a 20 second delay. Although diskpart is an obviously useful command, I'm not sure what I'd use the scripting functions for. Perhaps the ability to create and break a mirror of a disk would be useful, but for other functions such as creating and deleting volumes, I'd have to be very sure the script was correct before I'd use it in any kind of production environment. The ability to list disk information is definitely useful, however the same information can be obtained through WMI. It remains to be seen how many users will make use of this new command.

Share:

More from Techworld

More relevant IT news

Comments




Send to a friend

Email this article to a friend or colleague:

PLEASE NOTE: Your name is used only to let the recipient know who sent the story, and in case of transmission error. Both your name and the recipient's name and address will not be used for any other purpose.

Techworld White Papers

Choose – and Choose Wisely – the Right MSP for Your SMB

End users need a technology partner that provides transparency, enables productivity, delivers...

Download Whitepaper

10 Effective Habits of Indispensable IT Departments

It’s no secret that responsibilities are growing while budgets continue to shrink. Download this...

Download Whitepaper

Gartner Magic Quadrant for Enterprise Information Archiving

Enterprise information archiving is contributing to organisational needs for e-discovery and...

Download Whitepaper

Advancing the state of virtualised backups

Dell Software’s vRanger is a veteran of the virtualisation specific backup market. It was the...

Download Whitepaper

Techworld UK - Technology - Business

Innovation, productivity, agility and profit

Watch this on demand webinar which explores IT innovation, managed print services and business agility.

Techworld Mobile Site

Access Techworld's content on the move

Get the latest news, product reviews and downloads on your mobile device with Techworld's mobile site.

Find out more...

From Wow to How : Making mobile and cloud work for you

On demand Biztech Briefing - Learn how to effectively deliver mobile work styles and cloud services together.

Watch now...

Site Map

* *