Partitioning drives from a Windows command prompt


I found myself needing to partition a LUN on one of the Windows servers I support, and was curious how to perform this operation from a shell prompt. After a bit of googling, I came across the diskpart utility. This nifty little utility allows you to view devices, create and destroy volumes, and modify partition tables. The syntax for the commands available to diskpart can be viewed by running the “help” subcommand:

C:\Bin> diskpart

DISKPART> help

Microsoft DiskPart version 5.1.3565

ADD - Add a mirror to a simple volume.
ACTIVE - Marks the current basic partition as an active boot partition.
ASSIGN - Assign a drive letter or mount point to the selected volume.
BREAK - Break a mirror set.
CLEAN - Clear the configuration information, or all information, off the
disk.
CONVERT - Converts between different disk formats.
CREATE - Create a volume or partition.
DELETE - Delete an object.
DETAIL - Provide details about an object.
EXIT - Exit DiskPart
EXTEND - Extend a volume.
HELP - Prints a list of commands.
IMPORT - Imports a disk group.
LIST - Prints out a list of objects.
INACTIVE - Marks the current basic partition as an inactive partition.
ONLINE - Online a disk that is currently marked as offline.
REM - Does nothing. Used to comment scripts.
REMOVE - Remove a drive letter or mount point assignment.
REPAIR - Repair a RAID-5 volume.
RESCAN - Rescan the computer looking for disks and volumes.
RETAIN - Place a retainer partition under a simple volume.
SELECT - Move the focus to an object.

To view the physical devices connected to a system, you can use the diskpart “list disk” subcommand:

C:\Bin> diskpart

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ---------- ------- ------- --- ---
Disk 0 Online 28 GB 0 B

To view a device’s partition table, you can select a disk and run the “list partition” subcommand:

C:\Bin> diskpart


DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list partition

Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 28 GB 32 KB

You can also list the volumes available to the system with the “list volume” subcommand:

C:\Bin> diskpart

DISKPART> list volume

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D CD-ROM 0 B
Volume 1 C NTFS Partition 28 GB Healthy System

Windows has some awesome utilities buried in the Windows folder, and the new shell should make automating tasks on Windows platforms a TON easier. Shibby!

This article was posted by Matty on 2006-05-23 20:20:00 -0400 -0400