Jump to content

leaderboard_interactive

DISKPART: Using the Command Line Utility


  • Please log in to reply
4 replies to this topic

#1
Night Hawk

Night Hawk

    WindowsForums Administration

  • Administrators
  • 8,140 posts
  • Gender:Male
The first question many might ask is just what is DiskPart or the DiskPart.exe command line utility included in Windows 2000, XP, Vista and now 7. First thing is to cover one general description found at the Microsoft TechNet site on DIskPart here in Part #1 of this reference on the command utility since you would need to get familiar with these in order to use it.

.nu{ display:inline;}DiskPart DiskPart.exe is a text-mode command interpreter that enables you to manage objects (disks, partitions, or volumes) by using scripts or direct input from a command prompt. Before you can use DiskPart.exe commands on a disk, partition, or volume, you must first list and then select the object to give it focus. When an object has focus, any DiskPart.exe commands that you type act on that object.

You can list the available objects and determine an object's number or drive letter by using the list disk, list volume, and list partition commands. The list disk and list volume commands display all disks and volumes on the computer. However, the list partition command only displays partitions on the disk that has focus. When you use the list commands, an asterisk (*) appears next to the object with focus. You select an object by its number or drive letter, such as disk 0, partition 1, volume 3, or volume C.

When you select an object, the focus remains on that object until you select a different object. For example, if the focus is set on disk 0, and you select volume 8 on disk 2, the focus shifts from disk 0 to disk 2, volume 8. Some commands automatically change the focus. For example, when you create a new partition, the focus automatically switches to the new partition.

You can only give focus to a partition on the selected disk. When a partition has focus, the related volume (if any) also has focus. When a volume has focus, the related disk and partition also have focus if the volume maps to a single specific partition. If this is not the case, then focus on the disk and partition is lost.


DiskPart commands
To view the command syntax, click a command:

active

On basic disks, marks the partition with focus as active. 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.


Important

  • DiskPart verifies only that the partition is capable of containing an operating system's startup files. 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's startup files, your computer might not start.
Top of page

Syntax
active

add disk

Mirrors the simple volume with focus to the specified disk.

Top of page

Syntax
add disk= n [noerr]

Top of page

Parameters
n : Specifies the disk to contain the mirror You can mirror only simple volumes. The specified disk must have unallocated space at least as large as the size of the simple volume you want to mirror.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

assign

Assigns a drive letter or mount point to the volume with focus. If no drive letter or mount point is specified, then the next available drive letter is assigned. If the drive letter or mount point is already in use, an error is generated.

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 MSDATA partition.

Top of page

Syntax
assign [{letter=d|mount=Path}] [noerr]

Top of page

Parameters
letter= d : The drive letter you want to assign to the volume.

mount= Path : The mount point path you want to assign to the volume.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

break disk

Applies to dynamic disks only. Breaks the mirrored volume with focus into two simple volumes. One simple volume retains the drive letter and any mount points of the mirrored volume, while the other simple volume receives the focus so you can assign it a drive letter.

By default, the contents of both halves of the mirror are retained. Each half becomes a simple volume. By using the nokeep parameter, you retain only one half of the mirror as a simple volume, while the other half is deleted and converted to free space. Neither volume receives the focus.

Top of page

Syntax
break disk= n [nokeep] [noerr]

Top of page

Parameters
n : Specifies the disk that contains the mirrored volume.

nokeep : Specifies that only one of the mirrored volumes is retained; the other simple volume is deleted and converted to free space. Neither the volume nor the free space receive the focus.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

clean

Removes any and all partition or volume formatting from the disk with focus. On master boot record (MBR) disks, only the MBR partitioning information and hidden sector information are overwritten. On GUID Partition Table (GPT) disks, the GPT partitioning information, including the Protective MBR, is overwritten. There is no hidden sector information.

Top of page

Syntax
clean [all]

Top of page

Parameter
all : Specifies that each and every sector on the disk is zeroed, which completely deletes all data contained on the disk.

convert basic

Converts an empty dynamic disk into a basic disk

Top of page

