Diskpart program. Formatting and creating a bootable USB flash drive or disk via the command line

DiskPart is a command-line console utility for working with disks (disk), partitions (partition) and volumes (volume). Developed by Microsoft for the Windows family of operating systems. Therefore, there should be much less problems, as, for example, when using software from Acronis, or Paragon. It has much more features than the Disk Management snap-in with a graphical interface. DiskPart can also be launched during the installation of Windows Vista/7/8, which will help in the future not to create an extra 100MB reserved partition that Windows creates automatically.

So, a start has been made. Now more about this "mysterious" section, which is created automatically.

When partitioning a disk during the installation of Windows 7, in addition to creating a partition for the system of the size we have chosen, the installer will create a main partition of 100MB in size, which will later contain boot files (bootmgr and BCD (Boot Configuration Data)). This is understandable, but why should we give Windows 7 an extra primary partition if there can be a maximum of 4 (or 3 if using an extended partition)? And do we need this confusion with 2 Windows 7 partitions? Is it worth mentioning that it is necessary in cases of partition compression or Windows partition encryption using BitLocker™ . It is also needed when using NTFS with a cluster size >4k. In all other cases, it is not necessary. So the average user doesn't need it.

What can I do to prevent this additional partition from being created?

Everything is simple! You need to install Windows on an already formatted active partition of the priority hard drive. If a HDD there is only one in the computer, then it will be a priority. If there are several of them, then it is recommended to disable extra disks during the installation of Windows. Or correctly prioritize in the BIOS (UEFI).

Consider 2 situations:
1. Disk is empty. There is no data on it, or the data is not important.
2. The disk is already marked. Those. it contains a section(s) with important information that should be left unchanged, and there is also a section(s) on the disk that should be deleted.

To launch DiskPart during Windows installation, at the first stage, press Shift + F10 and get into the cmd shell. Run the disk utility diskpart.


To run DiskPart from an already installed Windows 7/Vista, administrator rights are required, so run cmd with administrator rights.


There is a help command in diskpart to get general help, or use help commandname (for example, help clean) to get help on a specific command.


The following examples will use a 20GB virtual hard disk on the same VMware virtual machine. DiskPart will run from cmd shell during Windows 7 installation.
Additional items that apply to work in an already installed OS are marked with "*" and in italics.

Situation #1.
Disk is empty. There is no data on it or the data is not important. Let's create a main partition for the system, and an extended partition in which there will be two logical partitions for data and for documents.

Sequencing.
1. We look at the list of disks in the system.

Or

Or

4. Delete the information on the disk, reset the MBR.
or
clean all - zeroing all sectors on the disk
5. Let's create the main (primary) partition for the system X megabytes in size.

create part primary size=X

6. Let's make it active (bootable).
7. Format the partition in NTFS, assign the label (logical drive name) "System", apply quick format.

format fs=ntfs label=System quick

*. If necessary (for example, when a partition is created during normal operation in the OS, for further filling it with data from under the OS), connect this partition to the system (assign a letter to the logical drive in the current OS).

8. Let's create an extended (extended) partition for data and documents for all the remaining disk space.

create part extended

9. Inside the extended partition, create a logical (logical) partition for data, X megabytes in size.

create part logical size=X

10. Format the partition in NTFS, assign the label "Data", apply quick format.

format fs=ntfs label=Data quick


11. Repeat steps 9 and 10 for the section with documents. Inside the extended partition, let's create a logical (logical) partition for documents, for all the remaining space.

create part logical

12. Format the partition in NTFS, assign the label "Documents", apply quick format.

format fs=ntfs label=Documents quick

*. If necessary, connect this section to the system.

13. Let's see what happened.

14. If everything is correct, you exit diskpart.
15. Also, if the command line is no longer needed, then we also exit it.
*. By installing the system on a formatted primary partition labeled "System", Windows will not create an additional 100MB primary partition. Here is the result after installing Windows 7 with our partitions.

Situation #2.
The disk consists of the above configuration. 1 main partition, 1 extended. An extended partition consists of 2 logical partitions. You need to delete the partition with the system located on the main partition, and one of the logical partitions inside the extended partition, let it be the partition labeled "Data". In place of 1 main partition, create 2 main partitions, and label them "Win7" and "WinXP". In place of the logical partition, create 2 logical partitions labeled "Data1" and "Data2".

