Windows CMD – Disk Partition and Format with DiskPart

| |

NOTE: This is not put in code as it can be VERY difficult reverse the process below. ONLY do this if you have a clue of what you are doing .

This process has been tested on a USB Hard Drive, Thumb Drive, and Physical (Internal to computer) Hard Drive

Partition Modification:

  1. Open an elevated command prompt.
  2. Run diskpart
    diskpart
    
  3. List Disks
    list disk

    Note the disk number that corresponds to your USB drive (it should be obvious going by size)

    Example:

    DISKPART> list disk
    
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online          160 GB      0 B        *
      Disk 1    Online           28 GB      0 B
    
    DISKPART>
    
  4. select disk X where X is the number from step 4
    select disk 1
    
  5. List Partitions
    list partition
    

    There could be multiple partitions

  6. Select the partition
    select partition 0
  7. Delete the partition
    delete partition
  8. Select the partition
    select partition 1
  9. Delete the partition
    delete partition
  10. Create a primary partition – IMPORTANT
    create partition primary
  11. List volumes – IMPORTANT for next step as this will list the drive letters.
    You should notice that your drive is labeled as “RAW” in the “Fs” column this is the drive letter for the disk we just worked on
    list volume
  12. Exit DiskPart
    exit
  13. Format Disk – depending on your preferred type use ONE of the commands below.
    NOTE: In the example code g: is the drive letter for the drive we just worked with.
    format g: /q /c /FS:FAT32 /v:32GB
    format g: /q /c /FS:NTFS /v:32GB

    Securely Format, the 7 can be set at any number

    format g: /p:7 /x /c /FS:FAT32 /v:32GB
    format g: /p:7 /x /c /FS:NTFS /v:32GB

Exit Command Prompt (type exit or just close the window)

Referenced From: http://superuser.com/questions/536813/how-to-delete-a-partition-on-a-usb-drive

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.