Syntax
convert basic [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert dynamic

Converts a basic disk into a dynamic disk

Top of page

Syntax
convert dynamic [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert gpt

On Itanium-based computers, converts an empty basic disk with the master boot record (MBR) partition style into a basic disk with the GUID partition table (GPT) partition style.


Important
  • The disk must be empty to convert it to a GPT disk. Back up your data and then delete all partitions or volumes before converting the disk.
Top of page

Syntax
convert gpt [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

convert mbr

On Itanium-based computers, converts an empty basic disk with the GUID Partition Table (GPT) partition style to a basic disk with the master boot record (MBR) partition style.


Important
  • The disk must be empty to convert it to an MBR disk. Back up your data and then delete all partitions or volumes before converting the disk.
Top of page

Syntax
convert mbr [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition efi

On Itanium-based computers, creates an Extensible Firmware Interface (EFI) system partition on a GUID Partition Table (GPT) disk. After the partition has been created, the focus is given to the new partition.

Top of page

Syntax
create partition efi [size=n] [offset=n] [noerr]

Top of page

Parameters
size= n : The size of the partition in megabytes (MB). If no size is given, then the partition continues until there is no more free space in the current region.

offset = n : The byte offset at which to create the partition. If no offset is given, the partition is placed in the first disk extent that is large enough to hold it.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition extended

Creates an extended partition on the current drive. After the partition has been created, the focus automatically shifts to the new partition. Only one extended partition can be created per disk. This command fails if you attempt to create an extended partition within another extended partition. You must create an extended partition before you can create logical drives.

Top of page

Syntax
create partition extended [size=n] [offset=n] [noerr]

Top of page

Parameters
size= n : The size of the extended partition in megabytes (MB). If no size is given, then the partition continues until there is no more free space in the region. The size is cylinder snapped. The size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition would be rounded up to 504 MB.

offset= n : Applies to master boot record (MBR) disks only. The byte offset at which to create the extended partition If no offset is given, the partition will start at the beginning of the first free space on the disk. The offset is cylinder snapped. The offset is rounded to the closest cylinder boundary. For example, if you specify an offset that is 27 MB and the cylinder size is 8 MB, the offset is rounded to the 24 MB boundary.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition logical

Creates a logical drive in the extended partition. After the partition has been created, the focus automatically shifts to the new logical drive.

Top of page

Syntax
create partition logical [size=n] [offset=n] [noerr]

Top of page

Parameters
size= n : The size of the logical drive in megabytes (MB). If no size is given, then the partition continues until there is no more free space in the current region.

offset= n : Applies to master boot record (MBR) disks only. The byte offset at which to create the logical drive. The offset is cylinder snapped (that is, the offset is rounded up to completely fill whatever cylinder size is being used). If no offset is given, then the partition is placed in the first disk extent that is large enough to hold it. The partition is at least as long in bytes as the number specified by size=n. If you specify a size for the logical drive, it must be smaller than the extended partition.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition msr

On Itanium-based computers, creates a Microsoft Reserved (MSR) partition on a GUID Partition Table (GPT) disk.


Caution
  • Be very careful when using the create partition msr command. Because GPT disks require a specific partition layout, creating Microsoft reserved partitions could cause the disk to become unreadable. On GPT disks that are used to start Windows XP 64-Bit Edition, the EFI System partition is the first partition on the disk, followed by the Microsoft Reserved partition. GPT disks used only for data storage do not have an EFI System partition; the Microsoft Reserved partition is the first partition.

    Windows XP 64-Bit Edition does not mount Microsoft reserved partitions. You cannot store data on them and you cannot delete them.
Top of page

Syntax
create partition msr [size=n] [offset=n] [noerr]

Top of page

Parameters
size= n : The size of the partition in megabytes (MB). The partition is at least as long in bytes as the number specified by size=n. If no size is given, the partition continues until there is no more free space in the current region.

offset= n : The byte offset at which to create the partition. The partition starts at the byte offset specified by offset=n. It is sector snapped; that is, the offset is rounded up to completely fill whatever sector size is being used. If no offset is given, then the partition is placed in the first disk extent that is large enough to hold it.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create partition primary

Creates a primary partition on the current basic disk After you create the partition, the focus automatically shifts to the new partition. The partition does not receive a drive letter. You must use the assign command to assign a drive letter to the partition.

Top of page

Syntax
create partition primary [size=n] [offset=n] [ID={byte|GUID}] [noerr]

Top of page

Parameters
size= n The size of the partition in megabytes (MB). If no size is given, the partition continues until there is no more unallocated space in the current region. The size is cylinder snapped. The size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition would be rounded up to 504 MB. offset=n The byte offset at which to create the partition. If no offset is given, the partition will start at the beginning of the first free space on the disk. For master boot record (MBR) disks, the offset is cylinder snapped. The offset is rounded to the closest cylinder boundary. For example, if you specify an offset that is 27 MB and the cylinder size is 8 MB, the offset is rounded to the 24 MB boundary. ID={byte|GUID} Intended for Original Equipment Manufacturer (OEM) use only.


Caution
  • Creating partitions with this parameter might cause your computer to crash or be unable to start up. Unless you are an OEM or an IT professional experienced with GPT disks, do not create partitions on GPT disks using the ID=byte | GUID parameter. Instead, always use the create partition efi command to create EFI System partitions, the create partition msr command to create Microsoft Reserved partitions, and the create partition primary command (without the ID=byte | GUID parameter) to create primary partitions on GPT disks.
For MBR disks, you can specify a partition type byte, in hexadecimal form, for the partition. If no partition type byte is specified on an MBR disk, the create partition primary command creates a partition of type 0x6. Any partition type byte can be specified with the ID=byte | GUID parameter. DiskPart does not check the partition type byte for validity, nor does it perform any other checking of the ID parameter.

For GPT disks you can specify a partition type GUID for the partition you want to create:

  • EFI System partition: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
  • Microsoft reserved partition: e3c9e316-0b5c-4db8-817d-f92df00215ae
  • MSDATA partition: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
  • LDM Metadata partition on a dynamic disk: 5808c8aa-7e8f-42e0-85d2-e1e90434cfb3
  • LDM Data partition on a dynamic disk: af9b60a0-1431-4f62-bc68-3311714a69ad
If no partition type GUID is specified, the create partition primary command creates an MSDATA partition. Any partition type can be specified with the ID={byte | GUID} parameter. DiskPart does not check the partition GUID for validity, nor does it perform any other checking of the ID parameter.

noerr For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create volume raid

Creates a RAID-5 volume on the specified dynamic disks After you create the volume, the focus automatically shifts to the new volume.

Top of page

Syntax
create volume raid [size=n] [disk=n[,[n,]] [noerr]

Top of page

Parameters
size= n : The amount of disk space, in megabytes (MB), that the volume will occupy on each disk. If no size is given, the largest possible RAID-5 volume will be created. The disk with the smallest available contiguous free space determines the size for the RAID-5 volume and the same amount of space is allocated from each disk. The actual amount of usable disk space in the RAID-5 volume is less than the combined amount of disk space because some of the disk space is required for parity.

disk= n : The dynamic disks on which to create the volume. An amount of space equal to size=n is allocated on each disk.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create volume simple

Creates a simple volume After you create the volume, the focus automatically shifts to the new volume.

Top of page

Syntax
create volume simple [size=n] [disk=n] [noerr]

Top of page

Parameters
size= n/i> : The size of the volume in megabytes (MB). If no size is given, the new volume takes up the remaining free space on the disk.

disk= n : The dynamic disk on which to create the volume. If no disk is given, the current disk is used.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

create volume stripe

Creates a striped volume on the specified disks. After you create the volume, the focus automatically shifts to the new volume.

Top of page

Syntax
create volume stripe [size=n] [disk=n[,[n,]] [noerr]

Top of page

Parameters
size= n : The amount of disk space, in megabytes (MB), that the volume will occupy on each disk. If no size is given, the new volume takes up the remaining free space on the smallest disk and an equal amount of space on each subsequent disk.

disk= n : The dynamic disks on which to create the volume. An amount of space equal to size=n is allocated on each disk.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

delete disk

Deletes a missing dynamic disk from the disk list.

Top of page

Syntax
delete disk [noerr] [override]

Top of page

Parameters
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

override : Enables DiskPart to delete all simple volumes on the disk. If the disk contains half of a mirrored volume, the half of the mirror on the disk is deleted. The delete disk override command fails if the disk is a member of a RAID-5 volume.

delete partition

On a basic disk, deletes the partition with focus. You cannot delete the system partition, boot partition, or any partition that contains the active paging file or crash dump (memory dump).


Caution
  • Deleting a partition on a dynamic disk can delete all offline dynamic volumes on the disk, thus destroying any data and converting the disk to a basic disk. To delete a dynamic volume, always use the delete volume command instead.
Partitions can be deleted from dynamic disks, but they should not be created. For example, it is possible to delete an unrecognized GUID Partition Table (GPT) partition on a dynamic GPT disk. Deleting such a partition does not cause the resulting free space to become available. This command is particularly intended to allow reclamation of the space on a corrupted offline dynamic disk in an emergency situation where the clean command cannot be used.

Top of page

Syntax
delete partition [noerr] [override]

Top of page

Parameters
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

override : Enables DiskPart to delete any partition regardless of type. Typically, DiskPart only allows you to delete known data partitions.

delete volume

Deletes the selected volume. You cannot delete the system volume, boot volume, or any volume that contains the active paging file or crash dump (memory dump).

Top of page

Syntax
delete volume [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

detail disk

Displays the properties of the selected disk and the volumes on that disk.

Top of page

Syntax
detail disk

detail volume

Displays the disks on which the current volume resides.

Top of page

Syntax
detail volume

exit

Exits the DiskPart command interpreter.

Top of page

Syntax
exit

extend

Extends the volume with focus into next contiguous unallocated space. For basic volumes, the unallocated space must be on the same disk as, and must follow (be of higher sector offset than) the partition with focus. A dynamic simple or spanned volume can be extended to any empty space on any dynamic disk Using this command, you can extend an existing volume into newly created space.

If the partition was previously formatted with the NTFS file system, the file system is automatically extended to occupy the larger partition. No data loss occurs. If the partition was previously formatted with any file system format other than NTFS, the command fails with no change to the partition.

You cannot extend the current system or boot partitions.

Top of page

Syntax
extend [size=n] [disk=n] [noerr]

Top of page

Parameters
size= n : The amount of space, in megabytes (MB), to add to the current partition. If you do not specify a size, the disk is extended to take up all of the next contiguous unallocated space.

disk= n : The dynamic disk on which to extend the volume. An amount of space equal to size=n is allocated on the disk. If no disk is specified, the volume is extended on the current disk.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

help

Displays a list of the available commands.

Top of page

Syntax
help

import

Imports a foreign disk group into the local computer's disk group. The import command imports every disk that is in the same group as the disk that has focus.

Top of page

Syntax
import [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

list disk

Displays a list of disks and information about them, such as their size, amount of available free space, whether the disk is a basic or dynamic disk, and whether the disk uses the master boot record (MBR) or GUID partition table (GPT) partition style. The disk marked with an asterisk (*) has focus.

Top of page

Syntax
list disk

list partition

Displays the partitions listed in the partition table of the current disk. On dynamic disks, these partitions may not correspond to the dynamic volumes on the disk. This discrepancy occurs because dynamic disks contain entries in the partition table for the system volume or boot volume (if present on the disk) and a partition that occupies the remainder of the disk in order to reserve the space for use by dynamic volumes.

Top of page

Syntax
list partition

list volume

Displays a list of basic and dynamic volumes on all disks.

Top of page

Syntax
list volume

online

Brings an offline disk or volume with focus online.

Top of page

Syntax
online [noerr]

Top of page

Parameter
noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

rem

Provides a way to add comments to a script.

Top of page

Syntax
rem

Top of page

Examples
rem These commands set up 3 drives.

create partition primary size=2048

assign d:

create partition extend

create partition logical size=2048

assign e:

create partition logical

assign f:

remove

Removes a drive letter or mount point from the volume with focus. If the all parameter is used, all current drive letters and mount points are removed. If no drive letter or mount point is specified, then DiskPart removes the first drive letter or mount point it encounters.

The remove command can be used to change the drive letter associated with a removable drive. You cannot remove the drive letters on system, boot, or paging volumes. In addition, you cannot remove the drive letter for an OEM partition, any GPT partition with an unrecognized GUID, or any of the special, non-data, GPT partitions such as the EFI system partition.

Top of page

Syntax
remove [{letter=d|mount=Path [all]}] [noerr]

Top of page

Parameters
letter= d : The drive letter to be removed.

mount= Path : The mount point path to be removed.

all : Removes all current drive letters and mount points.

noerr : For scripting only. When an error is encountered, specifies that DiskPart continue to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

rescan

Locates new disks that may have been added to the computer.

Top of page

Syntax
rescan

retain

Prepares an existing dynamic simple volume to be used as a boot or system volume.

On an x86-based computer, creates a partition entry in the master boot record (MBR) on the dynamic simple volume with focus. To create an MBR partition, the dynamic simple volume must start at a cylinder aligned offset and be an integral number of cylinders in size.

On an Itanium-based computer, creates a partition entry in the GUID partition table (GPT) on the dynamic simple volume with focus.



Note

  • The retain command is intended for use only during Unattended Setup or by Original Equipment Manufacturers (OEMs).
Top of page

Syntax
retain

select disk

Selects the specified disk and shifts the focus to it.

Top of page

Syntax
select disk=[n]

Top of page

Parameters
n : The disk number of the disk to receive focus. If no disk number is specified, the select command lists the disk that currently has the focus. You can view the numbers for all disks on the computer by using the list disk command.

select partition

Selects the specified partition and gives it focus. If no partition is specified, the select command lists the current partition with focus. You can view the numbers of all partitions on the current disk by using the list partition command.

Top of page

Syntax
select partition=[{n|d}]

Top of page

Parameters
n : The number of the partition to receive the focus.

d : The drive letter or mount point path of the partition to receive the focus.

select volume

Selects the specified volume and shifts the focus to it. If no volume is specified, the select command lists the current volume with focus. You can specify the volume by number, drive letter, or mount point path. On a basic disk, selecting a volume also gives the corresponding partition focus. You can view the numbers of all volumes on the computer by using the list volume command.

Top of page

Syntax
select volume=[{n|d}]

Top of page

Parameters
n : The number of the volume to receive the focus.

d : The drive letter or mount point path of the volume to receive the focus.

Top of page

DiskPart scripting
Using DiskPart, you can create scripts to automate disk-related tasks, such as creating volumes or converting disks to dynamic. Scripting these tasks is useful if you are deploying Windows by using Unattended Setup or Sysprep, which do not support creating volumes other than the boot volume

To start a DiskPart script, at the command prompt, type:

DiskPart /S scriptname.txt

Where scriptname.txt is the name of the text file that contains your script.

To redirect DiskPart's scripting output to a file, type:

DiskPart /S scriptname.txt > logfile.txt

Where logfile.txt is the name of the text file where DiskPart writes its output.

When DiskPart starts, the DiskPart version and computer name are displayed at the command prompt. By default, if DiskPart encounters an error while attempting to perform a scripted task, DiskPart stops processing the script and displays an error code (unless you specified the noerr parameter). However, DiskPart always returns errors when it encounters syntax errors, regardless of whether you used the noerr parameter. The noerr parameter enables you to perform useful tasks such as using a single script to delete all partitions on all disks regardless of the total number of disks.

The following table lists the DiskPart error codes:

Error

Description

0

No errors occurred. The entire script ran without failure.

1

A fatal exception occurred. There may be a serious problem.

2

The parameters specified for a DiskPart command were incorrect.

3

DiskPart was unable to open the specified script or output file.

4

One of the services DiskPart uses returned a failure.

5

A command syntax error occurred. The script failed because an object was improperly selected or was invalid for use with that command.


Source: http://technet.micro...y/bb490893.aspx

Examples of use will start in Part #2

t71qir.jpg

 NOTICE: To All New Arrivals - WF Welcome Center - Community Rules

(avatar courtesy of TheBull - WF affiliate CreativX)


#2
Night Hawk

Night Hawk

    WindowsForums Administration

  • Administrators
  • 8,140 posts
  • Gender:Male
PART #2 of Using DiskPart:

In this second section here we will start off with one example showing how to clean everything off of one single hard drive without the use of any disk partitioning program but the simple command line utility DiskPart itself.

1) The first step is to get to know the intended drive to avoid accidentially removing everything off of the wrong drive when more then one is present. The first step before open a command prompt is verification of the intended drive that will be cleaned off entirely. On the example system here a total of four hard drives are present when looking in the "Control Panel>Adiministrative Tools>Computer Management>Storage>Disk Management" or simply put the Disk Management tool included in Windows.

Posted Image

2) Once the drive is known by which number that will be important when confirming it is the same one when opening up a command prompt in order to use the DiskPart utility there. The first thing done once the command prompt is open is to type "diskpart" and press enter. That will simply move onto the next line where you follow it with the next command "list disk" followed by once again pressing the enter key.

Posted Image

3)Now the drive is seen along with the other three. How do you select that drive from the list seen there? The command "select disk 1" is used in this circumstance to engage the Drive #1 shown earlier in the Disk Management tool there.

Posted Image

4)When using DiskPart there actually two different commands available while only one is for isolating one drive by itself, The other is the Mass Destruction command that will literally wipe all hard drives installed in one effort! and is not for this example here however. The two commands are "clean" and "clean all" where you can tell which one that would be! Here however the "clean" command is used for the intended drive.

Posted Image

From use of the "clean" command we now can see the results.

Posted Image

Another thing we also discover is that the drive is no longer found in Computer on Windows 7 or in Windows Explorer. What happened? The drive is now "offline" having no volume on it for Windows to mount as a logical drive.

Posted Image

Now that the drive has been totally cleaned of everything it is now aviailable for use but will need one or more new partition(s) which will be formatted for use according to the OS(in this example WIndows) being used. For immediate access to a newly partitioned drive(reparitioned and formatted) we opt to go back to the Disk Management tool one last time.

A new problem presents itself however when first arriving in the DM. Since the drive was offline and also now lacks any mbr... oops! a new prompt appears providing two options with the first being for the usual mbr seen as default.

The second is for the "GFT" or GUID Partition Table intended for drives 2tb and larger. We don't want that one!

Posted Image

Fortunately as you can see the default is for the standard mbr option. For the remainder of this example we now go back in the Disk Management tool to see a new volume created on the drive now seen as "raw".

Posted Image

Once the empty drive is right clicked on we now see something new appear namely the "new volume" wizard comes up once the drive is initialized and back online.

Posted Image

Posted Image

Posted Image

Posted Image

Posted Image

An interesting volume label for sure as we look at the new partition formatted and ready for use.

Posted Image

Part #3 will continue on with how to use DiskPart for creating partitions.

t71qir.jpg

 NOTICE: To All New Arrivals - WF Welcome Center - Community Rules

(avatar courtesy of TheBull - WF affiliate CreativX)


#3
Night Hawk

Night Hawk

    WindowsForums Administration

  • Administrators
  • 8,140 posts
  • Gender:Male
PART #3 of Using DiskPart : Creating New Volumes

In the third part of Using DiskPart we cover how to go about creating a new partition using the command line utility. The first thing to point to for the external reference source is the MS TechNet seen on how to go about this operation seen at http://technet.micro...978(WS.10).aspx

Create a partition or logical driveUpdated: January 21, 2005

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2




To create a partition or logical drive

Using the Windows interface
  • Open Computer Management (Local).
  • In the console tree, click Computer Management (Local), click Storage, and then click Disk Management.
  • Right-click an unallocated region of a basic disk, and then click New Partition, or right-click free space in an extended partition, and then click New Logical Drive.
  • In the New Partition wizard, click Next, click Primary partition, Extended partition, or Logical drive, and then follow the instructions on your screen.
Notes

  • To perform this procedure on a local computer, you must be a member of the Backup Operators group or Administrators group on the local computer, or you must have been delegated the appropriate authority. To perform this procedure remotely, you must be a member of the Backup Operators group or Administrators group on the remote computer. If the computer is joined to a domain, members of the Domain Admins group might be able to perform this procedure. As a security best practice, consider using Run as to perform this procedure. For more information, see Default local groups, Default groups, and Using Run as.
  • To open Computer Management, click Start, click Control Panel, double-click Administrative Tools, and then double-click Computer Management.
  • You can create primary partitions, extended partitions, and logical drives only on basic disks. You should create basic volumes instead of dynamic volumes if this computer also runs MS-DOS, Windows 95, Windows 98, Windows Millennium Edition, Windows NT 4.0, or Windows XP Home Edition.
  • On a master boot record (MBR) disk, you can create up to four primary partitions, or three primary partitions, one extended partition, and unlimited logical drives.
  • On a GUID partition table (GPT) disk, you can create up to 128 primary partitions.
Using a command line
  • Open Command Prompt.
  • Type:

    diskpart
  • At the DISKPART prompt, type:

    list disk

    Make note of the disk number of the disk on which you want to create a primary or extended partition.
  • At the DISKPART prompt, type:

    select diskn

    Select the disk n where you want to create the primary or extended partition.
  • At the DISKPART prompt, type one of the following:

    create partition primary [size=n] [offset=n] [ID=byte | GUID] [noerr]

    or

    create partition extended [size=n] [offset=n] [noerr]

    or

    create partition logical [size=n] [offset=n] [noerr]
  • At the DISKPART prompt, type:

    assign letter=D

Value Description list disk

Displays a list of disks and information about them, such as their size, amount of available free space, whether the disk is a basic or dynamic disk, and whether the disk uses the master boot record (MBR) or GUID partition table (GPT) partition style. The disk marked with an asterisk (*) has focus.

select disk

Selects the specified disk, where n is the disk number, and gives it focus.

create partition primary

Creates a primary partition on the current basic disk. After you create the partition, the focus automatically shifts to the new partition. The partition does not receive a drive letter; you must use the assign command to assign a drive letter to the partition.

create partition extended

Creates an extended partition on the current drive. After the partition has been created, the focus automatically shifts to the new partition. Only one extended partition can be created per disk. This command fails if you attempt to create an extended partition within another extended partition. You must create an extended partition before you can create logical drives.

create partition logical

Creates a logical drive in the extended partition. After the partition has been created, the focus automatically shifts to the new logical drive.

size= n

The size of the partition in megabytes (MB). If no size is given, the partition continues until there is no more unallocated space in the current region. The size is cylinder snapped; the size is rounded to the closest cylinder boundary. For example, if you specify a size of 500 MB, the partition would be rounded up to 504 MB.

offset= n

The byte offset at which to create the partition. If no offset is given, the partition will start at the beginning of the first free space on the disk. For master boot record (MBR) disks, the offset is cylinder snapped; the offset is rounded to the closest cylinder boundary. For example, if you specify an offset that is 27 MB and the cylinder size is 8 MB, the offset is rounded to the 24 MB boundary.

ID= byte | GUID

Intended for Original Equipment Manufacturer (OEM) use only.

Caution

  • Creating partitions with this parameter might cause your computer to crash or be unable to start up. Unless you are an OEM or an IT professional experienced with GPT disks, do not create partitions on GPT disks using the ID=byte | GUID parameter. Instead, always use the create partition efi command to create EFI System partitions, the create partition msr command to create Microsoft Reserved partitions, and the create partition primary command (without the ID=byte | GUID parameter) to create primary partitions on GPT disks.
For MBR disks, you can specify a partition type byte for the partition. If no partition type byte is specified on an MBR disk, the create partition primary command creates a partition of type 0x6. Any partition type byte can be specified with the ID=byte | GUID parameter. DiskPart does not check the partition type byte for validity, nor does it perform any other checking of the ID parameter.

For GPT disks you can specify a partition type GUID for the partition you want to create:

  • EFI System partition: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
  • Microsoft reserved partition: e3c9e316-0b5c-4db8-817d-f92df00215ae
  • Basic data partition: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
  • LDM Metadata partition on a dynamic disk: 5808c8aa-7e8f-42e0-85d2-e1e90434cfb3
  • LDM Data partition on a dynamic disk: af9b60a0-1431-4f62-bc68-3311714a69ad
If no partition type GUID is specified, the create partition primary command creates a basic data partition. Any partition type can be specified with the ID=byte | GUID parameter. DiskPart does not check the partition GUID for validity, nor does it perform any other checking of the ID parameter.

noerr

For scripting only. When an error is encountered, specifies that DiskPart continues to process commands as if the error did not occur. Without the noerr parameter, an error causes DiskPart to exit with an error code.

assign letter=D

Assigns a drive letter, D, to the volume with focus. If no drive letter or mount point is specified, the next available drive letter is assigned. If the drive letter or mount point is already in use, an error is generated.

Notes

  • To perform this procedure on a local computer, you must be a member of the Backup Operators group, Administrators group, or you must have been delegated the appropriate authority. If the computer is joined to a domain, members of the Domain Admins group might be able to perform this procedure. As a security best practice, consider using Run as to perform this procedure. For more information, see Default local groups, Default groups, and Using Run as.
  • To open a command prompt, click Start, point to All programs, point to Accessories, and then click Command prompt.
  • You can create primary partitions, extended partitions, and logical drives only on basic disks. You should create basic volumes instead of dynamic volumes if this computer also runs MS-DOS, Windows 95, Windows 98, Windows Millennium Edition, Windows NT 4.0, or Windows XP Home Edition.
  • On a master boot record (MBR) disk, you can create up to four primary partitions, or three primary partitions, one extended partition, and unlimited logical drives.
  • On a GUID partition table (GPT) disk, you can create up to 128 primary partitions, but no extended partitions or logical drives.
  • You cannot create partitions on removable media using DiskPart.
  • For more information about DiskPart, see Related Topics.
Information about functional differences
  • Your server might function differently based on the version and edition of the operating system that is installed, your account permissions, and your menu settings. For more information, see Viewing Help on the Web.

The main point of referring to the MS page is simple as you will see in the example when the need to call up the help in the command prompt does seem a bit limited for the beginner. In this example here however we return to the exact same hard drive shown in Part #2 of the guide here for our test example of how it looks as well showing one type of error that could be seen. The steps here will indicate the "dos" and the "don'ts" to end up with the results we are looking for.

1) We first take a look at the drive in the Disk Management tool once again there to see where we start off here. As you will remember we removed the previous partition seen on the drive making it "raw" in Part #2 earlier.

Posted Image

2) For this example however we will treat that drive as being a brand new just added onto the system but still fresh out of the box(retail or OEM makes no difference). This where we now open up a new command prompt window in order to get started here. The first command entered is "diskpart" to open the utility.

Posted Image

3) Once we see the dos type prompt return "DISKPART>" we once again enter the "list disk" command to have the list of hard drives installed on the system displayed. Here the "select disk" command is used.

Posted Image

The idea of first going into the Disk Management tool is simply to verify that we have the correct drive before entering any commands which might effect the wrong drive if the right one isn't selected as seen in the image here. Note the number of the drive has to match what was seen in the DM there.

4) The first thing to do is getting familiar with the command structure itself as far as which type of partition we are looking for to start with since that will be part of the command itself being used. In this example the typical MS primary type partition is what we are looking for prmarily for Windows use. We start off by typing the command in at the dos like prompt for the 1tb drive being illustrated here.

