Fixing Disk Drives Using Diskpart (Windows)

Fixing Disk Drives Using Diskpart (Windows)

Usually using a  hard drive or flash drive is as easy as just plugging in the drive and letting Windows recognize it.  However, sometimes things can go terribly wrong leaving the drive with only a fraction of its space usable and no easy way to fix it.  I recently encountered this problem again while using my Windows 7 PC and thought this would be a great How-To article as I remember finding little information online to help fix this problem previously.

Disclaimer: Follow this tutorial at your own risk. This post will help you gain space on an improperly formatted storage device. Using DiskPart can result in data loss. Selecting the wrong drive/disk/volume and formatting/cleaning a disk will cause data loss. Always be sure to back up your data.

I was working on turning a 16GB flash drive into a bootable usb installer for openSUSE Linux (so I could turn an old PC without a DVD/CD drive into a home server.  This is a possible future post. I will be sure to link to it here if I create it)  However when I plugged the drive into my PC, I saw that I left the drive in a broken state with only 4MB of usable space.  This happened as I was not successful with my last attempt to create a Linux USB installer.  There are many other situations where this can happen as well.

4MB USB Drive. However it should have 16GB
Disk shows only 4MB of space, however it is actually a 16GB flash drive.

As right clicking and formatting the drive will only format the space listed, my next step was to examined the drive using Disk Management.  Disk Management can be found under the Control Panel, under System and Security in the Administrative Tools section.  Here there is an option ‘Create and format hard disk partitions’.

Looking at the drive under Disk Management showed that all the space expected was still on the drive, however was not included in the current usable space.

Disk Management screen showing my lost 14GB of space
Disk Management shows all drives available on your PC. Here it shows my system drives, DVD drive and the 4MB disk drive with 14GB of unused space.

Although you can usually right click the drives here and extend or delete a partition, this drive would have none of that.  This is where Diskpart comes in.

Diskpart is a built in utility in Windows that allows you to manage storage devices via a command line.  Don’t worry though, even though it doesn’t have a GUI(Graphical User Interface) it is very easy to use and straight forward.

Diskpart  can be started in two ways, both requiring Administrative privileges:

  1. Search your PC for ‘diskpart‘ and run the search result.
  2. Open the command line utility(cmd.exe) as Administrator and then run ‘diskpart‘.

Either method should bring up a window that looks like this:

diskpart
Daunting blank screen

Don’t be intimidated by the blank screen, typing help will show you all of the commands available to you.

diskpart_help
Still daunting, but these are a helpful list of commands available to manage your storage devices.

Great, so now we have a wall of commands to use, but which ones?

First we want to use list.  This will list all objects of a particular type.  Typing list without a parameter will show you the options.  Disk, Partition, Volume and VDisk.

  • Disks are storage devices, think of it as the physical device.
  • Partition is a section of the Physical Disk.  You can create multiple partitions on a single disk.
  • Volume is one or more partitions that create a single accessible space
  • VDisk is a virtual disk, it is the same logically as a physical disk, however is created as a file on a disk instead of being a physical storage device.

Now that we understand the list command, lets find the disk we need to use by using the command: list disk

list_disk
Example: list disk – shows my four physical storage devices. This image was taken after I corrected my size issue.  As you can see Disk 3 is the disk I used as it is the one with 14GB of storage.

Once you have identified the disk you want to work with, you will need to select it using the select command.

select disk yourdisk#

yourdisk# is the disk that you you need. (For my example, the command I used was: select disk 3)

Running the command will let you know what disk was selected with a response of Disk # is now the selected disk.

After selecting the disk, we need to clean all settings from it.  (Warning, this will cause data loss!)
Run the command clean.

Once cleaned, you may receive either an error or success message.   I received an error but the disk no longer retained its broken partitioning.  I had checked this by viewing the device under My Computer and the usb drive had only a name with no space listed.

Next we will need to reformat the disk.  This will be done by selecting the Volume.  Use list volume followed by select volume # (be sure to use the correct number of the volume you wish to format.)

With the volume selected, we can now use format.  This command will format the drive as specified.
(Warning: Formatting will cause data loss. Be sure you have the proper volume selected!
I wanted a simple NTFS drive, so I issued format FS=NTFS

To quick format, add QUICK at the end, Ex:  format FS=NTFS QUICK.

I prefer to use a full format instead of quick so all previous data is overwritten to ensure that I will not have file or drive troubles down the road.  If the drive was only being formatted and not having to correct the filesystem/partition(s) then a quick format would do.

Once the format is complete you should have full space on the drive once again.

If you would like additional information regarding diskpart‘s commands, you can find them on Microsoft’s Technet Site:  http://technet.microsoft.com/en-us/library/cc766465%28v=ws.10%29.aspx

Please let me know if anything is unclear or needs revised in the comments below!

 

Comments are closed.