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.</li></ol>

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.