Posted Image

With 931gb usable drive space the command "create partition primary size 931 offset 8mb" since the entire is being used but something may go wrong if the command is even slightly off a bit. First of all the size entered must see the number in megabytes using the mb abbreviation not the gb for gigabytes or we end up seeing.......

Posted Image

The offset added at the end is for the size we want for the mbr itself and could be upto 24mb in size as seen on the MS page there. What happens if you make a mistake and are working on a machine that is not connected to the internet at the time say helping a friend out or in a repair shop where you work? The word "help" is then added at the beginning of the "create partition primary" command to read as "help create partition primary" for this example here.

Posted Image

If the size is omitted you may see results where the DiskPart tool simply automatically grabs all unallocated drive space it sees on that one drive alone when createing the new primary partition. For simply seeing one large primary that will work easy for most as seen here.

Posted Image

The actual command for the drive here would be "create partition primary size 1000202784mb offset 8mb" for the approximate size when simply looking at the properties screen for the drive itself along with only seeing the default 8mb mbr Windows would place there.

For working on drives where another partition will follow however the exact size intended would be entered to avoid seeing DiskPart simply grab all unallocated space for that one partition alone. As you may have noticed the system protection inplace prompted immediately as soon as the new primary partition was successfully created showing that the command line utility performed the task it was given when entered correctly.

