author avatar
    Technology Manager of Test Dept.
 

Summary
Explore Diskpart command for hard disk adjustments, and restore deleted files confidently with Renee Undeleter.



Detailed explanation of DiskPart command

I. About the DiskPart command

1. What is the DiskPart command?

DiskPart is a command-line utility used in various Windows operating systems to manage disks, partitions, and volumes. Users can perform tasks like adding drive letters, resizing partitions, marking partitions as active, creating or deleting partitions, and formatting. Administrative privileges are required to run DiskPart commands from Command Prompt or PowerShell Terminal.

2. Common DiskPart command parameters

The DiskPart command has many parameters, some common ones are listed below. For more parameters, refer to Microsoft’s official description page.
parameterillustrate
assignAssign a drive letter or mount point to the selected volume.
attributesDisplay, set, or clear disk or volume attributes.
activeMark the disk partition that has focus as active.
createCreate a partition on a disk, a volume on one or more disks, or a VHD (virtual).
cleanRemoves all partition or volume formats from the selected disk.
selectMove focus to a disk, partition, volume, or virtual hard disk (VHD).
convertConverts the file allocation table of a FAT (FAT) FAT32 volume to the NTFS file system, leaving existing files and directories intact.
deleteDelete a partition or volume.
detailDisplays information about the selected disk, partition, volume or virtual hard disk (VHD).
exitExit the diskpart command interpreter.
extendExtends the volume or partition with focus and its file system onto (frees up) space on the disk.
formatFormat the disk to accept Windows files.
inactiveMarks the system partition or boot partition that has focus as basic primary (logging) activity in MBR disks.
listDisplays a list of disks, disk partitions, disk volumes, or VHD (virtual).

3. How to open DiskPart?

Here are 2 ways to open DiskPart.
Method 1: Start the Windows computer, enter cmd in the search box, right-click (command prompt), and select (Run as administrator).
run as administrator
Enter "diskpart" in the command prompt and press Enter. Then, enter the corresponding parameters after "DISKPART" and press Enter to execute the command.
Method 2: Start the Windows computer, press (Windows logo + R) to open the run window, enter (diskpart) in the text box and click the (OK) button, then enter the corresponding parameters behind (DISKPART>) and press (Enter) to execute the command.
type diskpart to run

II. Common usage scenarios of the DiskPart command

Introducing common DiskPart command usage scenarios and specific steps for reference.

1. Add drive letter

We can add a drive letter to the partition through the DiskPart command. Specific steps are as follows:
Step 1: Start the computer, enter (cmd) in the search box, right-click (Command Prompt), and select (Run as Administrator).
run as administrator
Step 2: Please enter the following commands to add the drive letter, and press the (Enter) key once for each line of command.

diskpart

list volume

(list all volumes/partitions in the computer)

Select volume 7

(the partition number of a hard drive)

assign letter=M

(add drive letter M, M can be replaced by other unused English letters)

exit

(exit)
Diskpart assigns a drive letter

2. Mark the partition as active

The active partition is the Windows primary partition with boot data, completing handover and startup tasks with the BIOS to boot the system. Follow the steps below to set up an active partition
Step 1: Start the Windows computer, press (Windows logo + R) to open the Run window, enter (diskpart) in the text box, and click the (OK) button.
type diskpart to run
Step 2: Enter the following commands and press the (Enter) key after each command.

list disk

(list the disk in the computer)

select disk 0

(disk 0 refers to the number of the hard drive where Windows is to be installed)

list partition

(list the partitions in the disk)

select partition 1

(1 is the number of the partition to be marked as active, and please modify it according to your partition.)

active

(set the partition as active)

exit

(exit)
diskpart set the active partition

3. Format the disk

To format a disk using Diskpart, follow these steps:
Step 1: Start the Windows computer, enter (cmd) in the search box, right-click (Command Prompt), and select (Run as Administrator).
run as administrator
Step 2: Next, enter the following commands in sequence in the command prompt, and press the (Enter) key after you input each command.

diskpart

list disk

(list the disks in the computer)

select disk 1

(1 refers to  the target disk number)

clean

(delete partitions and volumes on the disk and clear all information)
diskpart clear disk data
Then please continue to enter the following command:

create partition primary

(If you need to assign a drive letter, you can enter (assign letter = H) after this command. H is the drive letter of the new partition, which can be changed according to your hard drive.)

format fs=fat32 quick

(fs=fat32 means to format the target partition as a FAT32 file system, or replace FAT32 with exFAT or NTFS, and quick means to quickly format.)

exit

(exit)
diskpart create primary partition and format

4. Understand the disk or partition information