Sequencing.
Since the disk contains important information, I advise you to use the "detail disk" and "list part" commands as often as possible to control your actions. Well, as always, the author is not responsible for your actions.
1. The first 3 points are unchanged. We look at the list of disks in the system.
2. Set the focus to the priority (first in BIOS) disk for further work.

Or
sel disk N - select disk number N
3. Check that the required disk is selected.

Or

4. We look at what sections are on the disk and their numbering order.
5. We combine these numbers with their names and sizes (in the mind, or on a piece of paper), focusing on the results of the next command.

6. We understand that the disk is based on partition number 1 and has a size of 17GB, has the label "System" and it is this that we must delete. To do this, set the focus to this section.
*. You can check that exactly the section that you wanted to select was selected.

detail disk

7. Delete the selected section.
8. We check that everything was deleted correctly.

9. Let's create a primary (primary) partition for the "Win7" system with a size of X megabytes.

create part primary size=X

10. Let's make it active (bootable).
11. Format the partition in NTFS, assign a label (logical drive name) "Win7", apply a quick format.

format fs=ntfs label=Win7 quick

12. Let's create a primary (primary) partition for the "WinXP" system, for all the remaining space.

create part primary

13. Format the partition in NTFS, assign a label (logical drive name) "WinXP", apply a quick format.

format fs=ntfs label=WinXP quick

14. We check that everything was created correctly.

Macrorit Disk Partition is a portable program for managing hard disk partitions. Thanks to this tool, you can not only resize individual partitions without formatting them first, but also optimize the overall speed of your HDD/SSD.

The main window of Macrorit Disk Partition displays basic information about the disks installed in the system: total volume, amount of free space, file system and current "health". The program also indicates the partitions and boot areas that are located on each physical media. In order to get more detailed information about disks, select the "Properties" item in the partition's context menu. In the same place (in the context menu) you will find other functions that Macrorit Disk Partition can perform: resizing, copying a partition, changing the label, checking the volume for errors, defragmenting, deleting a partition, formatting, full cleaning and analyzing the media surface. The program also provides a tool for creating boot drives.

Almost every function in Macrorit Disk Partition has a special step-by-step wizard with detailed explanations and tips. The developers from Macrorit did everything to make working with their program as comfortable as possible. It is one of the few hard drive managers that is completely free for home use. There is also a paid Professional edition that offers users 24/7 technical support and a few extra features.

Key features and functions

  • the ability to manage the size of existing partitions without prior formatting;
  • the ability to select new sections and assign them the necessary labels;
  • availability of tools for defragmentation, checking the disk surface, formatting and complete cleaning of data from the partition;
  • the ability to assess the current state of the physical media;
  • the function of creating bootable media;
  • section with detailed information about the sectors;
  • the ability to work in portable mode (without installation in the system).

DiskPart is a command-line console utility for working with disks (disk), partitions (partition) and volumes (volume). Developed by Microsoft for the Windows family of operating systems. Therefore, there should be much less problems, as, for example, when using software from Acronis, or Paragon. It has much more features than the Disk Management snap-in with a graphical interface. DiskPart can also be launched during the installation of Windows Vista/7/8, which will help in the future not to create an extra 100MB reserved partition that Windows creates automatically.

So, a start has been made. Now more about this "mysterious" section, which is created automatically.

When partitioning a disk during the installation of Windows 7, in addition to creating a partition for the system of the size we have chosen, the installer will create a main partition of 100MB in size, which will later contain boot files (bootmgr and BCD (Boot Configuration Data)). This is understandable, but why should we give Windows 7 an extra primary partition if there can be a maximum of 4 (or 3 if using an extended partition)? And do we need this confusion with 2 Windows 7 partitions? Is it worth mentioning that it is necessary in cases of partition compression or Windows partition encryption using BitLocker™ . It is also needed when using NTFS with a cluster size >4k. In all other cases, it is not necessary. So the average user doesn't need it.

What can I do to prevent this additional partition from being created?

