Difference between revisions of "File recovery"

From ArchWiki
Jump to: navigation, search
(Preface/Introduction: Move introduction out. See Help:Style.)
m (Format/style fixes.)
Line 1: Line 1:
 
[[Category:File systems]]
 
[[Category:File systems]]
 
[[Category:System recovery]]
 
[[Category:System recovery]]
This article lists data recovery and undeletion options for [[Arch Linux]]. Please contribute to this page using the general format below, keeping it brief if possible.
+
This article lists data recovery and undeletion options for Arch Linux. Please contribute to this page using the general format below, keeping it brief if possible.
== Special Notes==
+
 
 +
== Special notes==
  
 
=== Before you start ===
 
=== Before you start ===
Line 8: Line 9:
 
This page is mostly intended to be used for educational purposes. If you have accidentally deleted or otherwise damaged your '''valuable and irreplaceable''' data and have no previous experience with data recovery, turn off your computer immediately (Just press and hold the off button or pull the plug; do not use the system shutdown function) and seek professional help. It is quite possible and even probable that, if you follow any of the steps described below without fully understanding them, you will worsen your situation.
 
This page is mostly intended to be used for educational purposes. If you have accidentally deleted or otherwise damaged your '''valuable and irreplaceable''' data and have no previous experience with data recovery, turn off your computer immediately (Just press and hold the off button or pull the plug; do not use the system shutdown function) and seek professional help. It is quite possible and even probable that, if you follow any of the steps described below without fully understanding them, you will worsen your situation.
  
=== Failing Drives ===
+
=== Failing drives ===
  
 
In the area of data recovery, it is best to work on images of disks rather than physical disks themselves. Generally, a failing drive's condition worsens over time. The goal ought to be to first rescue as much data as possible as early as possible in the failure of the disk and to then abandon the disk. The {{Pkg|ddrescue}} and {{Pkg|dd_rescue}} utilities, unlike {{ic|dd}}, will repeatedly try to recover from errors and will read the drive front to back, then back to front, attempting to salvage data. They keep log files so that recovery can be paused and resumed without losing progress.
 
In the area of data recovery, it is best to work on images of disks rather than physical disks themselves. Generally, a failing drive's condition worsens over time. The goal ought to be to first rescue as much data as possible as early as possible in the failure of the disk and to then abandon the disk. The {{Pkg|ddrescue}} and {{Pkg|dd_rescue}} utilities, unlike {{ic|dd}}, will repeatedly try to recover from errors and will read the drive front to back, then back to front, attempting to salvage data. They keep log files so that recovery can be paused and resumed without losing progress.
Line 20: Line 21:
 
Do not attempt a filesystem check on a failing drive, as this will likely make the problem '''worse'''. Mount it read-only.
 
Do not attempt a filesystem check on a failing drive, as this will likely make the problem '''worse'''. Mount it read-only.
  
===Backup Flash Media/Small Partitions===
+
=== Backup flash media/small partitions ===
 +
 
 
As an alternative to working with a 'live' partition (mounted or not), it is often preferable to work with an image, provided that the filesystem in question is not too large and that you have sufficient free HDD space to accommodate the image file. For example, flash memory devices like thumb drives, digital cameras, portable music players, cellular phones, etc. are likely to be small enough to image in many cases.
 
As an alternative to working with a 'live' partition (mounted or not), it is often preferable to work with an image, provided that the filesystem in question is not too large and that you have sufficient free HDD space to accommodate the image file. For example, flash memory devices like thumb drives, digital cameras, portable music players, cellular phones, etc. are likely to be small enough to image in many cases.
  
Line 28: Line 30:
 
  # dd if=/dev/target_partition of=/home/user/partition.image
 
  # dd if=/dev/target_partition of=/home/user/partition.image
  
===Working with Digital Cameras===
+
=== Working with digital cameras ===
 +
 
 
