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:
- Open an elevated command prompt.
- Run diskpart
diskpart
- 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>
- select disk X where X is the number from step 4
select disk 1
- List Partitions
list partition
There could be multiple partitions
- Select the partition
select partition 0
- Delete the partition
delete partition
- Select the partition
select partition 1
- Delete the partition
delete partition
- Create a primary partition – IMPORTANT
create partition primary
- 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 onlist volume
- Exit DiskPart
exit
- 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