Everything is simple! You need to install Windows on an already formatted active partition of the priority hard drive. If there is only one hard drive in the computer, then it will be a priority. If there are several of them, then it is recommended to disable extra disks during the installation of Windows. Or correctly prioritize in the BIOS (UEFI).

Consider 2 situations:
1. Disk is empty. There is no data on it, or the data is not important.
2. The disk is already marked. Those. it contains a section(s) with important information that should be left unchanged, and there is also a section(s) on the disk that should be deleted.

To launch DiskPart during Windows installation, at the first stage, press Shift + F10 and get into the cmd shell. Run the disk utility diskpart.


To run DiskPart from an already installed Windows 7/Vista, administrator rights are required, so run cmd with administrator rights.


There is a help command in diskpart to get general help, or use help commandname (for example, help clean) to get help on a specific command.


The following examples will use a 20GB virtual hard disk on the same VMware virtual machine. DiskPart will run from cmd shell during Windows 7 installation.
Additional items that apply to work in an already installed OS are marked with "*" and in italics.

Situation #1.
Disk is empty. There is no data on it or the data is not important. Let's create a main partition for the system, and an extended partition in which there will be two logical partitions for data and for documents.

Sequencing.
1. We look at the list of disks in the system.

Or

Or

4. Delete the information on the disk, reset the MBR.
or
clean all - zeroing all sectors on the disk
5. Let's create the main (primary) partition for the system X megabytes in size.

create part primary size=X

6. Let's make it active (bootable).
7. Format the partition in NTFS, assign the label (logical drive name) "System", apply quick format.

format fs=ntfs label=System quick

*. If necessary (for example, when a partition is created during normal operation in the OS, for further filling it with data from under the OS), connect this partition to the system (assign a letter to the logical drive in the current OS).

8. Let's create an extended (extended) partition for data and documents for all the remaining disk space.

create part extended

9. Inside the extended partition, create a logical (logical) partition for data, X megabytes in size.

create part logical size=X

10. Format the partition in NTFS, assign the label "Data", apply quick format.

format fs=ntfs label=Data quick


11. Repeat steps 9 and 10 for the section with documents. Inside the extended partition, let's create a logical (logical) partition for documents, for all the remaining space.

create part logical

12. Format the partition in NTFS, assign the label "Documents", apply quick format.

format fs=ntfs label=Documents quick

*. If necessary, connect this section to the system.

13. Let's see what happened.

14. If everything is correct, you exit diskpart.
15. Also, if the command line is no longer needed, then we also exit it.
*. By installing the system on a formatted primary partition labeled "System", Windows will not create an additional 100MB primary partition. Here is the result after installing Windows 7 with our partitions.

Situation #2.
The disk consists of the above configuration. 1 main partition, 1 extended. An extended partition consists of 2 logical partitions. You need to delete the partition with the system located on the main partition, and one of the logical partitions inside the extended partition, let it be the partition labeled "Data". In place of 1 main partition, create 2 main partitions, and label them "Win7" and "WinXP". In place of the logical partition, create 2 logical partitions labeled "Data1" and "Data2".

Sequencing.
Since the disk contains important information, I advise you to use the "detail disk" and "list part" commands as often as possible to control your actions. Well, as always, the author is not responsible for your actions.
1. The first 3 points are unchanged. We look at the list of disks in the system.
2. Set the focus to the priority (first in BIOS) disk for further work.

Or
sel disk N - select disk number N
3. Check that the required disk is selected.

Or

4. We look at what sections are on the disk and their numbering order.
5. We combine these numbers with their names and sizes (in the mind, or on a piece of paper), focusing on the results of the next command.

6. We understand that the disk is based on partition number 1 and has a size of 17GB, has the label "System" and it is this that we must delete. To do this, set the focus to this section.
*. You can check that exactly the section that you wanted to select was selected.

detail disk

7. Delete the selected section.
8. We check that everything was deleted correctly.

9. Let's create a primary (primary) partition for the "Win7" system with a size of X megabytes.

create part primary size=X

10. Let's make it active (bootable).
11. Format the partition in NTFS, assign a label (logical drive name) "Win7", apply a quick format.

