DiskPart

Disk Administration, Partition a disk. This page documents the Windows 8/10 + Server 2008-2016 versions of Diskpart.

Syntax
      DISKPART
Commands you can issue at the DISKPART prompt: ACTIVE On basic disks, marks the partition with focus as active. DiskPart does not check the contents of the partition. If you mistakenly mark a partition as active and it does not contain the operating system startup files, your computer might not start. This informs the basic input/output system (BIOS) or Extensible Firmware Interface (EFI) that the partition or volume is a valid system partition or system volume. Only partitions can be marked as active. A partition must be selected for this operation to succeed. Use the select partition command to select a partition and shift the focus to it. ADD disk=n [align=n] [wait] [noerr] Mirror the simple volume with focus to the specified disk. ASSIGN [{LETTER=D | mount=path}] [noerr] Assign a drive letter or mount point to the volume with focus. (Only Server 2012-2016) If no drive letter or mount point is specified, the next available drive letter is assigned. By using the assign command, you can change the drive letter associated with a removable drive. You cannot assign drive letters to system volumes, boot volumes, or volumes that contain the paging file. In addition, you cannot assign a drive letter to an Original Equipment Manufacturer (OEM) partition or any GUID Partition Table (gpt) partition other than a basic data partition. A volume must be selected for this operation to succeed. Use the select volume command to select a volume and shift the focus to it. ## Example To assign the letter E to the volume in focus, type: assign letter=e ATTRIBUTES DISK [{set | clear}] [readonly] [noerr]
ATTRIBUTES VOLUME [{set | clear}] [{hidden | readonly | nodefaultdriveletter | shadowcopy}] [noerr] Display, set, or clear the attributes of a disk or volume. AUTOMOUNT [enable] [disable] [scrub] [noerr] Enable or disable the automount feature. BREAK disk=n [nokeep] [noerr] Break the mirrored volume with focus into two simple volumes. CLEAN [all] (Only Server 2012-2016) Remove any and all partition or volume formatting from the disk with focus, 'all' will Zero the disk. COMPACT vdisk (Only Windows 7 + Windows Server 2008R2-2016) Reduce the physical size of a dynamically expanding virtual hard disk (VHD) file. This parameter is useful because dynamically expanding VHDs increase in size as you add files, but they do not automatically reduce in size when you delete files. CONVERT Convert file allocation table (FAT) and FAT32 volumes to the NTFS file system. CREATE partition efi [size=n] [offset=n] [noerr] CREATE partition extended [size=n] [offset=n] [align=n] [noerr] CREATE partition logical [size=n] [offset=n] [align=n] [noerr] CREATE partition msr [size=n] [offset=n] [noerr] CREATE partition primary [size=n] [offset=n] [id={ byte | guid }] [align=n] [noerr] Create a partition. CREATE volume raid [size=n] disk=n,n,n[,n,...] [align=n] [noerr] CREATE volume simple [size=n] [disk=n] [align=n] [noerr] CREATE volume stripe [size=n] disk=n,n[,n,...] [align=n] [noerr] CREATE volume mirror [size=n] disk=n,n[,n,...] [align=n] [noerr] Create a volume. CREATE vdisk file=filepath {[type={fixed|expandable}] | [parent=filepath] | [source=filepath]} [maximum=n] [sd=SDDL] [noerr] Create a virtual disk (VHD). DELETE disk [noerr] [override] DELETE partition [noerr] [override] DELETE volume [noerr] Delete a partition, volume or a dynamic disk from the list of disks. DETAIL Disk DETAIL Partition DETAIL volume Display properties of the selected disk/volume/partition, display the disks on which the current volume resides: EXIT Exit Diskpart EXPAND vdisk maximum=n Expand the max size (in MB) available on a virtual disk (Win7 + Windows Server 2008R2-2016). EXTEND [size=n] [disk=n] [noerr] EXTEND filesystem [noerr] Extend a volume or partition with focus and its file system into free space on a disk. (Server 2012-2016) size= The space in MB. disk= The disk on which the volume or partition is extended. Default = current disk. FILESYSTEMS Display the current and supported file systems on the volume (Use 'Select Volume' first) FORMAT [[FS=FS] [REVISION=X.XX] | RECOMMENDED] [LABEL="label"] [UNIT=N] [QUICK] [COMPRESS] [OVERRIDE] [DUPLICATE] [NOWAIT] [noerr] Format a disk for use with Windows. GPT attributes=n (Only Server 2012-2016) OEM use only. Assign attributes to the selected GUID partition table (GPT) partition: HELP [command] IMPORT Imports a transportable shadow copy from a loaded metadata file into the system. Before you can use import, you must load a DiskShadow metadata file using the load metadata command. INACTIVE On basic master boot record (MBR) disks, marks the system partition or boot partition with focus as inactive [don’t boot]. Use 'Select Partition' first. Your computer might not start without an active partition. LIST Disk LIST Partition LIST Volume LIST vdisk (Windows 7/10 / Server 2008 R2) LIST writers [metadata | detailed | status] LIST shadows {all | set SetID | id ShadowID} LIST providers Display a list of objects SetID List shadow copies that belong to the specified Shadow Copy Set ID. ShadowID List any shadow copy with the specified shadow copy ID MERGE vdisk depth=n (Windows 7/Server 2008R2-2016) Merge a differencing virtual hard disk (VHD) with its corresponding parent VHD. depth=1 will merge with parent. The parent VHD will be modified to include the modifications from the differencing VHD. OFFLINE disk [noerr] OFFLINE volume [noerr] Take an online disk or volume to the offline state, use 'Select Disk' first) ONLINE disk [noerr] ONLINE volume [noerr] Take an offline disk or volume to the online state. RECOVER [noerr] Refresh the state of all disks in the selected pack, attempt recovery on disks in the invalid pack, and resynchronize mirrored volumes and RAID-5 volumes that have stale plex or parity data. Only applicable to dynamic disks. REM (remark/comment) REMOVE letter=E [dismount] [noerr] Remove drive letter E from the in-focus partition. REMOVE mount=path [dismount] [noerr] Remove mount point from the in-focus partition. REMOVE all [dismount] [noerr] Remove ALL current drive letters and mount points. Remove a drive letter or mount point from a volume. REPAIR disk=n [align=N] [noerr] Repair a RAID-5 volume with a failed member by replacing with a specified dynamic disk. align = N Align all volume extents to the closest alignment boundary. Extent offsets will be a multiple of N. RESCAN Locate new disks and volumes that have been added to the computer. RETAIN Prepare an existing dynamic simple volume to be used as a boot or system volume. SAN [policy={OnlineAll | OfflineAll | OfflineShared}] [noerr] Display or set the SAN policy for the currently booted OS. Specifying onlineAll on a server that shares disks could lead to data corruption. Do not set this policy if disks are shared among servers unless the server is part of a cluster. SELECT Disk={ n | diskpath | system | next } SELECT Partition=n (Volume number) SELECT Volume={ n | d } [noerr] (Volume number or Drive Letter) SELECT vdisk file=fullpath [noerr] Shift the focus to an object. SET ID={ byte | GUID } [override] [noerr] Change the partition type for the partition with focus (for OEM use): SHRINK [desired=n] [minimum=n] [nowait] [noerr] (Reduce the size of the in-focus volume)
SHRINK querymax [noerr] Reduce the size of the selected volume. Desired = Desired space in MB. Minimum = space in MB to reduce the volume by. QueryMax = Returns the maximum number of bytes that the volume can be reduced by. UNIQUEID disk [id={dword | GUID}] [noerr] Display or set the GUID partition table identifier or MBR signature for the (basic or dynamic) disk with focus. id= For MBR disks specify a 4-byte DWORD in hex form for the signature. Commands to Manage Basic Disks: ASSIGN MOUNT=path (Choose a mount point path for the volume) CREATE PARTITION Primary Size=50000 (50 GB) CREATE PARTITION Extended Size=25000 CREATE PARTITION logical Size=25000 DELETE Partition EXTEND Size=10000 GPT attributes=n (assign GUID Partition Table attributes) SET id=byte|GUID [override] [noerr] (Change the partition type) Commands to Manage Dynamic Disks: ADD disk=n (Add a mirror to the in-focus SIMPLE volume on the specified disk see 'Diskpart Help' for more.) BREAK disk=n (Break the current in-focus mirror) CREATE VOLUME Simple Size=n Disk=n CREATE VOLUME Stripe Size=n Disk=n,n,... CREATE VOLUME Raid Size=n Disk=n,n,... DELETE DISK DELETE PARTITION DELETE VOLUME EXTEND Disk=n [Size=n] EXTEND Filesystem [noerr] IMPORT [noerr] (Import a foreign disk group, use 'Select disk' first) RECOVER [noerr] (Refresh disk pack state, attempt recovery on an invalid pack, & resynchronize stale plex/parity data.) REPAIR disk=n [align=n] [noerr] (Repair the RAID-5 volume with focus, replace with the specified dynamic disk) RETAIN (Prepare an existing dynamic simple volume to be used as a boot or system volume)

