Monday, December 19, 2011

A Windows administrator's guide to Diskpart commands


Introduction
Systems administrators frequently build, manipulate and extend disk partitions in Windows in order to keep from running out of space on their servers. One tool they use is Microsoft's Diskpart utility, which allows Windows administrators to configure storage from a script, a remote session or other command prompt.
This guide reviews the many Diskpart commands and explains how administrators can use Diskpart to manipulate, extend and delete disk partitions.
The Diskpart.exe command-line utility can extend the data volumes and existing partitions in Windows 2000, Windows XP and Windows Server 2003 by using the unallocated space displayed in the Disk Management snap-in.

Diskpart: A command-line for manipulating disk partitions in Windows
Diskpart is a command-line utility for manipulating disk partitions in Windows 2000, Windows XP Home and Professional and Windows Server 2003. It is included by default in Server 2003 and all versions of XP, and is available as part of the Windows 2000 Resource Kit. It is not available for Windows 95, 98 or Me.
Aside from the user typing in commands, Diskpart can be scripted to perform multiple commands via a text file script, making it possible for an admin to automate creating complex partition arrangements not possible through unattended setup files. (Script files are simply lists of commands separated by line breaks, and are used by issuing the command Diskpart /S <script_name>.)
Diskpart should not be used to modify dynamic disks except to down-convert a dynamic disk to a basic disk. Doing anything else can destroy the partition table of a dynamic disk. You can also use DISKPART to convert a basic disk to a dynamic disk, but if you do so, that should be the last command issued through Diskpart for a particular disk.
Some of the most common commands that Diskpart uses includes:
1.    ACTIVE: Activates the current basic partition.
2.    ADD/BREAK: Creates or breaks a mirror for a selected volume.
3.    ASSIGN/REMOVE: Assigns or removes a drive letter or mount point to a volume designated by the SELECT command. Use the syntax ASSIGN LETTER=<drive_letter>.
4.    CLEAN: Removes all configuration information from the SELECTed disk. This is useful for removing boot sector metadata.
5.    CONVERT: Converts a SELECTed disk. Valid choices include BASIC, DYNAMIC (to convert dynamic disks to basic and vice versa), GPT and MBR (to convert GUID partition table disks to master boot record partition table disks).
6.    CREATE/DELETE: Creates a new partition or volume, or deletes a Selected partition or volume. Deleting an entire disk requires that the drive first be unmounted with REMOVE.
7.    DETAIL DISK | PARTITION | VOLUME: -- Returns detailed information about the Selected disk, partition or volume.
8.    EXTEND -- Extends a volume to fill available (unpartitioned) space on a drive.
9.    LIST DISK | PARTITION | VOLUME: -- Lists the disks, partitions, or volumes available on the current system. LIST DISK or LIST PARTITION requires that a disk or partition be selected with the SELECT command.
10. ONLINE: Set online any Selected disk or volume that is currently marked as offline.
11. RESCAN: Search the computer for newly-installed disks and volumes.
12. SELECT DISK | PARTITION | VOLUME: Changes the context of the program to work with a specific disk, partition or volume. Disks are selected by number starting with 0, so SELECT DISK 1 would select the second enumerated hard drive in a system. Partitions are selected on the currently-selected disk by number as well, starting with 1. Volumes are selected independent of disk or partition and start at 0.

Diskpart utility scans for newly added disks
One particularly useful utility for Windows 2000/XP/Windows Server 2003 users is the Disk Partition Utility, aka Diskpart, a command-line interpreter designed as a disk management tool. Diskpart can create, delete and resize hard drive partitions as well as assign or reassign drive letters.
Instead of using Disk Administrator, use Diskpart to find your newly added disks quickly (especially if you intend to perform other Diskpart tasks later). Note: Any text in parentheses are comments only; they should not be typed along with any commands given.
1.    At a command prompt, type: Diskpart.exe.
2.    At the DISKPART prompt, type: RESCAN (scans for newly added disks.)
3.    At the DISKPART prompt, type: LIST DISK (lists disks found; make note of the drive number you wish to manipulate)
4.    At the DISKPART prompt, type: Select Disk 1 (This selects the disk; make sure you type in the disk number from step 3.)
5.    At the DISKPART prompt, type: LIST PARTITION (lists partitions found.)
6.    At the DISKPART prompt, type: LIST VOLUMES (lists volumes (or logical drives) found.)
7.    At the DISKPART prompt, type: Exit.
Diskpart: Create, extend or delete a partition
One highly useful utility for Windows 2000/XP/Windows Server 2003 users is the Disk Partition Utility, aka Diskpart, a command-line interpreter designed as a disk management tool.
In a recent article, I showed you how to use Diskpart to scan for newly added disks. But Diskpart can also be used to create, delete and resize hard drive partitions as well as assign or reassign drive letters.
 Note: Any text in parentheses are comments only; they should not be typed along with any commands given.