format fs=ntfs label=Win7 quick

12. Let's create a primary (primary) partition for the "WinXP" system, for all the remaining space.

create part primary

13. Format the partition in NTFS, assign a label (logical drive name) "WinXP", apply a quick format.

format fs=ntfs label=WinXP quick

14. We check that everything was created correctly.

Today I want to tell you about such a wonderful program as. What is so wonderful about her? - you ask. And the fact that with its help you can (data from a flash drive after formatting) or a disk, and the most interesting thing is that this program is available to any Windows user through the command line, in other words, it does not require installation. And don't let the phrase "command line" scare you - using it is much more convenient and easier than it seems at first glance.


So, after we have inserted the USB flash drive into the USB connector, we launch the command line. To do this, press Start and in the search bar write cmd, and press Enter.

In the command line that appears, we write, thereby launching the program for managing disks. Click Enter.

In the list of devices we find our flash drive - it can be recognized by its size. In my case it is Disc 6. Therefore, we write the following command. If your flash drive is number 4, then you need to enter the command. If under the number 2, then, respectively. Click Enter.

Then we enter the command clean, which will delete all files from a flash drive or disk. Click Enter.

Then we enter the command. Thus, we select the specified section and move the focus to it. Click Enter.

Then we execute the command. The system marks the partition as active. Click Enter.

Now it is necessary. It can be fast or complete. Full formatting is done with the command format fs=NTFS. If you don’t want to wait and time is running out, then we do a quick format with the command format fs=NTFS QUICK. Click Enter.

We are waiting for the end of formatting.

Now you need to assign a letter to the flash drive. We do this with the command assign. Click Enter.

The flash drive is automatically assigned a letter, and after that, the autorun of the media is triggered.

Now you can exit the program. We enter the command exit and press Enter.

The last thing to do is copy the distribution files of the operating system (the one for which we made a bootable USB flash drive) to, in fact, our flash drive. After that, our flash drive will be bootable, and will boot absolutely everywhere, on any device. With its help, it will be possible to install your operating system anywhere.

I want to note that with the help of the program you can carry out a lot of manipulations with both hard drives () and flash drives. The example discussed today is only a small part of all the possibilities. I will consider other commands and examples of working with this program in the following articles.

Also read on this topic:

Format flash drive to NTFS
How to recover data from a flash drive after deletion or formatting? How to change disk size in Windows 2000/XP/Vista/7/8. Free program EaseUS Partition Master Free How to create a bootable UEFI flash drive to install Windows 8.1 and 10?
How to freeze a row in Excel? How to create a disk image using Daemon Tools?

This guide explains how to use the diskpart utility for the following Windows versions: Windows XP, Vista, 7, 8, 8.1 or 10.

What is diskpart

The diskpart utility (available in Windows 2000, XP, Vista, 7, 8, 8.1 and 10) can be used to create or delete partitions on your PC.

The utility allows you to:

  • Partition
  • Remove partitions
  • Remove formatting
  • Assign and remove drive letters and mount points
  • Convert disks from basic to dynamic
  • Create and extend volumes

Most commands that you can perform in Disk Management (see ) are available with diskpart. Because it's a command line utility, you need to open Command Prompt and type diskpart .

On Windows Vista, 7, 8 and 10 systems, you can type diskpart at Run, click OK or press Enter and Command Prompt will automatically open with diskpart loaded.

When the utility is loaded, you will notice the version installed on your computer:

Microsoft DiskPart version 6.1.7600 Copyright 1999-2008 Microsoft Corporation. On Computer: MY_COMPUTER

Commands and parameters

The diskpart tool has the following commands and parameters available:


error codes

You can find a list of error codes to debug various errors:

  • Code 0 means no errors occurred
  • Code 1 means that a fatal exception occurred
  • Code 2 means that the parameters you specified for a command are incorrect
  • Code 3 means that diskpart is unable to open the specified file
  • Code 4 means that diskpart (one of the services used by the utility) returned a failure
  • Code 5 means a command syntax error

diskpart in Windows XP

Note that the fdisk utility found in pre-Windows XP systems is now known as diskpart on Windows XP systems.

