Managing Storage from the Command Line

One of the neat things about the way that Windows Server 2008 was designed is that many aspects of the operating system can be managed from the command line. If you happen to need to define a RAID array, it is usually easier to point and click your way through the process using the Disk Management Console, but that’s assuming that you need to perform the operation on a single machine, and that the machine has a GUI interface installed. If you need to provision multiple machine you may be better off scripting the operation. Likewise, if you are trying to manage a server core installation, then you may have no choice but to manage your disk subsystem from the command prompt. In this article, I will show you how.

The Diskpart command

Windows Server 2008 contains a command line utility called Diskpart.exe that allows you to manage your server’s disk subsystem from the command line. To use this command simply open a Command Prompt window, and enter the DISKPART.EXE command. Upon doing so, Windows will place you into the Diskpart shell. From there, you can use various commands to manage your disk subsystem.

The Diskpart Command Syntax

Diskpart commands follow a verb-noun syntax. The verb tells Windows what action you want to perform, and the noun tells Windows which object you want to perform the action against. One of the simplest examples of a Diskpart command is the List Disk command. In this case, List is the verb, and Disk is the noun. Upon entering this command, Windows will display a list of all of the physical disks that are installed in the server. You can see an example of this in Figure A.

managing storage from the command line 1 small

Figure A The List Disk command shows you which disks are installed in the server.

I will say that Diskpart seems to have a bug in it. You will notice in the figure above that Diskpart shows 0 bytes free on Disk 0. In actuality though, the disk has 42 GB of free space.

Unfortunately, my test machine isn’t great for demonstrating Diskpart because it only has one disk installed. Notice in the figure above though, that each disk is assigned a number. When you need to perform an operation on a particular disk, you can specify the disk by entering the Select command. For example, if I wanted to perform an operation against Disk 0, I would enter Select Disk 0.

In many cases, managing disks involves creating fault tolerant volumes, and you can easily do that using Diskpart. Imagine for example, that your system had four hard drives installed, and that those hard drives were numbered 0, 1, 2, and 3. Let’s also pretend that Disk 0 is our system drive, and that Disk 1, 2, and 3 are blank hard drives that we want to convert into a RAID 5 volume.

Before we can create a RAID 5 volume, we have to ensure that each disk is acting as a dynamic disk. If you look back at Figure A, you can see that the List Disk command will tell you whether or not a disk is dynamic. Assuming that none of the disks are dynamic, you can convert them from basic to dynamic by entering the following commands:

​Select Disk 1
Convert Dynamic
Select Disk 2
Convert Dynamic
Select Disk 3
Convert Dynamic

Now that we have converted our disks, we can create the RAID 5 volume by entering the following commands:

​Select Disk 1
Create Volume RAID Disk 1, 2, 3

If you enter the List Volume command, Diskpart should verify that a RAID volume has been created. Although my test server does not have enough disks to create a RAID volume, Figure B shows what the List Volume command looks like. Notice that every volume is assigned a volume number.

managing storage from the command line 2 small

Figure B Each volume is assigned a volume number.

The last thing that we have to do is to format the volume that we have created, and assign it a drive letter. For the sake of demonstration, imagine that our empty raid volume is assigned volume number 2, and that we want to mount the volume as drive G:. To do so, we would enter these commands:

​Select volume 2
Format FS=NTFS Label=MyNewVolume
Assign Letter=F

When you are done, you can use the List Volume command to verify the success of the operation. Finally, enter the Exit command to leave the Diskpart shell.


Unfortunately, there is no way that I can teach you about all of the Diskpart commands within the confines of an article. If you need additional help with using the Diskpart command, just enter Diskpart.exe at the command prompt. When Windows opens the Diskpart shell, enter a question mark. When you do, Windows will display a list of all of the commands that are available to you.

Got a question? Post it on our Windows Server 2008 forums!