Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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? My friend tried a "full format" on the drive in Windows and it failed.

share|improve this question
up vote 11 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
@wnoise if mkfs fails, fsck isn't going to help. – derobert Dec 11 '12 at 17:59

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
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
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
@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
If the flash internally erases to all ones, then the translation layer should be inverting the bits since it is customary to format disks with all zeroes. – psusi Dec 12 '12 at 1:56

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

Low-level formatting means many different things to different people and on 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

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

share|improve this answer

I've come across devices in the past (although not for a while) which implement the SCSI FORMAT UNIT command - from Linux you can use:

sg_format --format /dev/sdX

to reset these devices to a factory state (USB storage spec is derived from the older SCSI standards).

I believe some newer USB 3 devices also implement ATA security commands, so you could use https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase which is likely to have the effect of resetting the flash translation layer to its factory state (as it typically does with SSDs).

share|improve this answer

Your Answer


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.