blog.dotkam.com stats

AddThis Social Bookmark Button

Restore/Format USB Flash Drive

Who does not have a flash memory USB drive? (128Mb - 16Gb…) Everybody does, even my dog, if I had one, would have it. However, sometimes these little dongles can be tricky to use if they are not properly formatted. The usual format for the flash memory USB drive is FAT16, and it is understood by many operating systems with no problem. But in case the drive is not formatted properly/or you think it is not formatted properly, you can always reformat it, and here is how.

The whole process consists of 5 steps ans takes about 15 seconds um.. if do it slowly.. :)

WARNING: All the data will be lost from the flash UBS drive since we are going to reformat it.

We are going to use fdisk utility, so “for starters” here are available commands that you can use with fdisk:

a - toggle a bootable flag
b - edit bsd disklabel
c - toggle the dos compatibility flag
d - delete a partition
l - list known partition types
m - print this menu
n - add a new partition
o - create a new empty DOS partition table
p - print the partition table
q - quit without saving changes
s - create a new empty Sun disklabel
t - change a partition’s system id
u - change display/entry units
v - verify the partition table
w - write table to disk and exit
x - extra functionality (experts only)

Now let’s get to cooking a new and fresh flash memory USB drive…

Step 1. Run fdisk via sudo on your USB flash drive device:

user@host:~$ sudo fdisk /dev/sdb

enter “p” command to list current partition table of the USB drive:

Command (m for help): p  
 
Disk /dev/sdb: 1039 MB, 1039663104 bytes 
32 heads, 62 sectors/track, 1023 cylinders 
Units = cylinders of 1984 * 512 = 1015808 bytes 
Disk identifier: 0xf1f494df  
 
Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1        1023     1014785   83  Linux

Here you will see whatever partition (if any) currently present. In my case (above) it is a “Linux” partition, in your case it may be something different. But it does not really matter, because we are going to delete it anyway:

Step 2. Enter “d” command to delete existing partition (if you have any). If you have several, delete several by using”d” command multiple times:

Command (m for help): d 
Selected partition 1

Step 3. Now let’s get to business and enter “n” command to create a new partition:

Command (m for help): n 
Command action 
e   extended 
p   primary partition (1-4) 
p 
Partition number (1-4): 1 
First cylinder (1-1023, default 1): 
Using default value 1 
Last cylinder or +size or +sizeM or +sizeK (1-1023, default 1023): 
Using default value 1023

As you can see from above, I entered “1” for “Partition number”, and hit enter key twice to leave everything by default.

Now let us list current partitions with “p” command again:

Command (m for help): p  
 
Disk /dev/sdb: 1039 MB, 1039663104 bytes 
32 heads, 62 sectors/track, 1023 cylinders 
Units = cylinders of 1984 * 512 = 1015808 bytes 
Disk identifier: 0xf1f494df  
 
Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1        1023     1014785   83  Linux

We have a single “Linux” partition which is fine (for now).

Step 4. Time to actually apply our changes, so enter a “w” command that will write out all the changes to the USB drive.

Command (m for help): w 
The partition table has been altered!  
 
Calling ioctl() to re-read partition table. 
Syncing disks.

fdisk will write all the changes to the USB drive and exit. But we are not done yet. Our goal is to make a (in this case) FAT16 partition, so this USB drive can be read by most operating systems.

Step 5. For that we will use mkfs.vfat utility:

user@host:~$ sudo mkfs.vfat -F 16 /dev/sdb1 
mkfs.vfat 2.11 (12 Mar 2005)

Now we are good to go! It was easy, as I promised :)

Let’s look at the new USB drive now. Mounting it first:

user@host:~$ sudo mount /dev/sdb1 /mnt/flashka/ 
user@host:~$ cd /mnt/flashka/ 
user@host:/mnt/flashka$ ls -l 
total 0

Checking what it has under the hood:

user@host:/mnt/flashka$ df -h 
Filesystem            Size  Used Avail Use% Mounted on 
/dev/sdb1             991M     0  991M   0% /mnt/flashka  
 
user@host:/mnt/flashka$

It has 991Mb which is what they call 1Gb flash memory USB drive! :)


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

8 Responses to “Restore/Format USB Flash Drive”

  1. Karl Bunous Says:

    Excellent way to restore any USB drive! I just went through all the steps with my old 128Mb flash that I could not use before, and it worked! Woohoo - thank you!

  2. Great tutorial..This is very nice website.

    Bookmarking it.

    Thanks !!

  3. thanks for tuto
    im having a problem here
    sudo mkfs.vfat -F 16 /dev/sdb1

    mkfs.vfat 2.11 (12 Mar 2005)
    /dev/sdb1: No such file or directory

    i try
    sudo mkfs.vfat -F 16 /dev/sdb
    but it show

    mkfs.vfat 2.11 (12 Mar 2005)
    mkfs.vfat: Will not try to make filesystem on full-disk device ‘/dev/sdb’ (use -I if wanted)

  4. You can also try using GParted if you don’t like using the command line.

  5. i have use GParted
    but its show “Error while setting new disklabel” hen i try to create partition “msdos”

  6. HideYourTracks.org,

    It seems like you did not complete steps before “sudo mkfs.vfat -F 16 /dev/sdb”, which is the last step in the tutorial above (btw - nice tutorial :) ).

    I did not have any problems with my 2Gb ScanDisk Thumb Drive.

    Thanks,

    J

  7. […] - bookmarked by 3 members originally found by valtoni on 2008-09-18 Restore/Format USB Flash Drive http://blog.dotkam.com/2008/07/10/restoreformat-usb-flash-drive/ - bookmarked by 2 members […]

  8. […] I ended up cancelling the writing in the middle. Gah~! But the blog dotkam saved me by teaching me how to restore the format of a USB flash drive. I haven’t formatted anything in Linux in ages so this gave me a crash course on using the […]

tell me something...
  1. (required)
  2. (valid email required)
  3. Captcha
  4. (required)