I have a usb thumb drive that I want to reuse.
How can I format it?
I have a usb thumb drive that I want to reuse.
How can I format it?
There are lots of different ways to do this.
You don't necessarily need to ‘format’ (i.e. make a filesystem — you can't format USB sticks in the corrects sense of the word) the stick if you just want to delete all files.
Assuming the stick is mounted under /media/something
, you can say:
sudo rm -rf /media/something/*
You will not be asked to confirm! This won't touch hidden files (recycling bin folders from Windows or Mac, etc).
If you want a pristine filesystem, make sure the filesystem is unmounted first:
sudo umount /dev/whatever_the_device_is
sudo mkfs.vfat -n "Volume Label" /dev/whatever_the_device_is
This will make a FAT filesystem. If you need an NTFS filesystem, there's always mkfs.ntfs
, but you should be aware that some implementations are buggy. It depends on your distribution and how recent it is.
Fire up the KDE Partition Manager (if you don't have it, the Debian/Ubuntu package name is a slightly non-standard partitionmanager
). Do the obvious thing.
Use the Gnome Disk Utility (Palimpsest). It's quite trivial to use: just select your USB drive from the left. If it has a partition already, click the ‘Format’ button. Otherwise, there's a ‘Format Drive’ button which'll do everything for you.
Ask Ubuntu has this exact question already answered: How to format USB or external drive in 11.10? — note how this just walks you through using the Palimpsest Disk Utility.
My own favourite GUI tool for this job is GParted. It does everything you need (except, sadly, LVM and encryption) and it's user friendly to boot.
Have a look at the mkfs
family of utilities (depending on what you want to format to, you may want mkfs.ext[234]
, mkfs.vfat
, or something else entirely). Bear in mind that you may also have to change the partition type identifier in the partition table using fdisk
or similar to make it work across systems.
To (re)create a filesystem, use one of the mkfs family of tools. Choose the one based on what filesystem you want; the most common ones are:
mkfs.vfat
) for maximum compatibility. FAT32 has no notion of file ownership or permissions or symbolic links or many other unixy concepts, just files and directories with many punctuation characters forbidden in file names, and no case sensitivity. The maximum file size is 4GB. Choose this filesystem if you just need to store a bunch of files that aren't larger than 4GB.You'll need to find out the name of the device that the drive is plugged into. Under Linux, removable drives usually have names like /dev/sda
, /dev/sdb
, etc. Be sure to pick the right one, or you might erase your hard disk. Under Linux, you can get a list of available drives and their partitions by running cat /proc/partitions
; the number in the third column is the size in kilobytes.
You can also get an idea of where a drive is plugged in by looking at names in /dev/disk/by-path
, and drive models in /dev/disk/by-id
. Thumb drives normally have a single partition numbered 1.
On many systems, these tools live in /sbin
or /usr/sbin
, which is not in the default path for non-root users. Furthermore, you're likely to need to be root to run them.
To create a new filesystem, run the mkfs
command on the right device:
mkfs.TYPE /dev/NAME_OF_DEVICE
Remember to put the right partition number. If you're running Linux and you have a single hard drive and no other connected external drive, the device is usually /dev/sdb1
. Thus, the typical command is
sudo mkfs.vfat /dev/sdb1 # be sure to adjust the device name if necessary
mkfs
will leave some fragments of old data in place, that will not be erased until they're overwritten by a new file. These fragments can be recovered by looking at the device content, bypassing the filesystem. (There's no guarantee that it will be easy to reconstruct meaningful data from the fragments, so don't hope to use this as an undo for oops-I-formatted-the-wrong-device.) If you want to erase all existing data, run the following command before mkfs
:
tee </dev/zero /dev/NAME_OF_DEVICE
Make very very sure that you pick the right device name, as this will erase all data with no hope of recovery.
Note that while this will erase the data with no possibility of recovery by ordinary software means, it may leave traces behind that can be recovered with some electronic work. See Is it enough to only wipe a flash drive once?. The only paranoia-compliant way of erasing data on a flash drive is to have encrypted it in the first place, and destroy all copies of the key.