Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 08-30-2009, 06:02 PM   #1
Registered: Jul 2004
Location: Milpitas, California
Distribution: 1/2 Debian 1/2 my own
Posts: 189

Rep: Reputation: 30
32Gb SDHC with bad sectors

I recently bought a generic 32Gb card on
Ebay and got what I paid for - a bunch of bad sectors which makes my recorded videos unplayable when it reaches a bad frame.

The actual fraction of bad blocks is pretty low ~ 0.001, but I can't get format to recognize them as bad. I tried using the badblocks program to detect them:

badblocks -b 512 -v -w /dev/mmcblk0p1 4296000 4096000
Checking for bad blocks in read-write mode
From block 4096000 to 4296000
Testing with pattern 0xaa: done
Reading and comparing: 4169376

After running the test twice on the same range of 200k 512byte blocks, I get about ~167 bad blocks, but the problem is that the block #s are different due to wear leveling, so I don't think the blocks can be marked bad at the file system level. The persistent # bad blocks suggests the card doesn't remap bad blocks, which would be a real bummer.

Is there anything I can do about them, or am I out of luck? Namely, does anyone know the details of wear leveling, so I can mark all logical sectors that can map to a bad physical block as bad?

Last edited by bobwall; 08-30-2009 at 06:15 PM.
Old 08-31-2009, 11:39 AM   #2
Registered: Mar 2007
Posts: 239

Rep: Reputation: 34
Wear levelling is new to me.

For normal hard disks, I usually create a partition comprising the bad sectors, and use the rest.

If the camera can manage multiple partitions, try creating a hidden partition containing the bad sectors.
Old 08-31-2009, 12:04 PM   #3
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
"Wear levelling" is probably handled differently by different chip manufacturers, and they are unlikely to publish or share their methods, as this would be sensitive commercial information.

Also, levelling is hidden from the hardware interface - the device itself re-maps blocks somehow, and I don't even know if it does this with hard, firm- or software. Without an electron microscope and an unreasonable amount of work, I am not going to be able to know.

So, I think your device is basically broken. Sorry for the bad news.
Old 09-01-2009, 03:12 AM   #4
LQ Newbie
Registered: Jul 2009
Location: Blm. IL. USA
Distribution: slackware
Posts: 13

Rep: Reputation: 0
Maybe you could try to reformat the card using the option to check for and mark bad sectors.
Old 09-01-2009, 03:32 AM   #5
Registered: Jul 2004
Location: Milpitas, California
Distribution: 1/2 Debian 1/2 my own
Posts: 189

Original Poster
Rep: Reputation: 30
Surprisingly, the 1st 2Gb of space has virtually no bad sectors. Maybe this "quality control" helps unsuspecting customers from noticing corrupt images and from totally ruining the company's reputation.

A full format doesn't detect any bad sectors. I think this is because the format just writes 0s to every sector and expects the drive to report an error if it doesn't succeed. I don't know if flash storage is supposed to report errors to the software - maybe it never does because it masks write errors and remaps the block silently.

Either way, I'm quite convinced this SD card doesn't do bad block remapping nor raise errors. Meanwhile, I've written a tool (attached) to test the sectors by doing a write/read for each free FAT32 cluster and marking them bad if the read back is wrong. I've found a region becomes practically error free after ~4% - ~20% of the clusters have been marked bad. Based on the program execution, it seems a physical block is usually remapped within ~32M of some logical position and only at certain alignments. It's not as clear as a set associative cache, but there definitely is a pattern. An estimate for # logical locations a physical sector can map to is 20% / .001 = ~200.

try creating a hidden partition containing the bad sectors.
I don't think that's practical. It's similar to my method, but it only works well when the bad blocks are tightly clustered, which isn't true in my case, hence it would waste a lot of space.
Attached Files
File Type: txt mark_bad.cpp.txt (6.9 KB, 42 views)

Last edited by bobwall; 09-01-2009 at 03:56 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad sectors, what to do with them? SuperDude123 Linux - Hardware 4 02-15-2009 07:36 PM
Checking for Bad sectors rotty Linux - Hardware 2 09-28-2006 11:34 PM
Bad sectors tuxombie Linux - Hardware 3 01-29-2005 01:05 PM
searching 4 bad sectors zeky Linux - Software 1 12-12-2002 08:49 AM
Bad sectors blystovski Linux - Software 1 10-17-2001 12:18 PM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration