The DiskPart utility
This
section looks at the DiskPart utility in more detail, explaining the
options available with DiskPart and how it might be used when
performing maintenance on or troubleshooting a computer. The DiskPart
utility and commands are designed to work directly with disks, volumes,
and partitions.
When you launch DiskPart from a command line, you are
prompted to allow or deny its use by User Account Control. Because
DiskPart can make potentially harmful changes to your system, you are
prompted to verify that it should be allowed to run. A new command
prompt window opens that is running DiskPart.exe. When DiskPart is
loaded, your cursor follows the DISKPART> prompt, which is shown in Figure 8.
From this prompt, your command-line session can execute any of the
DiskPart options and commands. Many commands, DIR for example, will
produce different results within DiskPart than might appear when
executing the command outside DiskPart. DIR returns a list of the
commands available within the DISKPART prompt. This is shown in Figure 9.
Using DiskPart to manage and review existing items on your Windows
8–based computer can be a great starting point for adding or removing
volumes and other potentially dangerous maneuvers.
Note
GETTING HELP FOR COMMANDS
When working with DiskPart, help is available for all the commands by typing help before a command. For example, typing Help Add displays help items related to the Add command.
-
Active
Marks the selected partition as active
-
Add Adds a mirror to a simple volume
-
Assign
Assigns a drive letter or mount point to the selected volume
-
Attach
Attaches a virtual disk file
-
Attributes
Manipulates the attributes of a disk or volume
-
Automount
Enables or disables automatic mount for basic volumes
-
Break
Breaks a mirror set
-
Clean
Removes the configuration data or all data from a disk or volume
-
Compact
Reduces the physical size of a file
-
Convert
Converts a basic disk or volume to a dynamic disk or volume
-
Create
Creates a partition, virtual disk, or volume
-
Delete
Removes a partition, virtual disk, or volume
-
Detail
Provides object details
-
Detach
Disconnects a virtual disk file
-
Exit
Quits DiskPart
-
Extend
Extends a volume
-
Expand
Expands a virtual disk file’s maximum size
-
Filesystems
Displays current and supported file systems on the selected volume
-
Format
Formats the selected disk, partition, or volume
-
GPT
Assigns attributes to the selected GPT partition
-
Help
Displays help for a DiskPart command or a list of all commands
-
Import
Imports a disk group
-
Inactive
Sets the selected object to inactive
-
List Displays a list of objects
-
Merge
Merges a child disk with its parent
-
Online
Sets an offline object online
-
Offline Sets an online object offline
-
Recover
Refreshes the state of all disks in a pack, attempts recovery on invalid disks, and resynchronizes mirrored and RAID-5 volumes
-
Rem
Enables comment lines in scripts; takes no action on the command line
-
Remove
Removes a drive letter or mount point
-
Repair
Repairs a RAID-5 volume with a failed disk
-
Rescan
Rescans the computer for new or changed disks or volumes
-
Retain
Places a retained partition under a single volume
-
SAN
Displays or sets the SAN policy for the currently started operating system
-
Select
Shifts the context or focus of DiskPart to a disk, partition, volume, or other object
-
SetID
Changes the partition type
-
Shrink
Decreases the size of the selected volume
-
UniqueID
Displays or sets the GUID Partition Table identifier or Master Boot Record signature of a disk
DiskPart performs a number of the same functions as the Disk
Management console, providing a command-line alternative to the GUI. In
addition to running operations directly at the command line, you can
script DiskPart actions to automate the process of managing disks,
volumes, and partitions.
Similar to the earlier example of extending the size of a volume
with computer management, you can use DiskPart to shrink volumes where
space might no longer be needed. For example, you added 250 MB to the
documents volume earlier in this lesson. Now, you no longer need the
additional space; perhaps a large number of files are no longer needed
in your testing. By using DiskPart, you can reclaim this space. To do so, complete the following steps:
-
Open the Start screen.
-
Search for DiskPart.
-
Press Enter or tap or click the result returned to launch the utility.
-
Allow DiskPart when prompted for UAC by tapping or clicking Yes.
-
List the volumes available within the computer by typing list volume on the command line and pressing Enter.
-
From the list of volumes, select the volume to shrink by typing select volume # on the command line, where # is the number of the volume returned in the previous step. Press Enter.
-
Shrink the volume by 250 MB by typing Shrink desired=250 on the command line and tapping or clicking Enter.
-
Type Exit on the command line and press Enter to close DiskPart.
Important
DISKPART MAKES CHANGES IMMEDIATELY
Shrinking volumes or partitions by using DiskPart happens almost immediately. Typing Shrink by itself on the command line will reduce the selected volume to the smallest available size.
Even though the DiskPart command-line tool can be scripted, it still
requires you to work with one object at a time. When one operation
completes, the script can move on to the next object. The following is
an example of a script using DiskPart:
Select volume 1
Clean
Create partition primary size=300
Exit
This script selects volume 1 and cleans it, which removes all
partitions and data from the disk. Then the script creates a 300-MB
primary partition on volume 1.
To execute a script in DiskPart, type the following command:
diskpart -s <scriptfile>