Step 1: Start the Windows computer, enter (cmd) in the search box, right-click (Command Prompt), and select (Run as Administrator).
run as administrator
Step 2: Please enter the following command to know the disk information, and press (Enter) after you input each command.

diskpart

list disk

 (list the disks in the computer)

select disk 2

 (2 is the target disk number)

detail disk

 (list the target disk type and status, and show you whether it is read-only and other attributes, etc.)
Step 3: To retrieve information about a specific partition, enter the following command and press (Enter) after each line.

diskpart

list disk

(list the disks in the computer)

select disk 0

(0 is the target disk number)

list partition

(list all partitions in the target disk)

select partition 2

(select the target partition)

detail partition

(display whether the target partition is hidden, active, and its file system, size, etc.)

5. Clear the read-only attribute of the disk

If the disk is set to read-only, use the Diskpart command to resolve the issue.
Step 1: Start the Windows computer, enter (cmd) in the search box, right-click (Command Prompt), and select (Run as administrator).
run as administrator
Step 2: Enter the following commands in sequence and press the Enter key once for each command line.

diskpart

list disk

(list all disks in the computer)

select disk 1

(1 indicates the number of the target disk, which can be changed.)

attributes disk clear readonly

(clear the read-only attribute of the disk)

exit

(exit)
attributes disk clear readonly command

6. Convert disk partition format

When initializing a disk in the Windows system, the user will be prompted to choose between MBR or GPT partition types. To convert the disk partition format, you can use the Diskpart command.
Step 1: Start the Windows computer, enter (cmd) in the search box, right-click (Command Prompt), and select (Run as administrator).
run as administrator
Step 2: Please enter the following commands in sequence, and press the (Enter) key once for each command line.

diskpart

list disk

(list all disks in the computer)

select disk 1

(1 indicates the target disk number)

clean

(clear all information and data in the disk)

convert gpt

(convert the disk to GPT partition form, or replace GPT to MBR according to your needs.)

exit

(exit)
diskpart
The clean parameter of Diskpart will clear all data on the disk, partition or volume. If you accidentally run this command parameter, resulting in the loss of all disk/partition data, you can check the following content to try to scan and restore.

III. If the hard disk/partition data is deleted by mistake, how to restore it?

After deleting data by mistake, stop using the target hard disk/partition immediately to avoid storing new data, then use professional data recovery software like Renee Undeleter to scan and restore the data as soon as possible. The software offers a free trial version that can scan the hard disk/partition to find lost files, with a preview function to check for data damage, and a free recovery quota of 50MB.

1. What is Renee Undeleter?

Renee Undeleter is a software designed to restore data files that have been accidentally deleted, emptied from the recycle bin, or lost due to disk formatting. It offers four functional modules for file recovery, formatting recovery, partition recovery, and image creation to help solve various data loss issues.
Hot Topic - ADsRenee Undeleter – Simple & Powerful Software for Data Recovery

Easy to use Recover data by 3 steps;

Multiple scan modes Fast partition scan, whole partition scan and whole disk scan;

Supported file types Image, video, audio, text, email and so on;

Image creation Create a partition image to read and back up data;

Supported devices SD card, SDHC, SDXC, USB flash drive, hard disk and computer.

Easy to use Recover data by 3 steps;

Multiple scan modes Fast partition/whole partition/whole disk scan;

Supported devices SD card/USB/hard disk.

Free TrialFree TrialFree Trial 800 people have downloaded!

2. How to use Renee Undeleter to recover hard disk/partition data?

Step 1: Download, install, and run Renee Undeleter on the computer, and select the (Whole Disk Scan) option on the main interface. To speed up the scanning process, consider using the (Fast Partition Scan) or (Whole Partition Scan) function.
Note: Do not install Renee Undeleter in the disk where data is lost to avoid data overwriting.
elect whole disk scan in renee undeleter
Data recovery function introduction:

  • Fast Partition Scan – Quickly retrieve files lost due to accidental deletion or emptying the recycle bin.
  • Whole Partition Scan – Quickly recover files lost due to inaccessible or formatted partitions.
  • Whole Disk Scan – Analyze and get partition information and perform a full scan of the entire partition.
  • Image Creation – You can create a mirror image for a partition to back up the current partition state.
Step 2: Select the disk where the lost data is located, then click Next.
select a disk to recover in renee undeleter
Step 3: Please wait patiently for the scan to find all existing partitions on the disk. Select the lost partition to scan in the “Select the partition you need to scan” window. If not selected, all partitions will be scanned, taking longer but scanning more data.
Step 4: Double-click files to preview during scanning. Check the required files, then click (Recover) to restore target files to other disks.
recover files from whole disk scan with renee undeleter