{"id":1016,"date":"2008-12-03T22:03:34","date_gmt":"2008-12-03T13:03:34","guid":{"rendered":"https:\/\/regex.info\/blog\/2008-12-03\/1016"},"modified":"2008-12-03T22:03:34","modified_gmt":"2008-12-03T13:03:34","slug":"recovering-photos-from-a-corrupt-memory-card-with-photorec","status":"publish","type":"post","link":"https:\/\/regex.info\/blog\/2008-12-03\/1016","title":{"rendered":"Recovering Photos from a Corrupt Memory Card with PhotoRec"},"content":{"rendered":"\n\n<div class='ic'><a name='006580' href=\"\/i\/JF7_006580.jpg\"\n><img loading=\"lazy\" decoding=\"async\" src=\"\/i\/JF7_006580_sm.jpg\" width=\"690\" height=\"459\"\nalt=\"Almost Lost Brilliant Orange at the Nanzenji Temple, Kyoto Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\nid=\"i006580\"\nphotostream=\"fall\"\ntitle=\"Almost Lost Brilliant Orange at the Nanzenji Temple, Kyoto Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\/><\/a>\n<br\/><span class=\"camera-info robots-nocontent\">Nikon D700 + Nikkor 85mm f\/1.4 &mdash; <sup>1<\/sup><big>\/<\/big>6400 sec, <span class='f'>f<\/span>\/2.2, ISO 200 &mdash;\n<a href=\"\/imageinfo.cgi?url=http%3A%2F%2Fregex.info%2Fi%2FJF7_006580.jpg\">map &amp; image data<\/a> &mdash; <a href=\"\/blog\/proximity\/i\/JF7_006580.jpg\">nearby photos<\/a><\/span>\n<br\/><span class='caption'>Almost Lost<\/span>\n<br\/>Brilliant Orange at the Nanzenji Temple, Kyoto Japan\n<\/div>\n\n<p>I accepted an invite the other day from my friend <a\nhref=\"\/blog\/2005-12-05\/108\">Shimada-san<\/a> to visit the\nNanzen'in temple\/gardens located in <span class='nobr'>a sequestered<\/span> back corner of the large\nNanzenji temple complex. <span class='nobr'>It was my<\/span> first visit to that sub-temple, and I'll\npost more about it later, but suffice to say that it was\n<i>spectacular<\/i>. <span class='nobr'>I took a<\/span> bazillion pictures, which <span class='nobr'>I found<\/span> totally\nmissing when <span class='nobr'>I got<\/span> home and tried to load them onto my PC. <span class='nobr'>The card was<\/span>\ncorrupt and Windows hung trying to read it. Yikes!<\/p>\n\n<div class='ic'><a name='006713' href=\"\/i\/JF7_006713.jpg\"\n><img loading=\"lazy\" decoding=\"async\" src=\"\/i\/JF7_006713_sm.jpg\" width=\"690\" height=\"459\"\nalt=\"Enjoying the Nanzen'in Gardens at the Nanzenji Temple, Kyoto Japan -- Nanzen'in (within Nanzenji) -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\nid=\"i006713\"\ntitle=\"Enjoying the Nanzen'in Gardens at the Nanzenji Temple, Kyoto Japan -- Nanzen'in (within Nanzenji) -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\/><\/a>\n<br\/><span class=\"camera-info robots-nocontent\">Nikon D700 + Nikkor 24-70mm f\/2.8 @ 55 mm &mdash; <sup>1<\/sup><big>\/<\/big>200 sec, <span class='f'>f<\/span>\/6.3, ISO 2500 &mdash;\n<a href=\"\/imageinfo.cgi?url=http%3A%2F%2Fregex.info%2Fi%2FJF7_006713.jpg\">map &amp; image data<\/a> &mdash; <a href=\"\/blog\/proximity\/i\/JF7_006713.jpg\">nearby photos<\/a><\/span>\n<br\/><span class='caption'>Enjoying the Nanzen'in Gardens<\/span>\n<br\/>at the Nanzenji Temple, Kyoto Japan\n<\/div>\n\n<p>It's the first time I've had a problem like this in the 10+ years I've\nbeen shooting digital, so <span class='nobr'>I finally<\/span> had to pay attention to the\nimage-recovery talk that often comes up in online photography forums.<\/p>\n\n<p>I recovered all the photos... the pictures on this post are from among\nthem.<\/p>\n\n<p>In the hope that it might prove useful to someone, I'll recount how <span class='nobr'>I\ndid<\/span> it. Having run into the problem on my Windows XP box, <span class='nobr'>I decided<\/span> to try\nthe recovery on my Mac.<\/p>\n\n<p>I used the most-excellent <a\nhref=\"http:\/\/www.cgsecurity.org\/wiki\/PhotoRec\">PhotoRec<\/a> software to\nrecover the files. <span class='nobr'>It's a command<\/span>-line program that can run on many\ndifferent operating systems (DOS, Windows, Linux, <span class='nobr'>Mac OS X<\/span>, FreeBSD...), so\n<span class='nobr'>I did<\/span> the recovery within <span class='nobr'>a Mac<\/span> <b>Terminal<\/b> window.<\/p>\n\n<style type=\"text\/css\">\n.t1016 { margin-left:2em; border-left: 3px solid gray; padding-left: 1em }\n.q1016 { color: #888 }\ntt { color:white }\n.hl { color: #F55 }\n.typ { color: #3C3 }\n<\/style>\n\n<p>First, <span class='nobr'>I mounted<\/span> the damaged card, and used the <b>df<\/b> command to see its raw device name:<\/p>\n\n<pre class='t1016'>\n\n% <b class='typ'>df<\/b>\n<span class='q1016'>Filesystem              512-blocks      Used   Avail Capacity  Mounted on\n\/dev\/disk0s2             155367520 148986336 5869184    96%    \/\ndevfs                          208       208       0   100%    \/dev\n&lt;volfs&gt;                       1024      1024       0   100%    \/.vol<\/span>\n<b class='hl'>\/dev\/disk1s1<\/b>               <span class='q1016'>7536512       704 7535808     0%<\/span>    <b class='hl'>\/Volumes\/NIKON D700<\/b>\n\n<\/pre>\n\n<p>The details of what you see would be different on your system, but the\nimportant thing here is to be able to identify the line with the memory\ncard (in my example, the last line), and to then identify the &#8220;raw device\nname&#8221; at the start of that line. <span class='nobr'>The raw device<\/span> name will always start with\n&#8220;<tt>\/dev\/<\/tt>&#8221; and in my example, it's &#8220;<tt>\/dev\/disk1s1<\/tt>&#8221;.<\/p>\n\n<p>(If there's a way to connect a memory card without OSX mounting it, <span class='nobr'>I'd like to<\/span> know, because that would be safer.)<\/p>\n\n<p>You then need to tell OS X to pretend that the memory card is no longer mounted while actually leaving it physically connected to the computer.\nThus, without disconnecting it, run the following (using the raw device name you find in the first step):<\/p>\n\n<pre class='t1016'>\n\n% <b class='typ'>sudo umount \/dev\/disk1s1<\/b>\n\n<\/pre>\n\n<p>You'll have to be an administrator, and will have to enter your password.<\/p>\n\n<p>Now, run <b>photorec<\/b>. <span class='nobr'>The Mac version<\/span> is in the &#8220;darwin&#8221; subfolder\nof the download folder, so after changing directories to the download\nfolder, here's what <span class='nobr'>I ran<\/span> (again, you'll want to change the raw device name\nto whatever you found):<\/p>\n\n<pre class='t1016'>\n\n% <b class='typ'>darwin\/photorec \/dev\/disk1s1<\/b>\nPhotoRec 6.10, Data Recovery Utility, July 2008\nChristophe GRENIER &lt;grenier@cgsecurity.org&gt;\nhttp:\/\/www.cgsecurity.org\n\nPhotoRec is free software, and comes with ABSOLUTELY NO WARRANTY.\n\nSelect a media (use Arrow keys, then press Enter):\n<span style='background-color:#AAA; color:black'>Disk \/dev\/disk1s1 - 8152 MB \/ 7775 MiB (RO)<\/span>\n\n[Proceed ]  [  Quit  ]\n\nNote: Some disks won't appear unless you're root user.\nDisk capacity must be correctly detected for a successful recovery.\nIf a disk listed above has incorrect size, check HD jumper settings, BIOS\ndetection, and install the latest OS patches and disk drivers.\n\n<\/pre>\n\n<p>I made sure that the raw device name was highlighted, then pressed\nenter. It'll progress through <span class='nobr'>a few<\/span> more screens where you tell it that the\ncard has an <b>Intel\/PC<\/b> partition-table type, that you want to do the\n&#8220;<b>whole disk<\/b>&#8221;, that the filesystem is &#8220;<b>Other<\/b>&#8221;, and where you\nwant to save whatever files it can recover. (<span class='nobr'>I had<\/span> just created a &#8220;found&#8221;\nfolder on my Desktop, and used that.)<\/p>\n\n<p>Make sure, of course, that you have at least enough free space on the\ndisk as the size of the card.<\/p>\n\n<p>PhotoRec took about two hours to process My Transcend 8GB &#8220;300&times;&#8221;\ncompact-flash card, and recovered all the pictures from the day, and\nhundreds of random other shots going back more than <span class='nobr'>a month.<\/span> <span class='nobr'>I reformat<\/span> the\ncard each time <span class='nobr'>I go<\/span> out, but that just marks the disk's table of contents as\nempty, without actually clearing out any data, so the data for random old\npictures remained on the card for PhotoRec to find.<\/p>\n\n<div class='ic tight'><a name='006793' href=\"\/i\/JF7_006793.jpg\"\n><img loading=\"lazy\" decoding=\"async\" src=\"\/i\/JF7_006793_sm.jpg\" width=\"690\" height=\"459\"\nalt=\"Nanzenji -- Kyoto, Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\nid=\"i006793\"\nphotostream=\"fall\"\ntitle=\"Nanzenji -- Kyoto, Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\/><\/a>\n<br\/><span class=\"camera-info robots-nocontent\">Nikon D700 + Nikkor 24-70mm f\/2.8 @ 70 mm &mdash; <sup>1<\/sup><big>\/<\/big>200 sec, <span class='f'>f<\/span>\/6.3, ISO 220 &mdash;\n<a href=\"\/imageinfo.cgi?url=http%3A%2F%2Fregex.info%2Fi%2FJF7_006793.jpg\">map &amp; image data<\/a> &mdash; <a href=\"\/blog\/proximity\/i\/JF7_006793.jpg\">nearby photos<\/a><\/span>\n<\/div>\n\n<p>PhotoRec does not recover the original filename with <span class='nobr'>a recovered<\/span> file,\nso whatever images it finds have names filled with apparently random\nnumbers, like &#8220;f1535616.jpg&#8221;. <span class='nobr'>If your digital<\/span>-photo workflow involves\nrenaming images based on, say, the image-capture date and time, you don't\ncare what the in-camera filename was, but <a\nhref=\"\/blog\/2008-02-16\/739\">my workflow<\/a> keeps the\nin-camera filename, so i wanted to rename the files to what they would have\nbeen.<\/p>\n\n<p>I used this magic incantation, which requires <a\nhref=\"http:\/\/www.sno.phy.queensu.ca\/~phil\/exiftool\/\">exiftool<\/a>:<\/p>\n\n<pre class='t1016 typ'>\n\nexiftool -q -p 'mv ${filename} JF7_00${filenumber}.NEF;'  *.nef  | sh\n\n<\/pre>\n\n<p>I don't know about other kinds of cameras, but Nikon SLRs include in the\nimage file a &#8220;FileNumber&#8221; bit of metadata that tells what number was used\nin the in-camera filename. <span class='nobr'>I use<\/span> <i>exiftool<\/i> to reference that number,\ninsert it into the pattern for the kind of filename <span class='nobr'>I want,<\/span> then combine\nthat with <span class='nobr'>a file<\/span>-rename command.<\/p>\n\n<p>Spiffy.<\/p>\n\n\n<p>It's probably overkill, but I then used the built-in Mac &#8220;Disk Utility&#8221;\nto zero-fill the entire memory card, then re-formatted it in my camera.\nGood as new.<\/p>\n\n<div class='ic tight'><a name='006782' href=\"\/i\/JF7_006782.jpg\"\n><img loading=\"lazy\" decoding=\"async\" src=\"\/i\/JF7_006782_sm.jpg\" width=\"690\" height=\"459\"\nalt=\"Nanzenji -- Kyoto, Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\nid=\"i006782\"\nphotostream=\"fall\"\ntitle=\"Nanzenji -- Kyoto, Japan -- Copyright 2008 Jeffrey Friedl, https:\/\/regex.info\/blog\/\"\/><\/a>\n<br\/><span class=\"camera-info robots-nocontent\">Nikon D700 + Nikkor 24-70mm f\/2.8 @ 70 mm &mdash; <sup>1<\/sup><big>\/<\/big>250 sec, <span class='f'>f<\/span>\/6.3, ISO 200 &mdash;\n<a href=\"\/imageinfo.cgi?url=http%3A%2F%2Fregex.info%2Fi%2FJF7_006782.jpg\">map &amp; image data<\/a> &mdash; <a href=\"\/blog\/proximity\/i\/JF7_006782.jpg\">nearby photos<\/a><\/span>\n<\/div>\n\n<p>The pictures I recovered are nice, but it's not like <span class='nobr'>I couldn't<\/span> have\njust walked down there again today to take most of them. <span class='nobr'>I'm happy<\/span> to have\nrecovered them, but I'm most happy about having this experience under my\nbelt, so that these techniques will be at my disposal should <span class='nobr'>I ever<\/span> be\nfaced with the loss of important pictures.<\/p>\n\n<p>In thanks for making this experience possible, <span class='nobr'>I sent<\/span> \u20ac25 <a\nhref=\"http:\/\/www.cgsecurity.org\/wiki\/Donation\">to the guy who wrote\nPhotoRec<\/a>, Christophe Grenier. Thanks, Christophe!<\/p>\n\n\n\n\n\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>I accepted an invite the other day from my friend Shimada-san to visit the Nanzen'in temple\/gardens located in a sequestered back corner of the large Nanzenji temple complex. It was my first visit to that sub-temple, and I'll post more about it later, but suffice to say that it was spectacular. I took a bazillion pictures, which I found totally missing when I got home and tried to load them onto my PC. The card was corrupt and Windows hung trying to read it. Yikes!<\/p> <p>It's the first time I've had a problem like this in the 10+ years I've [...]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1,4],"tags":[],"_links":{"self":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts\/1016"}],"collection":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/comments?post=1016"}],"version-history":[{"count":0,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts\/1016\/revisions"}],"wp:attachment":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/media?parent=1016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/categories?post=1016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/tags?post=1016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}