Python ddrescue-based hard disk recovery tool, but only recovers used filesystem space. For a useful guide on hard disk recovery, see this DIY hard disk recovery guide
Uses several techniques to try to recover only used parts of hard disks instead of the whole disk.
- First tries to clone supported filesystems using the relevant clone tool, see Filesystem support below
- If clone is successful, later unnecessary operations are skipped
- Starts a disk trace to record accessed hard disk blocks
- Reads and checks the partition table giving the user the option to repair using testdisk
- Scans each filesystem found to detect metadata blocks using fsck or similar
- Transfers the partition table and metadata to the image using ddrescue
- Finds used data blocks either directly like du, or indirectly by finding free space
- Transfers the data to the image using ddrescue
- Optionally diffs the source and destination filesystems to validate itself
- ddrescue stages are resumable
- Download using:
git clone https://github.com/racitup/ddrescue_used.git
cd ddrescue_used
chmod u+x ddrescue_used.py
./ddrescue_used -h
to print a list of dependency problems (if any) and usage help- The tool must be run as root (sudo) since it uses Linux commands that only root can run, such as mount
The destination filesystem should support both sparse files and compression, like btrfs. Ensure you have sufficient destination disk space. You should only need the same space as is used on the source disk, but more is better!
Attach the source disk as close as you can to the processor. By close I mean with as few bits of hardware in between as possible. I am currently testing a hard disk in a flakey USB3 caddy attached to a probably equally flakey USB3 hub. The caddy appears to get stuck in a read loop under heavy load. I would prefer to have the SATA disk attached directly to the motherboard by a SATA connection, but it does work well as a negative test case!
In Ubuntu (and probably many other distributions) filesystems will be automounted when they are attached and detected. This will interfere with tool behaviour and must be disabled:
- Install dconf-editor (
sudo apt-get install dconf-editor
) - Navigate to
org.gnome.desktop.media-handling
- Disable
automount
andautomount-open
This may also be configured in other places, e.g.:
Settings -> Removable Drives and Media -> Storage -> Removable Storage:
- Mount removable drives when hot-plugged
- Mount removable media when inserted
- Browse removable media when inserted
- Auto-run programs on new drives and media
- Auto-open files on new drives and media
These should all be unticked (disabled)
This tool is in Alpha testing.
The source disk is only ever used read-only, so the source data is safe. Please do not rely on the image created to be a reliable copy. Make use of the -d switch to diff the source with the image after the copy is created if you want to validate the image content. Beware this is very intensive and may take a long time! Use on failing hard disks at your own risk. If your data is valuable please use another recovery tool until this tool is properly validated. Testing with errored disks is ongoing.
The first thing the tool does is check for dependencies. It is only required to install the dependencies for the filesystems that you wish to recover.
Filesystem | Clone | Default Used Method | Notes |
---|---|---|---|
vfat | No | Free | |
ext2/3/4 | Yes | 2/3: Used, 4: Free | |
hfsplus | No | Free | |
ntfs | Yes | Used | |
xfs | Yes | Free | ** |
btrfs* | Yes | Free | **, Clone only supports metadata, data is transferred separately |
*btrfs support is restricted to single device filesystems. Multiple device filesystems are not supported and will cause the tool to fail. This is because the kernel uses the UUID to scan for sibling filesystems and gets confused when presented with the image which has an identical UUID. btrfstune -u has been tried to rectify this but at current moment causes filesystem corruption. There is no plan to enhance btrfs support.
**both btrfs and xfs give various mount and fsck errors, presumably due to UUID problems. I welcome feedback on solutions.
Filesystem support can be expanded if supported by Linux.
A utility called makedisk.py
is provided that will create a disk image for testing. Once created, attach the image to a loop device using losetup --partscan --find --show ./IMAGEFILE
and supply the loop device as the DEVICE
argument of ddrescue_used.
Usage:
./makedisk.py IMAGEFILE [FS1] [FS2]...
Please use the following command to create a log for reporting bugs. Note that this log may contain data from your disk that you may deem to be sensitive. Please sanitise as appropriate:
./ddrescue_used -kvvs DEVICE DISK.IMG DESTDIR 2> err.log
It is not recommended to pipe stdout to a file since the tool is at places interactive. Please paste stdout into a file separately if necessary. The -k option leaves log files in the destination which can also be useful for debugging.
Original work Copyright 2016 Richard Case
Everyone is permitted to copy, distribute and modify this software, subject to this statement and the copyright notice above being included.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM.