Best way to format your USB Flash Drive in Linux CLI


Best way to format your USB Flash Drive in Linux CLI:
(especially when gparted, or even fdisk, cfdisk give you problems):

1. Insert your usb memory pen / stick or whatever into the USB drive and immediately after that, open a terminal and input:

$ dmesg | tail

You should get an output of something like this:


[76384.491365] sd 6:0:0:0: [sdb] Write Protect is off
[76384.491369] sd 6:0:0:0: [sdb] Mode Sense: 23 00 00 00
[76384.491865] sd 6:0:0:0: [sdb] No Caching mode page present
[76384.491870] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[76384.494235] sd 6:0:0:0: [sdb] No Caching mode page present
[76384.494241] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[76384.494745]  sdb:
[76384.496734] sd 6:0:0:0: [sdb] No Caching mode page present
[76384.496738] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[76384.496742] sd 6:0:0:0: [sdb] Attached SCSI removable disk

2. Unmount your USB drive using the following command:
$ sudo umount /dev/sdb

Where "sdb" is your media drive you had to remember at step 1.

3. Format the drive using the following commands, depending on which filesystem you want I list ext3, ext4 or FAT32:

A1.) Format to FAT32
$ sudo mkfs.vfat /dev/sdb

/or

B.) Format to EXT3:
$ sudo mkfs.ext3 -n 'Label' -I /dev/sdb

/or

C.) Format to EXT4:
$ sudo mkfs.ext4 -n 'Label' -I /dev/sdb


C2.) Force Format to EXT4 if for some reason the first doesnt work nor the gparted or other partition applications don't work:

$ sudo mkfs -t ext4 /dev/sdb


/or

A2.) Alternatively you can create a FAT32 filesystem with the:
$ sudo mkdosfs -n 'Label' -I -F 32 /dev/sdb


*NOTES:

- Where Label will be the name displayed for the USB media so you can set it to whatever you want; and sd(x) is your usb drive you had to remember at step 1, in this case its sdb for my example
- Sometime you need to blow away or purge the contents of a drive before you can properly format it:

$ sudo dd if="/dev/null" of="/dev/sdb" 

/or

$ sudo dd if="/dev/zero" of="/dev/sdb"

2 comments:

Ye Olde Dood said...

So far, so good. One problem, maybe you have a tip?

The device is a Sandisk Cruzer 16Gig Flash drive.

I have written to it with unetbootin, and tried several other methods to use it a bootable install medium and/or a bootable live distro drive. Time passes, I gave up on those, and eventually I wanted it back as a storage device once more.

No matter what I've tried, it now takes forever to get seen in the Device Notifier of KDE (Kubuntu 12.10).

I have fsck'd it, reformatted it as ext2, then ext3, then NTFS, then FAT32, I have tried cfdisk -z, fdisk, parted, and a few others. nothing makes this ONE flash drive mount like all my other flash media - shows in device notifier in less than a second for other flash media in my system, this ONE flash drive takes 45 seconds or more, and often never shows. When device notifier sees it, it usually works fine, but the wait is dreadful. I've even deleted all the partitions (many times) and tried using the drive as a whole device (mkdosfs -I -F 32 /dev/sdf) and it still suffers delays.

Current iteration of format efforts has it displaying exactly one time for each login, then, if I disconnect from it, it will not show again until I restart X (and thus restart KDE).

dmesg | tail shows the device was seen by the system in a fraction of a second, so I wonder if there is a string coming from the bowels of this device which tosses KDE for a loop.

Any ideas for deeper remediation?

Ye Olde Dood said...

KDE Device notifier was hosed. A newly installed KDE installed with a newer distro needed merely a second to display the flash drive. I guess that the device itself contains a serial number string which never changes across formats; that string could persist in a corrupted device notifier index, where the remaining data in that record associated to the immutable device string would contain corrupted information.

Post a Comment