Solved

Zero out flash memory

Posted on 2007-12-05
10
2,231 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NetApp space reclaim 3 31
SSD mSata 250GB 37 72
Synology and UPS monitoring 2 22
Migrating a Linux server to VMware 3 51
Concerto Cloud Services, a provider of fully managed private, public and hybrid cloud solutions, announced today it was named to the 20 Coolest Cloud Infrastructure Vendors Of The 2017 Cloud  (http://www.concertocloud.com/about/in-the-news/2017/02/0…
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
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 video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…

809 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