If you can boot into Windows XP

If you can boot into your computer, you simply need to open Command Prompt to access diskpart:

  1. Boot into Windows XP
  2. Click start
  3. Click Run
  4. Type cmd
  5. Press Enter or click OK
  6. At the Command Prompt window, type diskpart
  7. Press Enter

If you can't boot into Windows XP

If you can't boot into Windows XP to access diskpart, you have 2 options:

  • Use the original CD to access Recovery Console

If you have the original CD:

If you can't boot into Windows XP, but you have the original CD, you can access the Recovery Console:

  1. Insert the Windows XP CD
  2. Reboot the computer
  3. Press any key to boot from the CD
  4. At the Microsoft Setup menu, press R
  5. Select the operating system and enter the Administrator password, if requested
  6. When Command Line appears, type diskpart
  7. Press Enter

diskpart in Windows Vista

You need to run these steps as an Administrator on Windows Vista systems.

If you can boot into Windows Vista with no errors, . Otherwise, follow .

If you can boot into Windows Vista

You simply need to open Command Prompt, if you can boot into Windows Vista:

  1. Boot into Windows Vista
  2. click start
  3. Type cmd
  4. Click Command Prompt from the search results list. You may need to right-click Command Prompt > Run as Administrator, if you are not logged in as Administrator already
  5. Type diskpart
  6. Press Enter

If you can't boot into Windows Vista

If you can't boot into your system, you have the following options:

  • Use the installation disc to access System Recovery Options
  • Access System Recovery Options without the installation disc (if installed)

If you can't boot into Windows Vista, but you have the Windows Vista disc, follow these steps to open diskpart:


For the full list of diskpart commands and paremeters, go to .

If your Windows Vista has the System Recovery Options installed and is available at the Advanced Boot Options menu, you can run Command Prompt from there. Otherwise, see the “If you use Easy Recovery Essentials” set of instructions below.

Follow these steps below to access diskpart without the installation disc:

    1. Reboot the computer
    2. Press F8 as your computer starts to boot, but before the Windows Vista logo appears
    3. Select Repair Your Computer, at the Advanced Boot Options menu

If a “Repair Your Computer” option isn’t listed, System Recovery Options is not installed on your computer. Use the original installation disc or go to the “If you use Easy Recovery Essentials” set of instructions below .

For the full list of diskpart commands and paremeters, go to .

If you use Easy Recovery Essentials:

If you don't have the installation disc available, can't boot into Windows Vista or you don't have the “Repair Your Computer” option listed at the Advanced Boot Options menu, you can use Easy Recovery Essentials to access Command Prompt and load diskpart.

Follow these steps:


diskpart in Windows 7

Note that you need to run these steps as an Administrator on Windows 7 computers.

If you can boot into Windows 7

If you can boot into your Windows 7 system, simply open Command Prompt:

  1. Boot into Windows 7
  2. click start
  3. Type cmd
  4. Click Command Prompt from the search results list. Right-click on Command Prompt > Run as Administrator.
  5. When Command Prompt loads, type diskpart
  6. Press Enter

For the full list of diskpart commands and paremeters, go to .

If you can't boot into Windows 7

Similar to Windows Vista, if you can't boot into your system, you have the following options:

  • Use the installation disc
  • Boot into the Advanced Boot Options menu to access System Recovery Options
  • Use Easy Recovery Essentials and access Command Line

If you have the installation disc:

If you can't boot into Windows 7, but you have the installation disc, you can run diskpart using the disc. To do so, follow these steps:


diskpart
  1. Press Enter

For the full list of diskpart commands and paremeters, go to .

If you don't have the installation disc:

Usually, Windows 7 systems should have the System Recovery Options installed on the hard drive. If it's not (follow steps below), go to the “If you use Easy Recovery Essentials” set of instructions below for an alternative to access diskpart.

Follow these steps to access diskpart without an installation disc on a Windows 7:


For the full list of diskpart commands and paremeters, go to .

If you use Easy Recovery Essentials:


diskpart in Windows 8

If you can boot into Windows 8

If you can boot into your Windows 8 system, you simply need to open Command Prompt to access diskpart. To do so, follow these steps:

