How to repair flash drive with diskpart?

Diskpart is a command-line utility included in Windows for managing disks and partitions. It allows you to perform various disk operations like initializing a disk, creating and deleting partitions, formatting volumes, setting active partitions, assigning drive letters, creating spanned/striped volumes, converting between dynamic and basic disks, etc. Diskpart can be very useful when trying to repair a corrupted flash drive or external hard drive.

When a flash drive becomes corrupted or unreadable by Windows, Diskpart provides a way to completely wipe and re-initialize the drive so that Windows recognizes it again. You can use Diskpart commands to clean the drive, create a new primary partition, format it, and assign a drive letter. After following the Diskpart steps, the flash drive is essentially reset to a blank state and ready to be used again. Diskpart offers more options and control compared to using Windows Disk Management for repairing drives. That’s why it’s such a valuable tool for troubleshooting and restoring access to malfunctioning flash drives.

Prerequisites

Before repairing a flash drive with Diskpart, there are a few prerequisites that need to be met:

You need administrator access on the computer in order to use Diskpart commands (source: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart). Diskpart is a command-line utility built into Windows operating systems, so you don’t need to install anything.

The flash drive that needs to be repaired must be plugged into the computer. Diskpart can only manage drives that are currently connected to the system.

It’s a good idea to backup any important data on the flash drive before using Diskpart, as the drive will be reformatted which will erase all existing data.

Overall, Diskpart requires admin access, the target drive connected, and backups completed before proceeding.

Check Drive Status

The first step is to check the status of the flash drive using the diskpart command in Windows. This will confirm whether Windows detects the drive and provide details on its current condition.

To check the drive status:

  1. Open the Command Prompt as an administrator. Go to Start, type ‘cmd’, right-click on Command Prompt and select Run as administrator.
  2. In the Command Prompt, type ‘diskpart’ and press Enter. This will open the DiskPart utility.
  3. Type ‘list disk’ and press Enter. This lists all the disks connected to your computer.
  4. Identify the disk number for your flash drive from the list.
  5. Type ‘select disk x’ where x is the disk number. This selects the flash drive.
  6. Type ‘detail disk’ and press Enter. This shows details about the drive including the current status.

Review the status to confirm if the drive is detected, if it shows the correct capacity, and if it displays any errors. This will indicate whether the drive is corrupted or unhealthy.[1]

Clean The Drive

The next step is to clean the flash drive. This will completely erase the drive and clear any existing partitions and data. To do this, use the ‘clean’ command in diskpart.

According to Seagate, the clean command removes the drive’s partition and file system information so it appears as raw unallocated space to the operating system. It also overwrites the Master Boot Record with null data.

After typing ‘clean’ and hitting enter, diskpart will clean the selected drive. This is an important step when trying to repair a malfunctioning or corrupted flash drive, as it wipes the slate completely clean.

The ‘clean’ command erases all existing data and partition information, preparing the drive to be repartitioned and reformatted.

Create Partition

The next step is to create a new primary partition on the flash drive. This can be done using the create partition primary command in diskpart.[1] For example:

create partition primary

This will create a new primary partition on the flash drive, using all available space. To specify the size of the partition, you can add the size option:

create partition primary size=1024

This will create a 1 GB primary partition. You can specify the size in megabytes (MB) or gigabytes (GB).

It’s important to note that this will delete all existing partitions and data on the drive when creating the new partition. So make sure to backup anything important first. The create partition primary command is a quick and easy way to setup a new blank partition on a flash drive using diskpart.

[1] https://www.diskpart.com/articles/create-multiple-partition-on-usb-drive-0708.html

Format Partition

Once the new partition is created on the flash drive, the next step is to format it. This will prepare the partition to store files by creating a file system. The Format command in DiskPart can be used to format the partition.

The basic syntax is:

format [partitonID] [filesystem] [options]

To format the partition quickly using the NTFS file system, the command is:


format [partitonID] fs=ntfs quick

For example, if the partition ID is 1, the command would be:

format 1 fs=ntfs quick

This will format the partition for use with the NTFS file system. The quick option skips some checks and performs a faster format.

Once the format command completes successfully, the partition will be ready to use.

Assign Letter

To assign a letter to the flash drive partition, use the assign letter command in diskpart. The syntax is:

assign letter=[letter]

Where [letter] is the drive letter you want to assign. For example, to assign the letter F, you would type:

assign letter=F

This will assign the selected partition the drive letter F. You can choose any available letter to assign to the flash drive partition. According to the Qualitest Group, letters A and B are reserved for floppy drives, and other letters may already be in use, so choose an available letter.

Once the letter is assigned, the flash drive partition will now be accessible in Windows Explorer with that drive letter.

Check Status Again

Once you have completed all the steps to clean, create a partition, and format the USB drive, it’s important to check the status again to confirm it was properly repaired. Here are the steps to repeat the status check:

1. Type list disk and hit enter. This will show all disks connected to the computer.

2. Type select disk x (where x is the number of your flash drive from the list disk command) and hit enter. This will select your flash drive.

3. Type detail disk and hit enter. This will show details about the selected disk.

4. Look for the disk status and partition information. It should show the disk as “Online” and display the correct partition type and format [1].

5. Type list volume and hit enter. Look for your flash drive letter and file system to confirm it is now working properly.

If everything looks correct, you have successfully repaired your flash drive using diskpart!

Finalize Changes

After completing all the necessary steps to repair your flash drive in Diskpart, you must use the “exit” command to finalize the changes and save them to disk. Without properly exiting Diskpart, any changes you made will not actually take effect.

According to Microsoft’s documentation, “The exit command quits the DiskPart command interpreter. If you have modified partitions without saving, exit prompts you to either save your changes or quit without saving. Type exit at the DISKPART prompt to quit the program.” (Source)

So after completing all other Diskpart commands like clean, create, select, assign, etc., be sure to type “exit” and save the changes to have them actually apply to your flash drive.

Conclusion

In summary, the key steps to repair a damaged flash drive using Diskpart on Windows are:

  1. Check the drive status and identify the correct disk number using the List Disk command
  2. Clean the drive by selecting the disk and using the Clean command
  3. Create a new primary partition using the Create Partition Primary command
  4. Format the partition using the Format FS= FAT32 Quick command
  5. Assign a drive letter using the Assign Letter=X command
  6. Check the status again to confirm the drive is now working
  7. Finalize the changes using the Exit command

Some additional tips for ongoing maintenance include:

  • Safely eject the flash drive before unplugging it to avoid corruption
  • Keep backups of important files on the flash drive
  • Run error-checking tools like CHKDSK periodically to catch issues early
  • Avoid exposing flash drives to liquids, heat, or physical damage to prolong their lifespan

Following these Diskpart steps and maintenance tips should help recover unusable flash drives and keep them working properly.