4) Now that the new seen as "RAW"" primaty has been created it will need to formatted before it is actually available for use. While the command prompt is still open you have two options as far as the file system is concerned when going to use the "format" command.

a) For the NTFS format you would type "format fs ntfs quick" in at the command prompt and press enter. The word "quick" seen there is for seeing the quick format option used rather the long wait for the full format.

b) For seeing a Fat 32 format the command would go as "format fs fat32 quick" to insure the quick format with the Fat 32 file system. Note the use of Fat 32 is typically used for external hard drives when sharing one drive between Windows and Apple/Mac since Fat is compatible with both Oparating Systems. Factory Fat 32 volumes are very much a standard for usb flash drives while factory exFat is seen on many external hard drives as a rule unless reformatted to NTFS.

Once you are finished with everything you can type "exit" or simply click on the red X in the upper right hand corner of the prompt to close it up and you are done. Or are you?

The last thing to point out here is that with any new volume(partition) being created it won't be available until going into the Disk Management one last time and giving it a right click. That's when the "Add New Dirve" popup appears and allows you to designate a drive letter which then see it initialize and mounted as a new logical drive in Windows.

In Part #4 we continue with how to expand existing volumes.

t71qir.jpg

 NOTICE: To All New Arrivals - WF Welcome Center - Community Rules

(avatar courtesy of TheBull - WF affiliate CreativX)


#4
Night Hawk

Night Hawk

    WindowsForums Administration

  • Administrators
  • 8,140 posts
  • Gender:Male
PART #4 of Using DiskPart: Extending Volumes

In the last part of this reference with an additional example of using the command line utility DiskPart we refer to the MS TechNet page seen at http://technet.micro...y/cc771473.aspx

This goes into extending basic volumes commonly seen with desktops and laptops alike for extended existing volumes(partitions) on hard drives. One thing to note here however is DiskPart can not be used to extend the C or other drive letter used for the version of Windows you are running while booted in the same installation. To expand one C primary while booted in Windows you would need to have a dual boot setup to extend the other installation's main OS boot primary or use a 3rd party drive partitioning program.

First we refer the TechNet on this as follows.

Extend a Basic VolumeApplies To: Windows 7, Windows Server 2008 R2

You can add more space to existing primary partitions and logical drives by extending them into adjacent unallocated space on the same disk. To extend a basic volume, it must be raw or formatted with the NTFS file system. You can extend a logical drive within contiguous free space in the extended partition that contains it. If you extend a logical drive beyond the free space available in the extended partition, the extended partition grows to contain the logical drive.

For logical drives, boot, or system volumes, you can extend the volume only into contiguous space and only if the disk can be upgraded to a dynamic disk. For other volumes, you can extend the volume into noncontiguous space, but you will be prompted to convert the disk to dynamic.


