{"id":195,"date":"2012-09-08T14:37:48","date_gmt":"2012-09-08T14:37:48","guid":{"rendered":"http:\/\/www.vidarholen.net\/contents\/blog\/?p=195"},"modified":"2012-09-08T14:37:48","modified_gmt":"2012-09-08T14:37:48","slug":"approaches-to-data-recovery","status":"publish","type":"post","link":"https:\/\/www.vidarholen.net\/contents\/blog\/?p=195","title":{"rendered":"Approaches to data recovery"},"content":{"rendered":"<p>There are a lot of howtos and tutorials for using data recovery tools in Linux, but far less on how to choose a recovery tool or approach in the first place. Here&#8217;s an overview with suggestions for which route to go or tool to use:<\/p>\n<table>\n<tr>\n<th>Cause<\/th>\n<th>Outlook<\/th>\n<th>Tools<\/th>\n<\/tr>\n<tr>\n<td>Forgotten login password<\/td>\n<td>Fantastic<\/td>\n<td>Any livecd<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">This barely qualifies as data recovery, but is included for completeness. If you forget the login password, you can just boot a livecd and mount the drive to access the files. You can also chroot into it and reset the password. Google &#8220;linux forgot password&#8221;.<\/td>\n<\/tr>\n<tr>\n<td>Accidentally deleting files in use<\/td>\n<td>Excellent<\/td>\n<td>lsof, cp<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">When accidentally deleting a file that is still in use by some process &#8212; like an active log file or the source of a video you&#8217;re encoding &#8212; make sure the process doesn&#8217;t exit (sigstop if necessary) and copy the file from the \/proc file handle. Google &#8220;lsof recover deleted files&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Accidentally deleting other files<\/td>\n<td>Fair for harddisks, bad for SSDs<\/td>\n<td>testdisk, ext3grep, extundelete<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">When deleting a file that&#8217;s not currently being held open, stop as much disk activity as you can to prevent the data from being overwritten. If you&#8217;re using an SSD, the data was probably irrevocably cleared within seconds, so bad luck there. Proceed with an fs specific undeletion tool:  Testdisk can undelete NTFS, VFAT and ext2, extundelete\/ext3grep can help with ext3 and ext4. Google &#8220;YourFS undeletion&#8221;. If you can&#8217;t find an undeletion tool for your file systems, or if it fails, try PhotoRec.<\/td>\n<\/tr>\n<tr>\n<td>Trashing the MBR or deleting partitions<\/td>\n<td>Excellent<\/td>\n<td>gpart (note: not gpart<strong>ed<\/strong>), testdisk<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">If you delete a partition with fdisk or recover the MBR from a backup while forgetting that it also contains a partition table, gpart or testdisk will usually easily recover them. If you overwrite any more than the first couple of kilobytes though, it&#8217;s a different ballgame. Just don&#8217;t confuse gpart (guess partitions) with gparted (gtk\/graphical partition editor). Google &#8220;recover partition table&#8221;.<\/td>\n<\/tr>\n<tr>\n<td>Reformatting a file system<\/td>\n<td>Depends on fs<\/td>\n<td>e2fsck, photorec, testdisk<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">If you format the wrong partition, recovery depends on the old and new file system. Try finding unformat\/recovery tools for your old fs. Accidentally formatting a ext3 fs to ntfs (like Windows helpfully suggests when it detects a Linux fs) can often be almost completely reverted by running fsck with an alternate superblock. Google &#8220;ext3 alternate superblock recovery&#8221; or somesuch. <\/p>\n<p \/>\nReformatting ext2\/3\/4 with ext2\/3\/4 will tend to overwrite the superblocks, making this harder. Consider PhotoRec.\n<\/td>\n<\/tr>\n<tr>\n<td>Repartition and reinstall<\/td>\n<td>Depends on progress<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">If you ran a distro installer and accidentally repartitioned and reformatted a disk, try treating it as a case of deleted partitions plus reformatted partitions as described above. Chances of recovery are smaller the more files the installer copied to the partitions. If all else fails, PhotoRec.<\/td>\n<\/tr>\n<tr>\n<td>Bad sectors and drive errors<\/td>\n<td>Ok, depending on extent<\/td>\n<td>ddrescue<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">If the drive has errors, use ddrescue to get as much of the data as possible onto another drive, then treat it as a corrupted file system. Try the fs&#8217; fsck tool, or if the drive is highly corrupted, PhotoRec.<\/td>\n<\/tr>\n<tr>\n<td>Lost encryption key<\/td>\n<td>Very bad<\/td>\n<td>bash, cryptsetup<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">I don&#8217;t know of any tools made for attempting to crack a LUKS password, though you can generate permutations and script a simple cracker if you have limited number of permutations (&#8220;it was Swordfish with some l33t, and a few numbers at the end&#8221;). If you have no idea, or if your encryption software uses TPM (rare for Linux), you&#8217;re screwed.<\/td>\n<\/tr>\n<tr>\n<td>Reformatted or partially overwritten LUKS partition<\/td>\n<td>Horrible<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">LUKS uses your passphrase to encrypt a master key, and stores this info at the start of the partition. If this gets overwritten, you&#8217;re screwed even if you know the passphrase.<\/td>\n<\/tr>\n<tr>\n<td>Other kinds of corruptions or unknown FS<\/td>\n<td>Indeterminable<\/td>\n<td>PhotoRec, strings, grep<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td colspan=\"2\">PhotoRec searches by file signature, and can therefore recover files from a boatload of FS and scenarios, though you&#8217;ll often lose filenames and hierarchies. If you have important ASCII data, strings can dump ASCII text regardless of FS, and you can grep that as a last resort.<\/td>\n<\/tr>\n<\/table>\n<p>If you have other suggestions for scenarios, tools or approaches, leave a commment. Otherwise, I&#8217;ll wish you a speedy recovery!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a lot of howtos and tutorials for using data recovery tools in Linux, but far less on how to choose a recovery tool or approach in the first place. Here&#8217;s an overview with suggestions for which route to go or tool to use: Cause Outlook Tools Forgotten login password Fantastic Any livecd This &hellip; <a href=\"https:\/\/www.vidarholen.net\/contents\/blog\/?p=195\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Approaches to data recovery&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[6,4],"tags":[24,53,45],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-basic-linux","category-linux","tag-fs","tag-linux","tag-recovery"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":21,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}