Format a USB memory stick or camera memory card

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 ...

a iadtftiailMliiaaaiii -

File Edit View Jerrriin'al Tabs Help [email protected]:~i mount

/dev/sda5 on / type ext3 [rwp relatimeperr~or5=remount-ro)

proc on /proc type proc (™pnoexecpnosuidpnodev)

/sys on /sys type sysfs (™pnoexecpnosuidpnodei<)

varrun on /var/run type tmpfs (rwpnoexetpnosuidpnodevpmode-0755)

varlock on /var/tock type tmpfs (rwpnoexecpnosuidpnodevpmode=1777)

udev on /dev type tmpfs (rwpmode=0755)

devshm on /dev/shm type tmpfs (rw)

devpts on /dev/pts type devpts [ rvpgid-5pmode-620)

lrm on /lib/modules/2.6.24-19-generic/volatite type tmpfs (rv)

securityfs on /sys/kernel/security type securityfs (rw)

gvfs-fuse-daemon on /horoe/keir/.gvfs type fuse.gvfs-fuse-daemon (rwpnosuidpnodei<i_ ,user=keir)

/dev/scd0 on /media/cdrorai0 type iso9660 (ropnosuidpnodevputf8puser=keir) /dev/sdal on /media/disk type fuseblk (rvpnosuidpnodevpnoatimepallow otherpblksi ze=4096)

/dev/sdbl on /media/KINGSTON type vfat (rwpnosuidpnodevpuhelper=halpshortname=mi ixed, uid=1000, utf 8, uinask=077, f tush) keirtakeir-desktop:-? |

Figure 3.12: Finding out how a USB stick is referred to on a technical level (see Tip 44, on the preceding page)

So I made a note of /dev/sdbl. See Figure 3.12 for an example from my test PC with the relevant line highlighted. 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, as shown in Figure 3.13, on the next page. 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 Q to delete the partition. Then, regardless of whether you saw an error message or not, hit 0 to create a new partition and hit [Enter] twice to accept

¡31 i^l/^alz-daaliiup;'-

lie Edit View Terminal Tabs |_elp

cfdisk [util-linux-ng 2.13.1)

Disk Drive: /dev/sdb Size: 2063597568 bytes, 2063 MB Heads: 64 Sectors per Track: 62 Cylinders: 1015

Name Flags Part Type FS Type [Label]

Size (MB)

MS) IJilnkU'i HI ffiiEtl

rlMMV

mmmra) [ ilelete 1 r Heln 1 rMaximi/e] F Print 1 [ Quit ] [ Type ] [ Units ] [ Write 1

Toggle bootable flag of the current partition

Figure 3.13: Repartitioning the USB memory stick using cfdisk (see Tip 44, on page 104)

the default suggestions of partition type and size. Then hit Q, hit [Enter], and type 0C (that's zero then C) to set the new partition type. Finally, hit (W (that's [Shi ft] plus [w]), type yes and, once the partition table has finished being written to disk, type @ 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:

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.

To learn how to do cool things with USB memory sticks, see Tip 31, on page 88; Tip 113, on page 162; Tip 145, on page 188; Tip 229, on page 270; Tip 305, on page 355; and Tip 309, on page 361.

Was this article helpful?

0 0

Post a comment