Solved

Zero out flash memory

Posted on 2007-12-05
10
2,233 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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
 
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
We look at whether swapping a controller board on a failed hard drive is likely to solve the problem.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

685 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