When setting up a new drive, create in this order: Create Partition, Format drive, Assign drive letter.

The diskpart commands can be placed in a text file (one command per line) and used as an input file to diskpart.exe:

DiskPart.exe < myscript.txt

When selecting a volume or partition, you can use either the number or drive letter or the mount point path.

The Windows GUI interface can also be used to assign a mount-point folder path to a drive. In Disk Manager, right-click the partition or volume, and click Change Drive Letter and Paths, then click Add and then type the path to an empty folder on an NTFS volume.

The Windows Recovery Console, includes a simplified DISKPART command. It only provides functionality for adding and deleting partitions, but not for setting an active partition.

Always back up the hard disk before running diskpart.

Examples:

SELECT DISK=0
CREATE PARTITION PRIMARY
SELECT PARTITION=1
FORMAT FS=NTFS LABEL="New Volume" QUICK
ASSIGN LETTER=E EXIT

The default SAN policy in Windows Server 2008 / R2 is now VDS_SP_OFFLINE_SHARED for all non boot SAN disks.
This means that the disks will be offline at server startup (even if the drive contains a paging file).

This Disk Management error message indicates that the drive is offline:

"the disk is offline because of policy set by an administrator".

Query the current SAN policy to see if it is Offline Shared

DISKPART.EXE
DISKPART> san
SAN Policy : Offline Shared

To manually bring the disks online:
Computer Management > Storage > Disk Management, right-click the disk and choose Online.

If these are not part of a cluster, than an alternative is to make a SAN policy change, select the offline disk, clear its readonly flag and bring it online:

 DISKPART> san policy=OnlineAll 
 DiskPart successfully changed the SAN policy for the current operating system. 
 
 DISKPART> LIST DISK 
 Disk ### Status        Size    Free    Dyn Gpt
 -------- ------------- ------- ------- --- ---
 Disk 0   Online         80 GB     0 B
 * Disk 1 Offline        20 GB  1024 KB 
 
 DISKPART> select disk 1 
 Disk 1 is now the selected disk. 
 
 DISKPART> ATTRIBUTES DISK CLEAR READONLY
 DISKPART> ONLINE DISK
 DiskPart successfully onlined the selected disk.

“Divide et impera” ~ Latin saying (Divide and conquer)

Related:

Q325590 - Use Diskpart.exe to extend a data volume
FSUTIL - File and Volume utilities
DISKSHADOW - Volume Shadow Copy Service
PowerShell equivalents: get-disk, set-partition, get-volume
Equivalent bash command (Linux): fdisk - Partition table manipulator for Linux


 
Copyright © SS64.com 1999-2019
Some rights reserved