How to Undo the Diskpart Clean Command and Recover Data after Disk Clean

manuviraj
Written by
Approved by
748

undo diskpart cleanRunning the clean command in diskpart is a recommended step if you want a fresh start on your drive and want to create new partitions and reformat the drive. But what if you run the command on the wrong disk. Is your data irreversibly lost? The answer is no. Use our guide and find out how you can recover data lost by the diskpart clean command.

What is a diskpart Command

Windows offers two ways to manage the storage disks connected to your PC–Windows Disk Management, and diskpart. While the first one has a GUI, diskpart is a command-line based utility. It’s more challenging to use, but diskpart offers far more functionality and options for disk modification and management.

The clean command removes the partition information from the selected drive. The space that the partition occupied will become unallocated, i.e., it will be available for creating a new partition. This means you won’t be able to access or modify files that were located in the partition. However, the files themselves are not deleted, until you create a new volume using the unallocated space.

A similar command, clean all, is destructive. Not only does it remove the partition information and unallocate the space, but it also wipes your data completely. It does this by writing zeroes to each sector of the disk. As a result, the previous data is practically irrecoverable. The command also takes much longer to run–about an hour per 320 GB of storage size.

Only use the clean all command if you want to securely erase all data on your drive.

Is It Possible to Undo the diskpart Clean Command?

No, you cannot undo the diskpart clean command. Creating a new partition using the unallocated space and formatting it will not get back your data. Instead, it’ll make recovering the cleaned partition even more difficult.

If you accidentally executed the clean command, don’t execute any more commands. Your data can be recovered from the unallocated space using data recovery software. In most cases, you can even restore the entire partition from an accidentally cleaned disk.

How to Recover Data after diskpart Clean with Data Recovery Software

Modern data recovery solutions can access and recover data from unallocated space on your drive. But, there are plenty of such programs available on the internet, and it can be overwhelming to choose from so many options.

We recommend you opt for Disk Drill, as it makes data recovery extremely accessible. It essentially eliminates the hassle of double-checking for compatibility between the data recovery program and your particular data recovery situation. How? Well, it works with both GPT and MBR drives, recognizes over 400 file formats, and is available for both Windows and macOS. In fact, as a Windows user, you can take advantage of Disk Drill’s free trial and recover up to 500 MB of data at zero cost.

Here’s how you can use Disk Drill to recover data, lost by running the diskpart clean command:

  1. Download Disk Drill and install it.
  2. Open Disk Drill, select the drive that you accidentally cleaned and click on Search for lost data.Search for lost data in Disk Drill.
  3. Click on Review found items to view the recoverable files on your disk. You can directly click on the relevant file type to filter out the results (Pictures, Videos, Audio, Documents, Archives, and Other).Review found items.
  4. Expand the Existing section to view files that are there on the cleaned disk. You can also expand the Deleted or lost section to view files that you accidentally deleted earlier.Data recovery sections.
  5. Use the checkboxes next to the file names to select them. Disk Drill displays a preview of the currently selected file. To manually see a preview, click on the eye icon next to the filename. Click on Recover once you’re satisfied with your selection.List of recoverable files.
  6. Choose a recovery destination for the files, and click Next.Recovery destination prompt in Disk Drill.
  7. Disk Drill will recover your files.

How to Recover Partition after diskpart Clean

After running the diskpart clean command, the space it occupied will become unallocated, and you won’t be able to use it. So, how do you make that space usable again? You have two options–create a new partition from the unallocated space using diskpart or Windows Disk Management, or use TestDisk to recover the cleaned partition in its entirety.

If you opt to go with the first option, be sure to recover your data. While data recovery programs can still recover your files if you performed a quick format, restoring data after a full format is impossible.

Option 1: Use diskpart to Create a Partition

If you’re comfortable using Windows Command Prompt, you can use the diskpart utility itself to create a new partition from the unallocated space.

Follow these instructions carefully:

  1. Search for “cmd” in Windows Search (Windows Key + S). Right-click on Command Prompt > Run as administrator.
  2. Type diskpart in the console and press Enter.Diskpart command.
  3. Type list disk and press Enter.List disk diskpart.
  4. Type select disk x and press Enter. Replace x with the disk number of the cleaned disk. For example, select disk 1.Select disk diskpart.
  5. Create a primary partition using the create partition primary command. The partition size will be equal to the total unallocated space on the drive.Create partition diskpart.
  6. Type format fs=NTFS quick and press Enter. This will format the drive to the NTFS file system and make it ready to store your files. You can use a file system of your choice.Format parameters diskpart.
  7. Now, type list volume and press Enter.List volume diskpart.
  8. Type select volume x and press Enter. Replace x with the number of the newly created partition. In our case, it was Volume 6.Select volume diskpart.
  9. Type assign letter=X and press Enter. Replace X with whatever drive letter you want to assign to the volume.Assign drive letter diskpart.

Option 2: Use Disk Management to Allocate Space

A more approachable way to create a new partition using unallocated space, is to use the Disk Management GUI.

Here’s how to create a new partition from the cleaned disk, using Windows Disk Management:

  1. Type “disk management” in Windows Search (Windows Key + S). Choose Create and format hard disk partitions from the search results.
  2. Look towards the bottom of the Disk Management. The cleaned disk’s space will show up as Unallocated. Right-click on this space and choose New simple volume.New simple volume wizard option.
  3. Click Next on the New simple volume wizard welcome screen.Simple volume welcome screen.
  4. Specify a partition size in the Simple volume size in MB field. Click Next.Specify volume size.
  5. Choose a drive letter in the Assign the following drive letter drop-down menu. Click Next.Assign drive letter.
  6. Define a name for your partition in the Volume label field. This is optional. Choose the required file system according to your needs, and click Next.Format parameters.
  7. Double-check everything and click Finish.Finish simple volume wizard.

Option 3: Use Testdisk to Create a New Partition Table

TestDisk is an excellent partition recovery tool that can help you to essentially revert the effects of the diskpart clean command. It’ll recover partitions from external and internal drives along with the partition table. The program restores the partition to its original state, with all your files intact.

However, TestDisk doesn’t have a GUI and all navigation is to be done through the keyboard.

To recover a cleaned partition using TestDisk, follow these steps:

  1. Download TestDisk and extract the contents. Run the testdisk_win.exe file.
  2. Use the Up and Down arrow keys to select whether you want to create a log file or not. Press Enter to confirm your selection. It’s usually a good idea to create one.Create log file.
  3. Select the disk you ran the clean command on, and press Enter. Again, use the arrow keys for this.Disk selection in TestDisk.
  4. Select the partition table type. TestDisk detects this automatically in most cases, so it’s best to leave the highlighted option as it is and simply press Enter.Partition table type.
  5. Select Analyse and press Enter.Analyse in TestDisk.
  6. Select Quick Search and press Enter.Quick Search in TestDisk.
  7. Use the Left and Right arrow keys to cycle between the partition types, until there’s a P right at the beginning of the partition. Use the image below for reference. Press Enter.Primary partition TestDisk.
  8. Select the Write option using the arrow keys and press Enter. If you want TestDisk to search for more partitions or if it didn’t find one you’re looking for, select Deeper Search instead and press Enter.Write option TestDisk.
  9. Press Y on the confirmation prompt and press Enter.
  10. TestDisk will recover the partition.

Conclusion

The diskpart utility is one of the most powerful ways to manage your drives. But, it’s easy to make a mistake and run the clean command on the wrong disk. While data recovery programs can recover your data here, the best way to protect yourself against data loss is to have a regular backup schedule and stick to it.

FAQ:

The clean all command permanently deletes all the data on the selected drive and writes zeroes to each sector. There’s little you can do to reverse this. Your best bet is to contact a professional data recovery service. Even then, a complete recovery of your data is unlikely.
No. In many ways, they’re the opposite. The clean command removes your data and the partition information, including the file system, from the selected drive. While formatting also removes all the files from your drive, it writes a new file system to your drive, readying it to store data.
The clean command removes all partitions and volumes from your drive and marks the space available for use. It doesn’t actually permanently delete your data. All of it is recoverable as long as you don’t reformat the drive. On the other hand, the clean all does everything that the clean command does, but it also overwrites each sector of the drive with zeros. This makes data recovery impossible.
There’s no official way to stop the clean all command once you press Enter. The only thing you can do is immediately reboot your PC. This will stop the command’s execution, but you also risk data corruption. However, this data will be recoverable using data recovery software.
manuviraj
Manuviraj Godara is a professional content writer with over 4 years of experience under his belt. His ever-growing fascination and experience with technology drives him to create content related to data recovery and consumer technology.
Approved by
12 years experience in software development, database administration, and hardware repair.