For the full list of diskpart commands and paremeters, go to .

If you can't boot into Windows 8

If you can't boot into your Windows 8, you have these options available:

  • Use the original DVD or USB with Windows 8 or Windows 8.1 to access the Repair your computer option
  • Use Easy Recovery Essentials to launch Command Line

If you have the installation disc:


For the full list of diskpart commands and paremeters, go to .

If you don't have the installation disc:

To access diskpart without an official Windows 8 or Windows 8.1 disc, follow these steps:


For the full list of diskpart commands and paremeters, go to .

If you use Easy Recovery Essentials:

Easy Recovery Essentials can run from any CD, DVD or USB flash drives.

To access diskpart using Easy Recovery Essentials, follow these steps:


diskpart in Windows 10

If you can boot into Windows 10

If you can boot into your Windows 10 system, you simply need to open Command Prompt to access diskpart. To do so, follow these steps:

For the full list of diskpart commands and paremeters, go to .

If you can't boot into Windows 10

If you can't boot into your Windows 10, you have these options available:

  • Use the original DVD or USB with Windows 10 to access the Repair your computer option
  • Boot into the System Recovery Options with Shift and F8
  • Use Easy Recovery Essentials to launch Command Line

If you have the installation disc:

If you can't boot, but you have the installation disc, follow these steps:


For the full list of diskpart commands and paremeters, go to .

If you don't have the installation disc:

If you don't have the installation disc, you can boot into System Recovery Options or use Easy Recovery Essentials.

To access diskpart without an official Windows 10 media, follow these steps:


For the full list of diskpart commands and paremeters, go to .

If you use Easy Recovery Essentials:

Easy Recovery Essentials can run from any CD, DVD or USB flash drives.

To access diskpart using Easy Recovery Essentials, follow these steps:


Troubleshooting

Download diskpart

You can't download diskpart utility. This utility is a command line utility part of Windows.

To access diskpart, you have the following options:

  • Use the original CD/DVD or USB of your Windows to access Recovery Console (for Windows XP) or System Recovery Options (for Windows Vista-8)
  • Boot into the recovery mode of your Windows
  • Use Easy Recovery Essentials, our recovery and repair disk, and open Command Line to access diskpart

Instructions on how to access diskpart if you use Easy Recovery Essentials:

  1. Download
  2. Burn the ISO Image. Follow . If you'd like to have a recovery USB instead, follow .
  3. Boot Easy Recovery Essentials from the CD, DVD or USB
  4. Select Launch Command Line

Instructions on how to access diskpart if you have the installation disc:

Instructions on how to access diskpart if you don't have the installation disc:

Format USB with diskpart

To format a USB flash drive with diskpart, follow these steps:

  1. Open the utility by typing diskpart in Command Prompt
  2. Press Enter
  3. Once loaded, type list disk: list disk
  4. Press Enter
  5. Determine which of the disks listed is your USB flash drive, e.g. Disk 2.
  6. Type select disk 2 , if #2 is the USB flash drive presented by the list disk command
  7. Press Enter
  8. Type clean to clean the USB flash drive: clean
  9. Press Enter
  10. Type this command: create partition primary
  11. Press Enter
  12. Type active: active
  13. Press Enter
  14. You should now receive this confirmation message: DiskPart marked the current partition as active.
  15. Type this command to format the USB flash drive: format fs=ntfs label="MY USB DRIVE"

    where ntfs is the NTFS file system (you can also use fs=fat32) and “MY USB DRIVE” is the label given to the USB drive.

  16. Type assign: assign
  17. Press Enter
  18. Quit diskpart by typing exit: exit
  19. Press Enter

Bootable USB with diskpart

To create a bootable USB using diskpart, follow the steps from .

Once successfully formatted the drive, simply copy the files to the USB drive.

USB not showing in diskpart

diskpart will not list external media, e.g. USB flash drive, if you're using Windows XP.

Windows Vista to Windows 8 systems will show the USB flash drives in diskpart.

More Information

Support Links

  • – our repair and recovery disk.

    It's an easy-to-use and automated diagnostics disk. It's available for , and . It's also available for Windows XP and Windows Server.

mob_info