How to Format a USB memory stick (or camera memory card) in Ubuntu

Sometimes if a USB memory stick or memory card stops working correctly, the best plan is to reformat it. To do this under Ubuntu, follow the steps below. Note that the instructions are extremely thorough - first the partition on the memory stick is deleted, then a new one is created and subsequently formatted. This should return virtually any USB stick to life, provided it isn't suffering from a hardware failure:

1. With the memory stick/card inserted, so its icon appears on the desktop, look for what it's called (its label) and make a note.

2. Now you must find how Ubuntu refers to it on a technical level so you can use the information later when formatting. Open a terminal window and type mount. Look through the list of results
for the label you noted, and then make a note of the beginning of the line, which will begin /dev. For example, on my test system, the beginning of the line read:

/dev/sdb1 on /media/KINGSTON type vfat (rw.nosuid,nodev ...

So I made a note of /dev/sdb1. What you discover may be different from my test PC because this identifier depends on how many hard disks and other removable storage devices that you have attached to your computer.

3. Right-click the desktop icon for the memory stick and select Unmount Volume.

4. Back in the terminal window, type the following:

$ sudo cfdisk /dev/sdb

You should replace /dev/sdb with what you discovered earlier - note that you will need to drop the number from the end. You should now see a listing showing the partition on the USB stick. If you see an error message instead, hit any key to quit cfdisk and try the following:

$ sudo cfdisk -z /dev/sdb

5. If you didn't see an error message, hit d to delete the partition. Then, regardless of whether you saw an error message or not, hit n to create a new partition and hit Enter twice to accept the default suggestions of partition type and size. Then hit t, hit Enter, and type 0C (that's zero then C) to set the new partition type. Finally, hit W (that's Shift plus w ), type yes and, once the partition table has finished being written to disk, type q to quit cfdisk (don't worry about the error messaging saying that no primary partitions are marked bootable - this is irrelevant in this case).

6. If, at this stage, the USB stick's icon suddenly reappears on the desktop, right-click it and once again select Unmount volume (close the file browsing window first, if one has appeared). Then type the following into the terminal window to format the new partition:

$ sudo mkfs.vfat -F 32 -n USBSTICK -I /dev/sdb1

You should replace USBSTICK with the label you want to apply to the device, and /dev/sdb1 with the hardware identification you discovered earlier. Once the format has completed the USB memory stick should automatically mount on the desktop. If not, remove it and then reinsert it.





Tags: format,partition,usb,memory stick,cfdisk

Related Articles