In order for some of the utilities listed in the next section to work with flash media, the device in question needs to be mounted as a block device (i.e., listed under /dev). Digital cameras operating in PTP (Picture Transfer Protocol) mode will not work in this regard. PTP cameras are transparently handled by libgphoto and/or libptp. In this case, "transparently" means that PTP devices do not get block devices. The alternative to PTP mode, USB Mass Storage (UMS) mode, is not supported by all cameras. Some cameras have a menu item that allows switching between the two modes; refer to your camera's user manual. If your camera does not support UMS mode and therefore cannot be accessed as a block device, your only alternative is to use a flash media reader and physically remove the storage media from your camera.
 
In order for some of the utilities listed in the next section to work with flash media, the device in question needs to be mounted as a block device (i.e., listed under /dev). Digital cameras operating in PTP (Picture Transfer Protocol) mode will not work in this regard. PTP cameras are transparently handled by libgphoto and/or libptp. In this case, "transparently" means that PTP devices do not get block devices. The alternative to PTP mode, USB Mass Storage (UMS) mode, is not supported by all cameras. Some cameras have a menu item that allows switching between the two modes; refer to your camera's user manual. If your camera does not support UMS mode and therefore cannot be accessed as a block device, your only alternative is to use a flash media reader and physically remove the storage media from your camera.
  
==Foremost==
+
== Foremost==
===Description===
+
 
