Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Learn how to master the DISKPART command

  1. #1
    Join Date
    Nov 2008
    Posts
    202

    Learn how to master the DISKPART command

    DiskPart is one of the most powerful Windows commands. It allows you to accurately manage the partitions, resizing them, their assignment and their formatting. It can be incorporated into a script, and most importantly, may itself execute scripts. It is essential to restructure the USB key and is a formidable weapon to automate deployment of Windows on parking machines.

    Before you can use DiskPart 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 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 displays only partitions on the disk that have 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.

    Warning

    The DISKPART command is for an informed public that already have a minimum knowledge about partitioning and formatting disks and the use of command-mode "command prompt".

    Misuse of this command can cause the loss of your data on your disks. We do not recommend beginners to use DISKPART. Most DiskPart functions are available as user-friendly Windows interface by clicking the right button on "My Computer" (or "Computer" on Vista) and selecting "Manage from the context menu" before selecting the module "Disk Management".

    DISKPART is present in XP, Vista and Windows 7. However, the XP version is more limited because it does not offer advanced features for resizing partitions, for example.

    To start DISKPART, do the following:

    - On Windows XP
    Go to Start> All Programs> Accessories
    Click Command Prompt.

    - For Windows Vista/Windows 7
    Go to Start> All Programs> Accessories
    Right click on the Command Prompt icon
    Select Run as administrator from the context menu.

  2. #2
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Commands Focus (Select/List)

    The DISKPART command uses mainly two types of commands:

    - Those which specify the target or the scope of action: List, Help, Rem, Select, Exit
    - Those that apply directly to the pre element: Active, Assign, Create, Extend, Shrink ...

    Most commands work on the pre element, in other words, the element that has the focus. It is, in the controls, the selected disk, the volume selected, the selected partition.

    The LIST command

    They enable the list of disks, partitions and volumes:

    - LIST DISK
    Gives the list of drives recognized by the system. The disc preceded by a "*" is the disk that currently has the Focus Diskpart.

    - LIST PARTITION
    Gives a list of partitions on the disk that has the Focus

    - LIST VOLUME
    Provides a list of all volumes (unit disc) declared in the system

    The SELECT

    They can change the "Focus" (ie the selected item).

    - SELECT DISK n
    Select the disk that has the focus. The "n" is the disk number as given by the LIST DISK command.

    - SELECT PARTITION n
    Select the partition that has the focus. The "n" is the partition number on the disk that has the focus and as indicated by the LIST PARTITION command

    - SELECT VOLUME l
    Select the volume designated for a Focus. The parameter "l" is the letter assigned to the unit disc.

    The capture demonstrates the combined use of the command LIST and SELECT.

  3. #3
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Erase and repartition

    The DISKPART commands make it possible to create and delete partitions. To do so, mainly 6 commands:

    - CLEAN
    One of the most practical and most dangerous: it removes at once all the partitions on the selected disk.

    - CLEAN ALL
    Equally dangerous, this command removes all of a sudden the selected disk partitions but also writes zero byte and every sector of the disk. Easy to completely erase a disk.

    - CREATE PARTITION PRIMARY size = n
    Creates a primary partition the size defined by the "n".

    - CREATE EXTENDED PARTITION size = n
    Creates an extended partition to the size defined by the "n".

    - CREATE PARTITION LOGICAL size = n
    Creates a logical partition in the extended partition to the size defined by the "n".

    - DELETE PARTITION
    Clears the partition that has the focus (be careful to check which partition is selected by a List Partition before running this command).

    Example of implementation:

    If you have a USB drive (we assume here Disc No. 3), you can have fun with the following sequence to erase everything and re-partitioning a primary partition of 1GB and a secondary logical partition on the rest of space disk:

    LIST DISK
    SELECT DISK 3
    CLEAN
    CREATE PARTITION PRIMARY size = 1000
    CREATE PARTITION EXTENDED
    CREATE PARTITION LOGICAL
    RESCAN
    LIST PARTITION

    Note in passing the command RESCAN who force DISKPART to refresh the data and take into account the creation of disk partitions and previously realized.

  4. #4
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Assign and resize volumes

    DISKPART can assign letters to partitions of volumes, but also to remove those letters (which is to hide the Windows partition).

    But above all DISKPART (Windows Vista and Windows 7) is used to resize partitions.

    The instructions to know are:

    - ASSIGN LETTER = l
    Assign selected volume (which has the focus) the letter indicated by the "l"

    - REMOVE LETTER = l
    Remove the drive letter associated with the disk volume that has the focus. The command REMOVE/ALL deletes all the letters of all volumes (dangerous).

    - EXTEND Size=n
    Extends the selected volume (the one that has the focus) by adding the size indicated by "n". The command only works on NTFS volumes

    - SHRINK QUERYMAX
    Indicates how many megabytes the currently selected NTFS volume can be reduced (depending on its defragmentation and not his occupation)

    - SHRINK DESIRED MINIMUM = x = y
    Reduces the disk at least the value "y", while trying to reach the value "x" if possible.

    Example of use of commands

    LIST DISK
    SELECT DISK 3
    CLEAN
    CREATE PARTITION PRIMARY size = 1000
    ASSIGN LETTER = G
    FORMAT FS = NTFS QUICK
    LIST VOLUME
    SELECT VOLUME G
    EXTEND size = 500
    SHRINK QUERYMAX
    SHRINK MINIMUM=500 DESIRED=800
    LIST VOLUME

    Note in passing the command FORMAT which can format a partition.

  5. #5
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Conversions and Details

    DiskPart allows for all sorts of conversions volumes not always feasible since the Windows interface.

    Orders for conversion

    - CONVERT MBR
    Converts a basic GPT disk or dynamic to MBR classic disk

    - CONVERT GPT
    Only 64 bits. Converts the selected MBR disk to GPT disk

    - CONVERT DYNAMIC
    Convert a basic disk to dynamic disk (useful on servers in particular) without losing data

    - CONVERT BASIC
    Convert a dynamic disk into basic disk. Beware, the disc must be empty of all data.

    Ordering information

    These commands display additional details on the disks, partitions and volumes.

    - DETAIL DISK
    Detailed information of the disk that has the focus

    - DETAIL PARTITION
    Detailed information of the partition that has the focus

    - DETAIL VOLUME
    Detailed information of the volume that has the focus

    Example:

    LIST DISK
    SELECT DISK 0
    DETAIL DISK
    SELECT PARTITION 1
    DETAIL PARTITION
    SELECT VOLUME C
    DETAIL VOLUME

  6. #6
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Other useful commands

    Here are other commands to know:

    - ?
    Provides a list of all commands

    - HELP command
    Explains the parameters of a command (example: HELP SHRINK)

    - EXIT
    Quits DISKPART and returns to the command prompt classic

    - OFFLINE DISK
    Met "offline" the current disc

    - ONLINE DISK
    Reconnect the disk placed OFFLINE

    - ACTIVE
    Because of the partition that has the Focus, the new boot partition (Active Partition)

  7. #7
    Join Date
    Nov 2008
    Posts
    202

    Re: Learn how to master the DISKPART command

    Scripting

    Diskpart supports scripted operations. To initiate a Diskpart script, use the diskpart /s script.txt command. You can script Diskpart on Windows XP, Windows 2000, Remote Installation Services (RIS) unattended install environments, or on the Windows Preinstall Environment (PE) for OEMs.

    By default, Diskpart can quit command processing and return an error code if there is a problem in the script. To continue to run a script in this scenario, include the noerr parameter on the command. This parameter allows you to use a single script to delete all partitions on all data drives, regardless of the total number of drives. However, not all commands support the noerr parameter. Even if you use the noerr parameter, an error is always returned on command syntax errors.

    The following list describes the error codes for Diskpart:
    • 0 - No error occurred. The entire script ran without failure.
    • 1 - A fatal exception occurred. There may be a serious problem.
    • 2 - The arguments specified on a Diskpart command line 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.

  8. #8
    Join Date
    May 2009
    Posts
    1

    Re: Learn how to master the DISKPART command

    It is true that running diskpart /s script.txt usually exits when errors occur and not all commands support the noerr parameter.
    The workaround for this , as usually, is simple :
    just run diskpart as follows: diskpart <script.txt
    ét voila. Errors are ignored and script continues on next line.
    I use it this way to make sure the CDROM drive (usually volume 0) gets assigned another drive letter than D , but on some hardware here, assigning it to letter "E:" gives an error about the disk not being empty or something.
    I made the script do:

    select volume 0
    assign letter g
    assign letter f
    assign letter e


    so it gets the lowest driveletter without erroring out....

  9. #9
    Join Date
    Nov 2009
    Posts
    1

    Re: Learn how to master the DISKPART command

    I am trying to use the diskpart error codes as triggers in my script.

    Basically, I need to automatically assign a drive letter to a volume on a usb device but the volume # might change depending upon the computer I plug it into.

    so I thought if i wrote a script that tried to id and assign to volume 1 and it wasn't my usb device I could get it to default to volume 2 and then 3.

    The end goal is that I have a program that requires a specific path to run and I need to push it out to a bunch of people all with different drive mappings.

    Any help is appreciated.

    thanks

  10. #10
    Join Date
    Oct 2011
    Posts
    1

    Re: Learn how to master the DISKPART command

    I really need some help with diskpart commands, so I hope that somebody is still monitoring this thread, or gets email notification. I recently sold a pc on ebay which would include a 320GB HDD. I didn't want to take any chances on data being recovered from the drive so I did a "clean all" on the disk to be sure.

    Seeing how this would take some time, I started it after work and went to bed. In the course of the night the XP machine this was running on decided to do an update and restart. Long story short, I no longer have the diskpart command line to create the new partition and format the drive, and I can't (don't know how) get the XP machine or a 7 machine to recognize the drive.

    I don't think it matters any, but the drive is sitting in a docking station and mounted in the machine. If anybody could help me out I would greatly appreciate it. If you can give me a list of commands I need to get this disk back to normal and ready to ship I would be forever gratefull.

  11. #11
    bpaw Guest

    Re: Learn how to master the DISKPART command

    I'm no expert, but I've been working on installing windows from a usb stick, and I think I might have something for you here. Boot from a windows installation disk and select the recovery option. Included somewhere in these menus is a dos-prompt option, you can run diskpart from it. If you don't have an optical drive (dvd drive) on the computer, then you need to make a boot-usb stick using a windows dvd and functioning computer, then you can boot from the usb as if it was an installation dvd.
    One more thing. If you don't have a windows dvd, just the download for installation, just click on it, it will burn an installation dvd for you, which you can then use for the proceses above.

  12. #12
    gigilatrottola Guest

    Re: Learn how to master the DISKPART command

    Quote Originally Posted by bponch View Post
    If anybody could help me out I would greatly appreciate it. If you can give me a list of commands I need to get this disk back to normal and ready to ship I would be forever gratefull.
    Second, I'm glad to offer you advice as this has just recently happened to me, hence my original reason for going in to this forum post.

    Any who, you were on the right track, you just got derailed and now you must jump tracks and start all over.

    Open CMD
    Type diskpart
    Hit enter
    Type list disk
    Hit enter
    Type select disk X (Where 'X' is your drive, chose the right one or else!)
    Hit enter
    Type attrib disk
    Hit enter
    Type attrib disk clear readonly
    Hit enter
    Type clean (or 'clean all' as desired)
    Hit enter
    Type exit
    Hit enter


    Done!

    Good Luck!
    Last edited by bhaskar; 21-12-2011 at 01:04 PM. Reason: External Links Not Allowed

  13. #13
    Join Date
    Aug 2011
    Posts
    1

    Re: Learn how to master the DISKPART command

    thanks for very useful information.... but i have a problem

    i was making usb bootable but interrupted it in the middle after that usb detected but becomes inactive as soon as i perform any action on it i m also not able to format it. it is showing healthy status in disk-part detail disk. partition inside that disk is also type Heathy anf offset is 64 KB but when i try to make partition active it shows "Diskpart encountered an error system cannot find the files specified"...


    Please tell me if there is any way of which i can formate and make my USB usable again.. THANk YOu

  14. #14
    Join Date
    Dec 2007
    Posts
    996

    Re: Learn how to master the DISKPART command

    Quote Originally Posted by ananddhouni View Post
    thanks for very useful information.... but i have a problem

    i was making usb bootable but interrupted it in the middle after that usb detected but becomes inactive as soon as i perform any action on it i m also not able to format it. it is showing healthy status in disk-part detail disk. partition inside that disk is also type Heathy anf offset is 64 KB but when i try to make partition active it shows "Diskpart encountered an error system cannot find the files specified"...
    Can you try to run DiskPart from a System Repair Disc. You can boot up your Windows 7 DVD and at the very first dialog requiring you to do something, use SHIFT + F10 key combo to get to a command prompt. Then after that go to a command prompt using the windows 7 dvd, follow the below steps:
    1. First of all boot up from your Windows 7 DVD.
    2. After that at the first dialog window, press SHIFT + F10 key combo
    3. Then you will have a X:> command prompt
    4. Lastly X: is a ram drive created by Windows

  15. #15
    Join Date
    May 2010
    Posts
    8

    smile Re: Learn how to master the DISKPART command

    I didn't know about "Diskpart"..I got very useful information by reading this article..Being a fresher I won't use but will keep in mind if any problem regarding the partitioning issue I'll surely go for your given steps

Page 1 of 2 12 LastLast

Similar Threads

  1. Diskpart and dumpcfg download
    By Thinkpad21 in forum Windows Server Help
    Replies: 3
    Last Post: 31-12-2013, 10:37 AM
  2. Fortify command disabled in Warlock: Master of the Arcane
    By Elias Blackman in forum Video Games
    Replies: 3
    Last Post: 11-05-2012, 10:47 AM
  3. How to use Diskpart as Hard Disk Manager on command line
    By FolloW Me in forum Tips & Tweaks
    Replies: 4
    Last Post: 22-02-2011, 12:32 PM
  4. Extending partition diskpart.exe
    By JennyHtwk in forum Windows Server Help
    Replies: 1
    Last Post: 13-01-2009, 07:52 AM
  5. Diskpart Format command
    By RScotti in forum Vista Help
    Replies: 10
    Last Post: 15-03-2007, 12:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,707,072.19100 seconds with 17 queries