Solved

Zero out flash memory

Posted on 2007-12-05
10
2,221 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 87

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 87

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 87

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 87

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

9 Experts available now in Live!

Get 1:1 Help Now