Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My friend was having problems with a USB flash drive, and I suggested he do a low-level format. Then it occurred to me that I don't even know how to do that in Linux. So... how can I low-level format flash memory in Linux?

Edit: I probably should have specified in the first place that my friend tried a "full format" on the drive in Windows and it failed.

share|improve this question
add comment

5 Answers

up vote 7 down vote accepted

"Low level formatting" was done on floppies, where you could write at different densities by choosing to organize the tracks and sectors differently. But this makes no sense for most modern media. Its notion of how to organize the data on the device is fixed and unchangeable. It doesn't make any sense at all for flash, which has discrete bits, rather than magnetic domains. Higher level formatting is possible, which is mkfs in unix-land.

share|improve this answer
    
So if the filesystem on my friend's flash drive is messed up, mkfs is his only option? What if that doesn't work? There's nothing else he can try? –  bmaupin Jan 31 '12 at 17:40
    
@Bryan: well, he could also try fsck, the equivalent of dos's chkdsk. –  wnoise Jan 31 '12 at 20:18
1  
@wnoise if mkfs fails, fsck isn't going to help. –  derobert Dec 11 '12 at 17:59
add comment

Low-level formatting means many different things to different people and different contexts.

The original meaning was a step needed in the formatting of disks - disk drives need header, sync and other patterns written on the media before it can store data to it. In this way the head can detect when it is A) on a track and B) where it is on the track. Low-level formatting a floppy prepares the disk to be able to read and write blocks. Early MFM and RLL PC hard drives could be low-level formatted, often using a utility built into the hard drive controller's (an ISA card) ROM. Modern IDE and SATA hard drives are low-level formatted too, but only at the factory.

Various other meanings include writing zeros to all blocks, configuring the drive to disable "hidden" areas such as HPA and DCO and then zeroing all blocks, or other things more related to partitioning than formatting.

Raw flash needs a different initial preparatory step at the factory - each flash "eraseblock" (analogus to a "block" on disks) needs to be tested and marked as bad if it is indeed bad. Each "eraseblock" has an additional small "OOB" block that holds error correcting information - and this is where it is marked as bad. You do NOT want to repeat this step as the act of writing to a bad block could prevent you from setting that particular bit again that identifies it as bad.

But you are not dealing with raw flash. You are dealing with a USB flash drive. There is a controller chip in all flash drives that accepts USB commands from the host and talks to the raw flash inside on the host's behalf. Some of these controller chips can be configured to report part of the flash as a separate CD-ROM partition, or act like two separate USB storage devices. Depending on the make and model of the controller chip, you may be able to find a recovery or configuration utility (likely Windows only) that could reset this controller chip. You would begin by opening the flash drive, looking for the smaller of (likely) two chips that are on the small PCB, and doing some Googling. The make and model printed on the outside of the case is not likely to help you find who made the controller inside of it.

share|improve this answer
add comment

There is no way to do a low-level format on most flash devices, since they have an additional translation layer from USB/ATA/SD/etc. to MTD which obscures the low-level MTD devices (which can be low-level formatted if gotten to directly [which you can't]).

share|improve this answer
add comment

mkfs.vfat /dev/hda1 will do the equivalent of the MSDOS "format" command.

share|improve this answer
add comment

use dd command for this dd if=/dev/zero of=/dev/hda

This will destroy ALL data on the hard drive, all boot sector info and all data on all partitions. It will not however render the disk useless, you simply have a clean disk that only needs to have partitions created and a new boot sector installed, which will happen when you install any OS including Linux or Windows. This is a good way to clean up any bad partitions, viruses, botched installs or data that you don't want to be seen.

share|improve this answer
4  
You do not want to use /dev/zero to erase a flash memory device. See the entry on my blog: fakkelbrigade.eu/chris/blog/2012/01/… –  Chris Down Jan 27 '12 at 19:46
    
On top of that, recreating the partitions and filesystem on a completely blank flash device will usually leave it misaligned, causing it to behave slower or wear faster than before. –  Ignacio Vazquez-Abrams Jan 28 '12 at 0:51
1  
It's not extraordinarily wrong to write /dev/zero to a flash device. The only advantage that writing 1s to the device gives is that you might get slightly faster write times the next time you write to the disk since it doesn't have to be erased first - and that depends on the flash translation layer being smart. –  Shawn J. Goff Jan 28 '12 at 1:22
2  
@ChrisDown, Not sure how it compares in performance, but you could use badblocks -s -w -t 0xff /dev/?d??. You get all 1's written, and tested too. –  Zoredache Jan 28 '12 at 1:36
    
@ChrisDown your blog entry has gone 404-compliant. –  derobert Dec 11 '12 at 18:01
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.