Extending a basic volume

To extend a basic volume using the Windows interface
  • In Disk Manager, right-click the basic volume you want to extend.
  • Click Extend Volume….
  • Follow the instructions on your screen.
To extend a basic volume using a command line
  • Open a command prompt and type diskpart.
  • At the DISKPART prompt, type list volume. Make note of the basic volume you want to extend.
  • At the DISKPART prompt, type select volume <volumenumber>. This selects the basic volume volumenumber that you want to extend into contiguous, empty space on the same disk.
  • At the DISKPART prompt, type extend [size=<size>]. This extends the selected volume by size megabytes (MB).

Value Description list volume

Displays a list of basic and dynamic volumes on all disks.

select volume

Selects the specified volume, where volumenumber is the volume number, and gives it focus. If no volume is specified, the select command lists the current volume with focus. You can specify the volume by number, drive letter, or mount point path. On a basic disk, selecting a volume also gives the corresponding partition focus.

extend

Extends the volume with focus into next contiguous unallocated space. For basic volumes, the unallocated space must be on the same disk as, and must follow (be of higher sector offset than) the partition with focus. A dynamic simple or spanned volume can be extended to any empty space on any dynamic disk. Using this command, you can extend an existing volume into newly created space.

If the partition was previously formatted with the NTFS file system, the file system is automatically extended to occupy the larger partition. No data loss occurs. If the partition was previously formatted with any file system format other than NTFS, the command fails with no change to the partition.

You cannot extend the current system or boot partitions.

size= size

The amount of space, in megabytes (MB), to add to the current partition. If you do not specify a size, the disk is extended to take up all of the next contiguous unallocated space.


Additional considerations
  • To extend a basic volume, it must either raw (not formatted with a file system), or it must be formatted with the NTFS file system.
  • If the disk does not contain boot or system partitions, you can extend the volume into other non-boot or non-system disks, but the disk will be converted to a dynamic disk (if it can be upgraded).
Additional references
And now for an example to illustrate one example of extending a primary NTFS partition where we return to the same drive seen before in Parts #2 + #3.

1) If just starting refer back to the previous posts for locating the intended drive in the Disk Management tool. Right clicking on the drive's icon can also show the actual size of the partition to be extended with a look at the properties screen. Knowing the present size will be the largest help when opening up the command prompt for diskpart in the next step here.

2) In this example either something went wrong like entering the incorrect size noting Part #3's reference to errors like typing the intended partition size and ending up with 9.31gb instead of the full use of the 1tb drive with a 931gb primary partition. Once we look in the Disk Management tool we either find a new partition was made too small or perhaps the "out of memory" error typically seen when running out of drive space appears for the existing partition.

Posted Image

Once you know the size of the intended partition the command prompt is then opened where the "diskpart" command to get things going is followed immediately with the "list volume" command to end up seeing all volumes even those on any disk left in an optical drive for example as seen in the next image here.

Posted Image

3) The next thing is entering a rather different command not based on the drive where the partition is located but the actual intended volume that will be extended in this example to fill the entire drive. The command used is "select volume 4" once we see the "Too Small" label on the designated partition.

Posted Image

4) For seeing this particular volume extended all you need to type is "extend" once the correct partition is selected and wham! We're there in a matter of a couple of seconds.

Posted Image

5) Relabeling the partition or volume name(optional) or simply put renaming it can be done on the spot or whenever later simply by right clicking on the volume in the DM or on the logical drive's icon seen in Windows Explorer. In WE the general tab's small text is where to change the volume name there and simply click ok or press the enter key to see that change made, The right click menu also sees the rename option as well. So the volume is now relabeled once the correct partition size is realized.

Posted Image

That wasn't so hard was it? Now for extending one partition while another is present on the same drive or for adding a new one to follow the user has control over the actual size by entering the correct size in when going to type the extend command with "extend size 100000mb" to realize a 100gb partition on a drive this size for let's say a new Windows installation while planning a dual boot setup leaving the remaining space for storage, backup, or something else like adding a Linux distro to follow.

INote if you make an error while typing in the command the help list of commands and definitions will appear immediately. For bringing them up at any time for extending a volume or for any other item like creating or deleting a partition simply add the word "help" at the beginning of the command itself. For extending type "help extend" to see....

Posted Image

That's it! DiskPart is able to delete, create, and extend partitions.. For shrinking partitions with the diskpart.exe tool that will be looked at in Part #5.

t71qir.jpg

 NOTICE: To All New Arrivals - WF Welcome Center - Community Rules

(avatar courtesy of TheBull - WF affiliate CreativX)


#5
Night Hawk

Night Hawk

    WindowsForums Administration

  • Administrators
  • 8,140 posts
  • Gender:Male
PART #5 of Using DiskPart: Shrink a Basic Volume

Since there are differences seen with DiskPart between XP, Vista, and 7 each having separate references to look over while this is mainly seen with shrinking volumes we'll be looking at three separate references here. For 7 and Server 2008 we start here with...

Shrink a Basic VolumeApplies To: Windows 7, Windows Server 2008 R2

You can decrease the space used by primary partitions and logical drives by shrinking them into adjacent, contiguous space on the same disk. For example, if you discover that you need an additional partition but do not have additional disks, you can shrink the existing partition from the end of the volume to create new unallocated space that can then be used for a new partition. The shrink operation can be blocked by the presence of certain file types; see Additional considerations for more information.

When you shrink a partition, any ordinary files are automatically relocated on the disk to create the new unallocated space. There is no need to reformat the disk to shrink the partition.

Membership in Backup Operators or Administrators, or equivalent, is the minimum required to complete this procedures.

Posted ImageCaution If the partition is a raw partition (that is, one without a file system) that contains data (such as a database file), shrinking the partition might destroy the data.




Shrinking a basic volume

To shrink a basic volume using the Windows interface
  • In Disk Manager, right-click the basic volume you want to shrink.
  • Click Shrink Volume.
  • Follow the instructions on your screen.

    Posted ImageNote You can only shrink basic volumes that have no file system or use the NTFS file system.


Additional considerations
  • When you shrink a partition, certain files (for example, the paging file or the shadow copy storage area) cannot be automatically relocated and you cannot decrease the allocated space beyond the point where the unmovable files are located. If the shrink operation fails, check the Application Log for Event 259, which will identify the unmovable file. If you know the cluster or clusters associated with the file that is preventing the shrink operation, you can also use the fsutil command at a command prompt (type fsutil volume querycluster /? for usage). When you provide the querycluster parameter, the command output will identify the unmovable file that is preventing the shrink operation from succeeding.

    In some cases, you can relocate the file temporarily. For example, if the unmovable file is the paging file, you can use Control Panel to move it to another disk, shrink the volume, and then move the page file back to the disk.
  • If the number of bad clusters detected by dynamic bad-cluster remapping is too high, you cannot shrink the partition. If this occurs, you should consider moving the data and replacing the disk.

    Do not use a block-level copy to transfer the data. This will also copy the bad sector table and the new disk will treat the same sectors as bad even though they are normal.
  • You can shrink primary partitions and logical drives on raw partitions (those without a file system) or partitions using the NTFS file system.
To shrink a basic volume using a command line
  • Open a command prompt and type diskpart.
  • At the DISKPART prompt, type list volume. Make note of the number of the simple volume you want to shrink.
  • At the DISKPART prompt, type select volume <volumenumber>. Selects the simple volume volumenumber you want to shrink.
  • At the DISKPART prompt, type shrink [desired=<desiredsize>] [minimum=<minimumsize>]. Shrinks the selected volume to desiredsize in megabytes (MB) if possible, or to minimumsize if desiredsize is too large.

Value Description list volume

Displays a list of basic and dynamic volumes on all disks.

select volume

Selects the specified volume, where volumenumber is the volume number, and gives it focus. If no volume is specified, the select command lists the current volume with focus. You can specify the volume by number, drive letter, or mount point path. On a basic disk, selecting a volume also gives the corresponding partition focus.

shrink

Shrinks the volume with focus to create unallocated space.

No data loss occurs. If the partition includes unmovable files (such as the page file or the shadow copy storage area), the volume will shrink to the point where the unmovable files are located.

desired= desiredsize

The amount of space, in megabytes, to recover to the current partition.

minimum= minimumsize

The minimum amount of space, in megabytes, to recover to the current partition. If you do not specify a desired or minimum size, the command will reclaim the maximum amount of space possible.


Additional considerations
  • When you shrink a partition, unmovable files (for example, the paging file or the shadow copy storage area) are not automatically relocated and you cannot decrease the allocated space beyond the point where the unmovable files are located. If you need to shrink the partition further, move the paging file to another disk, delete the stored shadow copies, shrink the volume, and then move the paging file back to the disk.
  • If the number of bad clusters detected by dynamic bad-cluster remapping is too high, you cannot shrink the partition. If this occurs, you should consider moving the data and replacing the disk.

    Do not use a block-level copy to transfer the data. This will also copy the bad sector table and the new disk will treat the same sectors as bad even though they are normal.
  • You can shrink primary partitions and logical drives on raw partitions (those without a file system) or partitions using the NTFS file system.
Additional references
Source: http://technet.micro...4.aspx#BKMK_CMD

For the previous versions of Windows 2000, XP, and Vista we come across a more simplified reference in the guide titled Using DiskPart.exe As Disk Management Alternative in Windows Vista, 2000, 2003, and XP". Here's how that goes.

Using DiskPart.exe As Disk Management Alternative in Windows Vista, 2000, 2003 and XP

Disk Management under Computer Management in Administrator Tools is a GUI (Graphical User Interface) based disk partitioning utility that allows Windows 2000, Windows 2003 Windows XP and Windows Vista users to set active partition, change drive letter and paths, extend volume, shrink volume, delete volume, and format the drives. However, Disk Management extension in Microsoft Management Console (MMC) does not always work properly. Problems faced by users including random grayed out or disabled of Extend Volume and Shrink Volume options, as Disk Management snap-in prohibits you from inadvertently performing actions that may result in data loss.

If you're getting frustrated with Disk Management, try out DiskPart utility, a text-mode command line interpreter based on scripts to manage, create, delete and resize objects such as disks, partitions and volumes in Windows Vista, XP, 2003 and 2000. (Later 3 operating systems do not install with DiskPart.exe by default, so users need to download and install DiskPart manually). As DiskPart is a command line utility, users will have to use various commands to instruct DiskPart to perform a disk related task. Users can use HELP command to list out all available commands for DiskPart. For various options for a command, append the command name to HELP, i.e. HELP [command], or simply type the command name itself only. For detailed explanation and guide to use the command, append the full command syntax to the HELP, i.e. HELP [full command syntax with option].

