Solved

Zero out flash memory

Posted on 2007-12-05
10
2,224 Views
Last Modified: 2013-11-14
I work with embedded systems.  Normally, when I need to wipe a hard drive clean, I use the Linux badblocks command to zero out the drive.  badblocks -svw -b 512 -t 0x00 /dev/<device> does the trick by doing a destructive bad sector test using zeroes as the test pattern.  I find that method to be faster than dd if=/dev/zero of=/dev/<device> bs=512, plus you get a progress indicator.

However, this method does not work on flash type media.  I have tried USB sticks and most recently, SD cards.  I wind up getting I/O errors about 3/4 of the way through, and the end of the card (as viewed in a hex editor) is not zeroed out at all (although the beginning is).  This happens with different media from different brands.  The failure is not always in the same spot, but they all fail.

SanDisk media in particular reacts very badly to this procedure.  Once you get the I/O errors, it is simply a matter of making a filesystem on it to use it again in Linux.  However, no Windows machine is ever able to work with the device ever again (not that I care that much about Windows, but it's odd).

Anwyay, my questions is this:  Is there some kind of booger in the way the Linux kernel is working, or can you not do block level operations on flash media like that?

How would you do a low-level zero of all the data on a flash card?
0
Comment
Question by:cuziyq
  • 4
  • 4
10 Comments
 
LVL 88

Expert Comment

by:rindi
ID: 20412471
What happens if you format it to fat32 within Linux?
0
 
LVL 14

Author Comment

by:cuziyq
ID: 20412934
For SanDisk media specifically, Linux will read the device just fine.  However, even with a FAT16 or FAT32 format, Windows cannot use it after it's been through the Linux badblocks scan.  Different types of media exhibit different behavior.  For example, with a 4GB SD card, Windows sees the device and even gives it a drive letter.  But trying to open it or get properties on it hangs Explorer to the point where Task Manager won't even kill it.  If I plug it into a SD-IDE adapter, Windows recognizes it as a fixed disk, but does not see that it is formatted.  When you try to format it with Disk Administrator, it grinds on it for about 30 seconds and then gives a very generic device error.

With a 2GB USB flash drive, Windows detects the stick in the port and knows what it is, but claims that it can't load the driver for it.  In both situations, Linux sees and uses the thing just fine.

So FYI, don't ever do a dd or badblocks command on SanDisk flash media if you ever want to use it in Windows ;-)

Anyway, I don't really care if it works in Windows or not.  I just don't understand why I can't do a wipe the same way I would with a hard drive.
0
 
LVL 88

Expert Comment

by:rindi
ID: 20413002
And if you del all partitions, can you format it within windoze then?
0
 
LVL 14

Author Comment

by:cuziyq
ID: 20413613
Not with SanDisk.  I have tried it with Kingston, Patriot, and A-Data flash memory.  They all work fine.  But once a SanDisk has been run through the wringers like that, Windows will never be able to work with it no matter what I've tried.
0
Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

 
LVL 88

Expert Comment

by:rindi
ID: 20413690
Strange.
0
 
LVL 14

Accepted Solution

by:
cuziyq earned 0 total points
ID: 20788109
I've found the answer.  Flash memory cells have a finite number of write cycles before the cell becomes "worn out" and unusable.  Flash devices have a non-addressable "slack" region that the controller uses to dynamically reallocate blocks so that wear is leveled out across the entire memory space, thus increasing its lifespan.

The oddity here is that Linux can see this slack space and thinks it is an addressable region when in fact it is not.  When it tries to write to that area, the flash controller barfs and now you have a bad low level format (which confuses Windows, but not Linux).

The answer, in case anyone is wondering, is to use a tool like WinHex, which can get raw access to physical devices in Windows, and zero it out that way.  Since Windows can't see that slack area, writing zeroes to the space that is addressable causes the flash controller to do its wear-leveling thing and properly deallocate the slack area, making the low-level format valid again.

I can't say if this is universal behavior, but it worked on the two SD cards I've tried it on.  It effectively revived otherwise dead cards.
0
 
LVL 14

Author Comment

by:cuziyq
ID: 20788174
Also FYI, in case anyone is interested . . . ALL flash memory devices employ a wear-leveling algorithm like this (with the exception if cheap Chinese counterfeits from eBay, which explains why their quality is so poor).  Therefore, it is physically impossible to securely wipe a flash memory device.  If it had sensitive information you wish to get rid of, the only option is to destroy the card.
0
 
LVL 88

Expert Comment

by:rindi
ID: 20794608
Don't delete, PAQ it. The asker provided useful info about flash memory and answered it himself.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20854150
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Setting up Two Three NICs with One on a Different Subnet 22 57
Server 2008 R2 Datacenter Repair OS 20 42
AD LDAP LDS 3 47
Set Warning Thresholds on Database mirroring 4 34
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Fine Tune your automatic Updates for Ubuntu / Debian
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now