Three till Seven

19 Apr 07how to reformat your pen drive

Note: If you enjoy this article, you might also check out the Geeky Stuff section.

USB pen drives are everywhere these days, and for good reason, since they’re dead useful. I use mine with my Linux box, my Powerbook, and various other systems I’ve had cause to stick it in. After a while, my 1 GB drive was only holding a few hundred MB. When I would do an ls -a on it, I would see several hidden directories, such as .Trashes and .Trash-sarah. Trying to sudo rm -rf .Trash* would fail out, however, giving complaints of a read-only filesystem. If you’re having such problems, or just really want to make sure your drive is clean, you can reformat it easily in Linux. I reformatted mine using Ubuntu, so the instructions have a slight bias; your mileage may vary. Warning: reformatting your pen drive will delete all its contents.

  1. Insert your USB drive and let it do its automount thing.
  2. In a terminal, do sudo fdisk -l to list your partitions. A list of your partitions will spit out, and your pen drive will probably be in a section like this:
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1         992      999813+   6  FAT16

    Your pen drive will not necessarily be located at /dev/sda1; if it isn’t, you’ll need to adjust later instructions to point to its location. Be sure you’re working with the right device, because if you use fdisk to delete partitions on, say, your main hard drive, you will delete your hard drive’s contents.

  3. Do sudo umount /dev/sda1 (or whatever the location of your pen drive is) to unmount your pen drive so that you can work with its partitions.
  4. Do sudo fdisk /dev/sda1 to use fdisk to adjust your pen drive’s partitions.
  5. You’ll now be within fdisk. When my drive was scrambled, I was able to type p to show the existing partition and d to delete it. Running through this tutorial to make sure it made sense, I had to type p to show the partition table, a to make a partition active, 1 to choose the first partition, and d to delete it. If your situation is like mine, you’ll be asked to choose between several partitions; start from 1 and work through them all. Fdisk complained about the partition not starting in the right spot until I got all the pen drive’s partitions deleted.
  6. Type n to create a new partition.
  7. Choose p to make it a primary partition.
  8. Type 1 to make this the first partition.
  9. Hit enter to choose the suggested first cylinder.
  10. Hit enter to choose the suggested last cylinder. This will make the partition take up the maximum space on your pen drive.
  11. Type a to make this partition active.
  12. Choose 1 to select making the first partition active.
  13. Type t to change this partition’s file system type.
  14. Type 6 to choose the FAT16 file system.
  15. Type w to write this new partition table.
  16. You will be dumped back out to your terminal. Type sudo mkfs.vfat -F 16 -n USB /dev/sda1 to format the first partition.

You can now remove and reinsert your USB drive because you’re done! Try going to its mount location (/media/usbdisk on my machine) and doing ls -la. You should see something like the following:

total 8
drwxr-xr-x 2 root root 4096 2007-04-18 18:18 .
drwxr-xr-x 6 root root 4096 2007-04-19 08:45 ..
-rw------- 1 root root    0 2007-04-18 18:18 .created_by_pmount

Other than that, your pen drive should be empty and ready for use. :) Thanks to Pendrivelinux.com for helping me reformat my drive initially through a tutorial for how to install Ubuntu on your pen drive.

a busy day, filled with Perlnanigans »« my birthday

10 Comments / Add your own »

  • Oh, I’ve been wondering how to get rid of those hidden .Trash directories that Ubuntu likes to stick on my USB stick (I’ve never heard them called pen drives!). I always just booted into Windows and deleted all of the trash files, but now that I don’t have to go throough the hassle of Windows, that’s nice.

  • You can configure Nautilus not to create the .Trash folder - see http://ubuntu.wordpress.com/2006/09/13/no-trash-on-external-usb-drives/

  • Awesome Steve, thanks! Now I can avoid future reformats.

  • so why do you delete/recreate partition before formating? surely a simple mkfs.vfat… would do?

  • Well you can also use gparted

    sudo apt-get install gparted

    gparted

    that’s it

  • hi
    im looking for mp4 player, its actull size showing 1.98 that mean 2gb but its formated to 475mb i want to remove this partition and make the partition to 1gb if possible tell me doing in windows, i try the things u mentioned steps ..

  • its partitoned to 475mb i want to delete this and extend its partition, 2gb mp4 player supports amv formate video file player..mp3,fm,pic book,games etc.if get solution plz mail me to dvinod.eluru@gmail.com

  • This is exactly what I have found. Could you tell me how I reformat a stick when I use a mac OS X?

    Many thanks

  • You should be able to use the same technique as above, because when I do which fdisk on my Powerbook, it tells me /usr/sbin/fdisk, so fdisk is available on OS X.

  • Excellent step by step instrutions. Worked great for me. Thank you!

Add a Comment

required
will not be published; required

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comments RSS feed / TrackBack URI