Disk Administration, Partition a disk.


      DISKPART /s scriptname.txt

      DISKPART /s scriptname.txt > logfile.txt

   /s scriptname.txt (one command per line)
         To create a diskpart script, create a text file scriptname.txt containing the Diskpart commands that you 
         want to run, one command per line, and no empty lines. Start a line with REM to make the line a comment.

Commands you can issue at the DISKPART prompt or in a text file:

 ACTIVE  On basic disks, mark 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-2022)

         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] (Server 2012-2022) Remove any and all partition or volume formatting from the disk with focus, 'all' will Zero the disk. See also the PowerShell cmdlet clear-disk COMPACT vdisk (Windows Server 2008R2-2022) 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 (Windows Server 2008R2-2022). 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. 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 (Windows Server 2012-2022) OEM use only. On basic GUID partition table (gpt) disks, this command assigns the gpt attribute(s) to the partition with focus. Gpt partition attributes give additional information about the use of the partition. Some attributes are specific to the partition type GUID. This might cause your basic data volumes to fail to be assigned drive letters, or to prevent the file system from mounting. 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 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 Server 2008R2-2022) 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. As a result, other differencing VHDs that are dependent on the parent will no longer be valid. You must choose and detach a VHD for this operation to succeed. Use the 'select vdisk' command to select a VHD and shift the focus to it. 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)
Prior to Windows 8/Server 2008 the DiskPart utility used a different syntax.

DiskPart can be used to automate disk-related tasks, such as creating volumes or converting disks to dynamic disks. Scripting these tasks is useful if you deploy Windows by using unattended Setup or the Sysprep tool, which do not support creating volumes other than the boot volume.

When using the DiskPart command as a part of a script, we recommend that you complete all of the diskpart operations together as part of a single diskpart script. To run consecutive diskpart scripts, allow at least 15 seconds between each script for a complete shutdown of the previous execution before running the DiskPart command again in successive scripts. Otherwise, the successive scripts might fail.
Add a pause between consecutive DiskPart scripts by adding a TIMEOUT /t 15 command to the batch file.

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

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.



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

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. 
 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 successfully onlined the selected disk.

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

Related commands

docs.microsoft.com - Configure UEFI/GPT-Based Hard Drive Partitions using Windows PE and DiskPart.
docs.microsoft.com - Configure BIOS/MBR-Based Hard Disk Partitions using Windows PE and DiskPart.
FORMAT - Format a disk.
FSUTIL - File and Volume utilities.
DISKSHADOW - Volume Shadow Copy Service.
REAGENTC - Configure Windows Recovery Environment (Windows RE) and System Reset.
SYSPREP - (Generalize) a Windows installation.
PowerShell equivalents: clear-disk, get-disk, set-partition, get-volume
Partition Wizard - GUI Disk Partition Manager.
Equivalent bash command (Linux): fdisk - Partition table manipulator for Linux.

Copyright © 1999-2024 SS64.com
Some rights reserved