13 Februray 2012

Fix Nikon DSLR SD Card Error

If you ever encounter the infamous "this memory card cannot be used. card may be damaged. insert another card" error on a Nikon DSLR, here is how I fix it on a Linux machine with a single command.

The strange thing about this error is that the card reads fine on computers. Copy all the photos on the card to your computer before proceeding because we are going to make the card appear unformatted to both the computer and the DSLR. You will lose all the photos without proper backup.

The next thing we are going to do is to mess up the partition table.

dd if=/dev/zero bs=1k count=1 of=/dev/mmcblk0 
mmcblk0 is how the SD card appears to my Linux system. YMMV if you are using a BSD system.

This command zeros out the first 1k block (two 512-bit sectors) of the raw SD card, and in turn erases the partition table on this card (which, I suspect, is the root of problem). This command should take only a fraction of a second to execute.

After this, insert the SD card into the DSLR. The card is recognized as unformatted and the DSLR prompts you to format it. Then, we go to the menu and format it.

The card should work by now.

Though I successfully rescue my "damaged" SD card this way, I still do not get it why the Nikon DSLR does not work with the card while a computer works fine; besides, I only took around 1.7G of RAW+JPEG photos, out of the 16G Kingston card (the card is not listed on the Nikon approved SD card for D5100 list), before the error appeared. If you know the reason why, please kindly drop me an email so I will update on this page. Appreciate it!