Tuesday, September 15, 2015

Cancel/Stop DiskPart full disk format

Using DiskPart to clean up hard disk partitions and MBR is fast and easy but you can accidentally invoke a full format which can take a while to finish. In that case, instinctively you would press Ctrl+C only to find that you've just killed DiskPart instead of stopping the format process.
Googling around, people suggest to kill the process using task manager (which you can't) or reboot your system. There is yet an other option, which worked for me, and no one mentioned (at least on the sites I checked).

You can take your disk offline! Doing so, it will stop the format process and by bringing the disk back online, you can continue working with it. Unfortunately, this solution works only with HDD (external or internal), not with flash drives (not supported operation). Stopping the format process will leave your partition in RAW state, which means it's inaccessible until you format it. If you want to recover data or partitions, you need to use recovery tools which I'm not covering with this post.

In order to take your disk offline you can use either DiskPart or Disk Management (Start -> Run -> diskmgmt.msc). 
With DiskPart you need to select your disk and then use the "offline disk" command. Here's an example:
C:\Windows\system32>diskpart
DISKPART> list disk
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          238 GB      0 B
  Disk 1    Online          186 GB      0 B
DISKPART> select disk 1
  Disk 1 is now the selected disk.
DISKPART> offline disk
  DiskPart successfully offlined the selected disk.
DISKPART> online disk
  DiskPart successfully onlined the selected disk.
Using Disk Management, Right click on the disk -> Offline.


If you're interested, here's how I was cleaning my old disks from partitions and Active (bootable) status:
C:\Windows\system32>diskpart
DISKPART> list disk
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          238 GB      0 B
  Disk 1    Online          186 GB      0 B
DISKPART> select disk 1
  Disk 1 is now the selected disk.
DISKPART> clean
  DiskPart succeeded in cleaning the disk.
DISKPART> create partition primary
  DiskPart succeeded in creating the specified partition.
DISKPART> format fs=ntfs quick
    100 percent completed
  DiskPart successfully formatted the volume.
DISKPART> assign
  DiskPart successfully assigned the drive letter or mount point.
Notice the quick parameter at the end of the format command which at some point I forgot and inspired this post.

If you need to do some DiskPart tasks repetitively, you should check DiskPart Scripting where you can automate the process passing a text file containing the commands you want to execute, for example:
C:\Users\Christos\Desktop>diskpart /s formatDisk1.txt
In my case, formatDisk1.txt content is:
list disk
select disk 1
clean
create partition primary
format fs=ntfs quick
assign