Create a partition in Windows with Diskpart. Using Diskpart to partition your disk is very beneficial for increasing the I/O performance of hard disks newly added to a RAID array. The documentation for many server applications, such as Microsoft Exchange Server, actually goes so far as to recommend that you should use Diskpart to create your Primary or Extended partitions. (A primary partition an be used as the system partition; an Extended Partition can only be used for additional logical drive assignments.)
To create a partition:
  1. At a command prompt, type: Diskpart.exe
  2. At the DISKPART prompt, type: LIST DISK (Lists disks found. Make note of the drive number you wish to manipulate.)
  3. At the DISKPART prompt, type: Select Disk 1 (This selects the disk; make sure to type in the disk number from step 2.)
  4. At the DISKPART prompt, type: CREATE PARTITION PRIMARY SIZE=10000
    (Change the word PRIMARY to EXTENDED to create an extended partition.) (If you do not set a size (in MB), such as the above example for 10 GB, then all available space on the disk will be used for the partition.) (Seriously consider adding the following option to the end of the above command if you are using RAID (especially RAID 5) to improve disk I/O performance: ALIGN=64)
  5. At the DISKPART prompt, type: ASSIGN LETTER=D (Choose a drive letter not already being used.)
  6. At the DISKPART prompt, type: Exit
  7. Use the Command Prompt format command, Disk Administrator or any disk format utility to format the drive (typically using NTFS, of course).
Extend a partition in Windows with Diskpart. When it comes to adding space to a partition or volume, this method is superior to configuring Dynamic Disks. Dynamic Disk extensions only concatenate the newly added space, menaing they merely add the disk space to the "end" of the original partition without restriping the data.
Concatenation isolates performance within each partition and does not offer fault tolerance when the partition is configured in a RAID array. Diskpart allows you to restripe your existing data. This is truly beneficial when the partition is set up in a RAID array, because the existing partition data is spread out across all the drives in the array, rather than just adding new space to the end (like Disk Administrator).
Microsoft's "official" position is that that you cannot use Diskpart to extend your system or boot partition. However, this tip on SearchWinComputing.com on increasing the capacity of your system volume, suggests otherwise.
Note: If you try it or any other method, make sure you have a full backup.
To extend a partition:
  1. Verify that contiguous free space is available on the same drive and that free space is next to the partition you intend on extending (with no partitions in between).
  2. At a command prompt, type: Diskpart.exe
  3. At the DISKPART prompt, type: Select Disk 1 (Selects the disk.)
  4. At the DISKPART prompt, type: Select Volume 1 (Selects the volume.)
  5. At the DISKPART prompt, type: Extend Size=10000 (If you do not set a size, such as the above example for 10 GB, then all available space on the disk will be used.)
  6. At the DISKPART prompt, type: Exit
Note: It is not necessary, but I normally reboot the server to make sure all is well from a startup standpoint.
To delete a partition in Windows with Diskpart: (Note: You cannot delete an active system or boot partition or a partition with an active page file.)
  1. At a command prompt, type: Diskpart.exe
  2. At the DISKPART prompt, type: Select Disk 1
  3. At the DISKPART prompt, type: Select Partition 1
  4. At the DISKPART prompt, type: DELETE partition
  5. At the DISKPART prompt, type: Exit
To wiping (or zero) a disk:
This operation deletes all data on the disk
  1. At a command prompt, type: Diskpart.exe
  2. At the DISKPART prompt, type: Select Disk 1
  3. At the DISKPART prompt, type: CLEAN ALL (The CLEAN ALL command removes all partition and volume information from the hard drive being focused on.)
  4. At the DISKPART prompt, type: Exit
Final note: Here are four important things to keep in mind regarding Diskpart.
  • Do not use DISKPART until you have fully backed up the hard disk you are manipulating
  • Do not use DISKPART on dynamic disks
  • Check with your disk vendor before using Diskpart
  • Install the Windows Resource Kit to get the Diskpart utility

No comments:

Post a Comment