For easy reference and getting start guide, here's some simple operation that you can perform on your hard disk and partition or volume with DiskPart. But before you continue, make sure that you backup important files and programs in case of any failure.

  • Start and Run DiskPart To run DiskPart, type DiskPart.exe in Start Search in Windows Vista, or in Run command text box in Windows 2000, 2003 and XP finished off by Enter key. A command prompt window with DISKPART shell is loaded.
  • List all disks on system in DiskPart To all your available installed hard disks on the system, simply type list disk, and hit Enter.
  • Select and set target disk to use in Disk Part To set and select a disk which you want to work with in DiskPart, use the following command syntax:

    select disk <disk number (###)>

    The disk number is retrieved from "list disk" command.
  • Create a partition with DiskPart If the hard disk is empty without any partition or still has unallocated space, a partition can be created on it with the following command syntax:

    create partition <partition type> [size=<n>] [offset=<n>] [id={<byte> | <guid>}] [align=<n>] [noerr]

    The partition types that are supported are primary partition (the only bootable type, but limited to four per hard disk), extended partition (also limited to four per hard disk to supplement those need more than 4 primary partitions), logical drive (to define within extended partition to allow many volumes to be created), EFI system partition and MSR (Microsoft Reserved partition). Note that not all options are available for all partition type.

    Example: create partition primary size=1000 (Create a primary partition with the size of 10GB.)
  • Create a volume in DiskPart DiskPart allows user to create RAID (RAID-5) volume using three or more specified dynamic disks, simple volume or striped volume using two or more specified dynamic disks. The syntax for the command is:

    create volume <volume type> [size=<n>] disk=<n>,<N>,<n>[,<n>[,...]] [align=<n>] [noerr]

    Example: create volume raid size=1000 disk=1,2,3 (Create a RAID-5 array volume with 1 GB (1000MB) using disk 1, 2 and 3.)
  • List all volumes in DiskPart Use the following command to list all volumes in order to check which number is associated with the volume we want to work with:

    list volume
  • Select a volume to manage in DiskPart Use the following command to select a volume in order to manage (shrink, extend, delete format) the volume:

    select volume <number>

    The number for the volume is retrieved from "list volume" command.
  • List all partitions in DiskPart Use the following command to list all partitions in order to check which number is associated with the partition we want to work with:

    list partition
  • Select a partition to manage in DiskPart Use the following command to select a volume in order to manage (shrink, extend, delete format) the partition:

    select partiton <number>

    The number for the partiton is retrieved from "list partition" command.
  • Shrink a volume (reduce size of partition) in DiskPart To reduce the size of the volume with focus by the specified amount and makes free disk space available from unused space at the end of the volume, use following command syntax:

    shrink [desired=<n>] [minimum=<N>] [nowait] [noerr]

    Example: shrink desired=500 minimum=250 (Shrink volume by 500 MB, with 250 MB as minimum size to be freed if not possible.)

    To check and determine how much is the maximum number of bytes that a volume can be reduced by (the free space that is available on the volume), use following command:

    shrink querymax [noerr]
  • Extends the volume or partition (increase size) in DiskPart To extend the volume or partition with focus and its file system into free (unallocated) space which can be used to store data on a disk, use following command syntax:

    extend [size=<n>] [disk=<n>] [noerr]

    The above command works on when both volume or partition is selected.

    Example: extend size=500 (Increase the size of current partition or volume selected by 500MB.)
  • Delete partition or volume with DiskPart Note that system, boot or any volume/partition that contains the active paging file or crash dump (memory dump) cannot be deleted. And users must select a partition or volume before start deletion operation. Dynamic disks should be removed by using "delete volume" command.

    delete partition

    delete volume
  • Format a volume or partition in DiskPart Simply select a partition or volume, and then type Format.

Source: http://www.mydigital...00-2003-and-xp/

The part we are concerned with however deals with reduction in size of a test partition on the drive we saw earlier. This time however the drive is loaded up with files and a little caution is observed size wise when going to shrink the test primary down in order to make room for a new second partition. With some 384gb of data and files on the 1tb example drive we wouldn't be planning to shrink the present partition down too far past the 500gb size in order to allow some "breathing room" to a degree.

First we'll go back over the part on shrinking volumes here. From there we have to calculate just how far we can go when shrinking the present partition down due to how is already taken up on the drive.

Shrink a volume (reduce size of partition) in DiskPart

To reduce the size of the volume with focus by the specified amount and makes free disk space available from unused space at the end of the volume, use following command syntax:

shrink [desired=<n>] [minimum=<N>] [nowait] [noerr]

Example: shrink desired=500 minimum=250 (Shrink volume by 500 MB, with 250 MB as minimum size to be freed if not possible.)

To check and determine how much is the maximum number of bytes that a volume can be reduced by (the free space that is available on the volume), use following command:

shrink querymax [noerr]




A good size for the present partition still leaving some free space available would be about 450gb with the absolute minimum at 400gb with 384gb already in use..

Posted Image

Since the amount of drive space entered is seen in MB for megabytes not GB for gigabyte we first need to calculate the correct number for a 450gb size. That would be taking into account the 1,024 binary factor as well to come up with "450 x1.024 = 460800mb".

Now that we have a numerical sum to work with we go to the command prompt to enter that in as part of the command once we have already opened that up and have the volume selected as you will notice the label on it here.

Posted Image

Let's see the results as that number as part of the command is entered. First however we make an inquiry on the maximum allowed reduction of space possible by entering the "shrink querymax" command here.

Posted Image

Well that was an impressive 547gb of reclaimable drive space for a total out the drive capacity of 931gb. Let's drop the 931 figure down by the 387gb of used drive space seen in the properties and confirms the 547gb of available free space. But we still want to leave some space available on the present partition to work with here so we elect the 460800mb total as the amount to use when entering this command for the example here. "shrink desired 460800 nowait noerr" brings up the "the arguments specified in this command are not valid.".

Posted Image

Oops! Is it now time to bring up the "help shrink" help list of commands or simply re-enter a different version using the same sum? Let's now try the "shrink desired 460800mb nowait noerr" command with the "MB for Megabyte" seen in it! Where was the real mistake?

1)syntax was off in Windows 7 by the use of the two items "nowait" and "noerr" which were intended for previous versions of Windows

2) A second error was seen raising the amount from 460800mb to 512000mb with the 460800 as the minimum which ended up generating a log. But didn't the querymax command indicate there was a total of 547gb available for reclaimation?

3)When shrinking any partition down when any data is present you always have to allow some left over free drive space for system access to the volume. Any attempt to reclaim the entire 547gb available for partition #2 resulted in seeing the process stall.

Remember the mention of leaving "some extra space available" made before. Keep that in mind the one thing to remember is that 1mb is one 1thousandth of a gig or 1,024mb is equal to 1gb explaining the unintended extra space with the first partition ending up being 31gb over the intended size when shrunk.

You have to adjust your calculations through trial and error at times when trying to calculate the accurate number to enter into the command.

Posted Image

If we accept the error and leave the results as 481gb here the drive is now ready for one or more new partitions. We now can see how that works by first mistyping the "create partition primary" command intentionally here so you can see the type of partitions displayed when the error is made.

With that in mind we now see a new primary partition added to the drive and formatted afterwards with the "format fs ntfs quick" command.

Posted Image

Posted Image

Oh look the security here detected a new drive! as you can see how the basic commands always seem to work the best. The last look here shows what happens when you go to use the "format fs ntfs" command but forget to add the "quick" for quick format onto it.

With the quick added at the end the formatting is just that quick! Without that however we end up waiting for a full format which takes a long... time.

Posted Image

Posted Image

Most will prefer to add the word "quick" when going to format any new partition created with DiskPart. When adding the "quick" at the end the volume actually ends up seeing a quick format take place almost instantaneously as seen in the next image here.

Posted Image

There's one for sure. If you realize a mistake has been made in a command and have already pressed the enter the only way to see the process halted immediately may just be a full system restart. By left clicking on the volume being formatted and going upto the "menu bar>Actions>All tasks" to select cancel it may continue going anyways.

Once you do have the new partition formatted don't forget to right click on it when going back into the Disk Management tool in order to see the prompt for adding a new drive where you then need to select a drive letter for it. Otherwise you won't find it in Computer, Windows Explorer since the volume wouldn't be mounted as a new logical drive.

A command line utility like DiskPart is much like MS Dos in that way where each command once entered is final. For eror messages appearing if any on the other hand you simply restart all over with no harm done.

t71qir.jpg

 NOTICE: To All New Arrivals - WF Welcome Center - Community Rules

(avatar courtesy of TheBull - WF affiliate CreativX)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users