[[Foremost]] is a console program to recover files based on their headers, footers, and internal data structures.  This process is commonly referred to as data carving. Foremost can work on disk image files (such as those generated by dd, Safeback, Encase, etc.) or directly on a drive. The headers and footers can be specified by a configuration file or command line switches can be used to specify built-in file types. These built-in types look at the data structures of a given file format, allowing for more reliable and faster recovery.  
+
[http://foremost.sourceforge.net Foremost] is a console program to recover files based on their headers, footers, and internal data structures.  This process is commonly referred to as data carving. Foremost can work on disk image files (such as those generated by dd, Safeback, Encase, etc.) or directly on a drive. The headers and footers can be specified by a configuration file or command line switches can be used to specify built-in file types. These built-in types look at the data structures of a given file format, allowing for more reliable and faster recovery.
===Installation===
+
 
{{AUR|foremost}} is available in the [[AUR]].
+
See [[Foremost]] article.
===External Links===
+
 
*Wiki:
+
== Extundelete ==
*Homepage: http://foremost.sourceforge.net
+
  
==Extundelete==
 
===Description===
 
 
'''[http://extundelete.sourceforge.net/ Extundelete]''' is a terminal-based utility designed to recover deleted files from ext3 and ext4 partitions. It can recover all the recently deleted files from a partition and/or a specific file(s) given by relative path or inode information. Note that it works only when the partition is unmounted. The recovered files are saved in the current directory under the folder named {{ic|RECOVERED_FILES/}}.
 
'''[http://extundelete.sourceforge.net/ Extundelete]''' is a terminal-based utility designed to recover deleted files from ext3 and ext4 partitions. It can recover all the recently deleted files from a partition and/or a specific file(s) given by relative path or inode information. Note that it works only when the partition is unmounted. The recovered files are saved in the current directory under the folder named {{ic|RECOVERED_FILES/}}.
===Installation===
+
 
 +
=== Installation ===
 +
 
 
{{Pkg|extundelete}} is available in the [[official repositories]].
 
{{Pkg|extundelete}} is available in the [[official repositories]].
  
===Usage===
+
=== Usage ===
 +
 
 
''Derived from the post on [http://linuxpoison.blogspot.com/2010/09/utility-to-recover-deleted-files-from.html Linux Poison].''
 
''Derived from the post on [http://linuxpoison.blogspot.com/2010/09/utility-to-recover-deleted-files-from.html Linux Poison].''
  
To recover data from a specific partition, the device name for the partition, which will be in the format {{ic|/dev/sdXN}} ({{ic|X}} is a letter and {{ic|N}} is a number.), must be known. The example used here is {{ic|/dev/sda4}}, but your system might use something different (For example, mmc card readers use {{ic|/dev/mmcblkNpN}} as their naming scheme.) depending on your filesystem and device configuration. If you are unsure, run {{ic|df}}, which prints currently mounted partitions.
+
To recover data from a specific partition, the device name for the partition, which will be in the format {{ic|/dev/sd''XN''}} (''X'' is a letter and ''N'' is a number.), must be known. The example used here is {{ic|/dev/sda4}}, but your system might use something different (For example, MMC card readers use {{ic|/dev/mmcblkNpN}} as their naming scheme.) depending on your filesystem and device configuration. If you are unsure, run {{ic|df}}, which prints currently mounted partitions.
  
 
Once which partition data is to be recovered from has been determined, simply run:
 
Once which partition data is to be recovered from has been determined, simply run:
  # extundelete /dev/sda4 --restore-file directory/file
+
  # extundelete /dev/sda4 --restore-file ''directory''/''file''
Any subdirectories must be specified, and the command runs from the highest level of the partition, so, to recover a file in {{ic|/home/SomeUserName/}}, assuming {{ic|/home}} is on its own partition, run:
+
Any subdirectories must be specified, and the command runs from the highest level of the partition, so, to recover a file in {{ic|/home/''SomeUserName''/}}, assuming {{ic|/home}} is on its own partition, run:
  # extundelete /dev/sda4 restore-file <SomeUserName>/<SomeFile>
+
  # extundelete /dev/sda4 restore-file ''SomeUserName''/''SomeFile''
 
To speed up multi-file recovery, extundelete has a {{ic|--restore-files}} option as well.
 
To speed up multi-file recovery, extundelete has a {{ic|--restore-files}} option as well.
  
 
To recover an entire directory, run:
 
To recover an entire directory, run:
  # extundelete /dev/sda4 --restore-directory <SomeUserName>/<SomeDirectory>
+
  # extundelete /dev/sda4 --restore-directory ''SomeUserName''/''SomeDirectory''
  
 
For advanced users, to manually recover blocks or inodes with extundelete, debugfs can be used to find the inode to be recovered; then, run:
 
For advanced users, to manually recover blocks or inodes with extundelete, debugfs can be used to find the inode to be recovered; then, run:
  # extundelete --restore-inode <inode>
+
  # extundelete --restore-inode ''inode''
"<inode>" stands for any valid inode. Additional inodes to recover can be listed in an unspaced, comma-separated fashion.
+
''inode'' stands for any valid inode. Additional inodes to recover can be listed in an unspaced, comma-separated fashion.
  
 
Finally, to recover all deleted files from an entire partition, run:
 
Finally, to recover all deleted files from an entire partition, run:
 
  # extundelete /dev/sda4 --restore-all
 
  # extundelete /dev/sda4 --restore-all
  
==Testdisk and PhotoRec==
+
== Testdisk and PhotoRec ==
===Description===
+
 
'''TestDisk''' and '''Photorec''' are both open-source data recovery utilities licensed under the terms of the [http://www.gnu.org/licenses/gpl.html GNU Public License] (GPL).
+
TestDisk and Photorec are both open-source data recovery utilities licensed under the terms of the [http://www.gnu.org/licenses/gpl.html GNU Public License] (GPL).
  
 
'''TestDisk''' is primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses, or human error, such as the accidental deletion of partition tables.
 
'''TestDisk''' is primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses, or human error, such as the accidental deletion of partition tables.
Line 75: Line 78:
 
'''PhotoRec''' is file recovery software designed to recover lost files including photographs (Hint: '''Photo'''graph'''Rec'''overy), videos, documents, archives from hard disks and CD-ROMs. PhotoRec ignores the filesystem and goes after the underlying data, so it will still work even with a re-formatted or severely damaged filesystems and/or partition tables.
 
'''PhotoRec''' is file recovery software designed to recover lost files including photographs (Hint: '''Photo'''graph'''Rec'''overy), videos, documents, archives from hard disks and CD-ROMs. PhotoRec ignores the filesystem and goes after the underlying data, so it will still work even with a re-formatted or severely damaged filesystems and/or partition tables.
  
===Installation===
+
=== Installation ===
{{Pkg|testdisk}} from the [[official repositories]] provides both '''TestDisk''' and '''PhotoRec'''.
+
  
===External Links===
+
{{Pkg|testdisk}} from the [[official repositories]] provides both TestDisk and PhotoRec.
*Wiki (TestDisk): http://www.cgsecurity.org/wiki/TestDisk
+
 
*Wiki (Photorec): http://www.cgsecurity.org/wiki/PhotoRec
+
=== See also ===
*Homepage: http://www.cgsecurity.org/
+
 
 +
* Wiki (TestDisk): http://www.cgsecurity.org/wiki/TestDisk
 +
* Wiki (Photorec): http://www.cgsecurity.org/wiki/PhotoRec
 +
* Homepage: http://www.cgsecurity.org/
 +
 
 +
== e2fsck ==
  
==e2fsck==
 
===Description===
 
 
'''e2fsck''' is the ext2/ext3 filesystem checker included in the base install of Arch. e2fsck relies on a valid superblock. A superblock is a description of the entire filesystem's parameters. Because this data is so important, several copies of the superblock are distributed throughout the partition. With the {{ic|-b}} option, e2fsck can take an alternate superblock argument; this is useful if the main, first superblock is damaged.
 
'''e2fsck''' is the ext2/ext3 filesystem checker included in the base install of Arch. e2fsck relies on a valid superblock. A superblock is a description of the entire filesystem's parameters. Because this data is so important, several copies of the superblock are distributed throughout the partition. With the {{ic|-b}} option, e2fsck can take an alternate superblock argument; this is useful if the main, first superblock is damaged.
  
 
To determine where the superblocks are, run {{ic|dumpe2fs -h}} on the target, unmounted partition. Superblocks are spaced differently depending on the filesystem's blocksize, which is set when the filesystem is created.
 
To determine where the superblocks are, run {{ic|dumpe2fs -h}} on the target, unmounted partition. Superblocks are spaced differently depending on the filesystem's blocksize, which is set when the filesystem is created.
  
An alternate method to determine the locations of superblocks is to use the -n option with mke2fs. Be '''sure''' to use the -n flag, which, according to the {{ic|mke2fs}} manpage, "''Causes mke2fs to not actually create a filesystem, but display what it would do if it were to create a filesystem. This can be used to determine the location of the backup superblocks for a particular filesystem, so long as the mke2fs parameters that were passed when the filesystem was originally created are used again. (With the -n option added, of course!)''".
+
An alternate method to determine the locations of superblocks is to use the -n option with mke2fs. Be '''sure''' to use the {{ic|-n}} flag, which, according to the {{ic|mke2fs}} manpage, "''Causes mke2fs to not actually create a filesystem, but display what it would do if it were to create a filesystem. This can be used to determine the location of the backup superblocks for a particular filesystem, so long as the mke2fs parameters that were passed when the filesystem was originally created are used again. (With the -n option added, of course!)''".
 +
 
 +
=== Installation ===
  
===Installation===
 
 
Both {{Pkg|e2fsck}} and {{Pkg|dumpe2fs}} are included in the base Arch install.
 
Both {{Pkg|e2fsck}} and {{Pkg|dumpe2fs}} are included in the base Arch install.
  
===External Links===
+
=== See also ===
*e2fsck man page: http://phpunixman.sourceforge.net/index.php/man/e2fsck/8
+
 
*dumpe2fs man page: http://phpunixman.sourceforge.net/index.php?parameter=dumpe2fs&mode=man
+
* e2fsck man page: http://phpunixman.sourceforge.net/index.php/man/e2fsck/8
 +
* dumpe2fs man page: http://phpunixman.sourceforge.net/index.php?parameter=dumpe2fs&mode=man
 +
 
 +
== Working with raw disk images ==
  
==Working with Raw Disk Images==
 
 
If you have backed up a drive using ddrescue or dd and you need to mount this image as a physical drive, see this section.
 
If you have backed up a drive using ddrescue or dd and you need to mount this image as a physical drive, see this section.
===Mount the Entire Disk===
+
 
 +
=== Mount the entire disk ===
 +
 
 
To mount a complete disk image to the next free loop device, use the {{ic|losetup}} command:
 
To mount a complete disk image to the next free loop device, use the {{ic|losetup}} command:
 
  # losetup -f -P /path/to/image
 
  # losetup -f -P /path/to/image
{{Tip|The {{ic|-f}} flag mounts the image to the next available loop device.}}
+
 
{{Tip|The {{ic|-P}} flag creates additional devices for every partition.}}
+
{{Tip|
===Mounting Partitions===
+
* The {{ic|-f}} flag mounts the image to the next available loop device.
 +
* The {{ic|-P}} flag creates additional devices for every partition.
 +
}}
 +
 
 +
=== Mounting partitions ===
 +
 
 
In order to be able to mount a partiton of a whole disk image, follow [[File_Recovery#Mount_the_Entire_Disk|the steps above]].
 
In order to be able to mount a partiton of a whole disk image, follow [[File_Recovery#Mount_the_Entire_Disk|the steps above]].
  
Line 111: Line 126:
 
  # mount /dev/loop0p1 /mnt/example
 
  # mount /dev/loop0p1 /mnt/example
 
This command mounts the first partition of the image in loop0 to the folder to the mountpoint {{ic|/mnt/example}}. Remember that the mountpoint directory must exist!
 
This command mounts the first partition of the image in loop0 to the folder to the mountpoint {{ic|/mnt/example}}. Remember that the mountpoint directory must exist!
====Getting Disk Geometry====
+
 
 +
==== Getting disk geometry ====
 +
 
 
Once the entire disk image has been mounted as a loopback device, its drive layout can be inspected.
 
Once the entire disk image has been mounted as a loopback device, its drive layout can be inspected.
===Using QEMU to Repair NTFS===
+
 
 +
=== Using QEMU to Repair NTFS ===
 +
 
 
With a disk image that contains one or more NTFS partitions that need to be {{ic|chkdsk}}ed by Windows since no good NTFS filesystem checker for Linux exists, QEMU can use a raw disk image as a real hard disk inside a virtual machine:
 
With a disk image that contains one or more NTFS partitions that need to be {{ic|chkdsk}}ed by Windows since no good NTFS filesystem checker for Linux exists, QEMU can use a raw disk image as a real hard disk inside a virtual machine:
  # qemu -hda /path/to/primary.img -hdb /path/to/DamagedDisk.img
+
  # qemu -hda ''/path/to/primary''.img -hdb ''/path/to/DamagedDisk''.img
Then, assuming Windows is installed on {{ic|primary.img}}, it can be used to check partitions on {{ic|/path/to/DamagedDisk.img}}.
+
Then, assuming Windows is installed on {{ic|''primary''.img}}, it can be used to check partitions on {{ic|''/path/to/DamagedDisk''.img}}.
  
 
== Text file recovery ==
 
== Text file recovery ==
 +
 
It's possible to find deleted plain text on a hard drive with a few commands. A preferably unique string from the file you are trying to recover is needed.
 
It's possible to find deleted plain text on a hard drive with a few commands. A preferably unique string from the file you are trying to recover is needed.
  
 
First, use the {{ic|strings}} command to dump all the text from a partition:
 
First, use the {{ic|strings}} command to dump all the text from a partition:
  
  # strings /dev/sdXN > BigStringsFile
+
  # strings /dev/sd''XN'' > ''BigStringsFile''
  
Then use {{ic|grep}} to filter through the content of {{ic|BigStringsFile}}:
+
Then use {{ic|grep}} to filter through the content of ''BigStringsFile'':
  
  $ grep -i -200 "Unique string in text file" BigStringsFile > GrepOutputFile
+
  $ grep -i -200 "Unique string in text file" ''BigStringsFile'' > ''GrepOutputFile''
  
 
{{Note|The {{ic|-200}} option tells grep to print 200 lines of context from before and after each mach of the string. You may need to adjust this if the text you are looking for is very long.}}
 
{{Note|The {{ic|-200}} option tells grep to print 200 lines of context from before and after each mach of the string. You may need to adjust this if the text you are looking for is very long.}}
Hopefully, the correct deleted data is now in GrepOutputFile.
+
Hopefully, the correct deleted data is now in ''GrepOutputFile''.
 +
 
 +
== See also ==
  
==External links==
+
* [https://help.ubuntu.com/community/DataRecovery Data Recovery] on the Ubuntu wiki
*[https://help.ubuntu.com/community/DataRecovery Data Recovery] on the Ubuntu wiki
+

Revision as of 08:26, 21 February 2014

This article lists data recovery and undeletion options for Arch Linux. Please contribute to this page using the general format below, keeping it brief if possible.

Special notes

Before you start

This page is mostly intended to be used for educational purposes. If you have accidentally deleted or otherwise damaged your valuable and irreplaceable data and have no previous experience with data recovery, turn off your computer immediately (Just press and hold the off button or pull the plug; do not use the system shutdown function) and seek professional help. It is quite possible and even probable that, if you follow any of the steps described below without fully understanding them, you will worsen your situation.

Failing drives

In the area of data recovery, it is best to work on images of disks rather than physical disks themselves. Generally, a failing drive's condition worsens over time. The goal ought to be to first rescue as much data as possible as early as possible in the failure of the disk and to then abandon the disk. The ddrescue and dd_rescue utilities, unlike dd, will repeatedly try to recover from errors and will read the drive front to back, then back to front, attempting to salvage data. They keep log files so that recovery can be paused and resumed without losing progress.

See Disk Cloning.

The image files created from a utility like ddrescue can then be mounted like a physical device and can be worked on safely. Always make a copy of the original image so that you can revert if things go sour!

A tried and true method of improving failing drive reads is to keep the drive cold. A bit of time in the freezer is appropriate, but be careful to avoid bringing the drive from cold to warm too quickly, as condensation will form. Keeping the drive in the freezer with cables connected to the recovering PC works great.

Do not attempt a filesystem check on a failing drive, as this will likely make the problem worse. Mount it read-only.

Backup flash media/small partitions

As an alternative to working with a 'live' partition (mounted or not), it is often preferable to work with an image, provided that the filesystem in question is not too large and that you have sufficient free HDD space to accommodate the image file. For example, flash memory devices like thumb drives, digital cameras, portable music players, cellular phones, etc. are likely to be small enough to image in many cases.

Be sure to read the man pages for the utilities listed below to verify that they are capable of working with image files.

To make an image, one can use dd as follows:

# dd if=/dev/target_partition of=/home/user/partition.image

Working with digital cameras

In order for some of the utilities listed in the next section to work with flash media, the device in question needs to be mounted as a block device (i.e., listed under /dev). Digital cameras operating in PTP (Picture Transfer Protocol) mode will not work in this regard. PTP cameras are transparently handled by libgphoto and/or libptp. In this case, "transparently" means that PTP devices do not get block devices. The alternative to PTP mode, USB Mass Storage (UMS) mode, is not supported by all cameras. Some cameras have a menu item that allows switching between the two modes; refer to your camera's user manual. If your camera does not support UMS mode and therefore cannot be accessed as a block device, your only alternative is to use a flash media reader and physically remove the storage media from your camera.

Foremost

Foremost is a console program to recover files based on their headers, footers, and internal data structures. This process is commonly referred to as data carving. Foremost can work on disk image files (such as those generated by dd, Safeback, Encase, etc.) or directly on a drive. The headers and footers can be specified by a configuration file or command line switches can be used to specify built-in file types. These built-in types look at the data structures of a given file format, allowing for more reliable and faster recovery.

See Foremost article.

Extundelete

Extundelete is a terminal-based utility designed to recover deleted files from ext3 and ext4 partitions. It can recover all the recently deleted files from a partition and/or a specific file(s) given by relative path or inode information. Note that it works only when the partition is unmounted. The recovered files are saved in the current directory under the folder named RECOVERED_FILES/.

Installation

extundelete is available in the official repositories.

Usage

Derived from the post on Linux Poison.

To recover data from a specific partition, the device name for the partition, which will be in the format /dev/sdXN (X is a letter and N is a number.), must be known. The example used here is /dev/sda4, but your system might use something different (For example, MMC card readers use /dev/mmcblkNpN as their naming scheme.) depending on your filesystem and device configuration. If you are unsure, run df, which prints currently mounted partitions.

Once which partition data is to be recovered from has been determined, simply run:

# extundelete /dev/sda4 --restore-file directory/file

Any subdirectories must be specified, and the command runs from the highest level of the partition, so, to recover a file in /home/SomeUserName/, assuming /home is on its own partition, run:

# extundelete /dev/sda4 restore-file SomeUserName/SomeFile

To speed up multi-file recovery, extundelete has a --restore-files option as well.

To recover an entire directory, run:

# extundelete /dev/sda4 --restore-directory SomeUserName/SomeDirectory

For advanced users, to manually recover blocks or inodes with extundelete, debugfs can be used to find the inode to be recovered; then, run:

# extundelete --restore-inode inode

inode stands for any valid inode. Additional inodes to recover can be listed in an unspaced, comma-separated fashion.

Finally, to recover all deleted files from an entire partition, run:

# extundelete /dev/sda4 --restore-all

Testdisk and PhotoRec

TestDisk and Photorec are both open-source data recovery utilities licensed under the terms of the GNU Public License (GPL).

TestDisk is primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses, or human error, such as the accidental deletion of partition tables.

PhotoRec is file recovery software designed to recover lost files including photographs (Hint: PhotographRecovery), videos, documents, archives from hard disks and CD-ROMs. PhotoRec ignores the filesystem and goes after the underlying data, so it will still work even with a re-formatted or severely damaged filesystems and/or partition tables.

Installation

testdisk from the official repositories provides both TestDisk and PhotoRec.

See also

e2fsck

e2fsck is the ext2/ext3 filesystem checker included in the base install of Arch. e2fsck relies on a valid superblock. A superblock is a description of the entire filesystem's parameters. Because this data is so important, several copies of the superblock are distributed throughout the partition. With the -b option, e2fsck can take an alternate superblock argument; this is useful if the main, first superblock is damaged.

To determine where the superblocks are, run dumpe2fs -h on the target, unmounted partition. Superblocks are spaced differently depending on the filesystem's blocksize, which is set when the filesystem is created.

An alternate method to determine the locations of superblocks is to use the -n option with mke2fs. Be sure to use the -n flag, which, according to the mke2fs manpage, "Causes mke2fs to not actually create a filesystem, but display what it would do if it were to create a filesystem. This can be used to determine the location of the backup superblocks for a particular filesystem, so long as the mke2fs parameters that were passed when the filesystem was originally created are used again. (With the -n option added, of course!)".

Installation

Both e2fsck and dumpe2fs are included in the base Arch install.

See also

Working with raw disk images

If you have backed up a drive using ddrescue or dd and you need to mount this image as a physical drive, see this section.

Mount the entire disk

To mount a complete disk image to the next free loop device, use the losetup command:

# losetup -f -P /path/to/image
Tip:
  • The -f flag mounts the image to the next available loop device.
  • The -P flag creates additional devices for every partition.

Mounting partitions

In order to be able to mount a partiton of a whole disk image, follow the steps above.

Once the whole disk image is mounted, a normal mount command can be used on the loop device:

# mount /dev/loop0p1 /mnt/example

This command mounts the first partition of the image in loop0 to the folder to the mountpoint /mnt/example. Remember that the mountpoint directory must exist!

Getting disk geometry

Once the entire disk image has been mounted as a loopback device, its drive layout can be inspected.

Using QEMU to Repair NTFS

With a disk image that contains one or more NTFS partitions that need to be chkdsked by Windows since no good NTFS filesystem checker for Linux exists, QEMU can use a raw disk image as a real hard disk inside a virtual machine:

# qemu -hda /path/to/primary.img -hdb /path/to/DamagedDisk.img

Then, assuming Windows is installed on primary.img, it can be used to check partitions on /path/to/DamagedDisk.img.

Text file recovery

It's possible to find deleted plain text on a hard drive with a few commands. A preferably unique string from the file you are trying to recover is needed.

First, use the strings command to dump all the text from a partition:

# strings /dev/sdXN > BigStringsFile

Then use grep to filter through the content of BigStringsFile:

$ grep -i -200 "Unique string in text file" BigStringsFile > GrepOutputFile
Note: The -200 option tells grep to print 200 lines of context from before and after each mach of the string. You may need to adjust this if the text you are looking for is very long.

Hopefully, the correct deleted data is now in GrepOutputFile.

See also