Skip to content

Safecopy

Safecopy is a command-line data recovery tool that copies from failing or damaged storage devices by skipping problematic areas and using incremental passes to minimize further damage, making it suitable for live Linux sessions where you need to image a dying drive safely.

Alternatively, you may utilize the rTS Debian live media created in this guide which already comes with Safecopy pre-installed.

Information

safecopy is one of the preinstalled packages for our r/Techsupport Rescue Media. If you are using this live image, you can skip the installation section.

How to install Safecopy

Refer below for installation instructions if you are not using our live image or want to install it on your own system.

Installing Safecopy

Debian / Ubuntu / Linux Mint:

Terminal window
sudo apt update && sudo apt install safecopy

Fedora / RHEL / CentOS / AlmaLinux:

Terminal window
sudo dnf install safecopy

Arch / Manjaro / CachyOS:

Terminal window
sudo pacman -Syu safecopy

Safecopy reads from a source (failing disk/partition) to a destination (image file or another disk) by jumping over bad areas with adjustable skip sizes and retries, then backtracking precisely to find readable edges.

It supports multiple passes: start fast to grab good data, then incremental runs on bad areas only.

Important: Identifying the source and destination drives

Section titled “Important: Identifying the source and destination drives”
Caution

Read this section very carefully before using any form of data recovery software!

Please refer to this guide on how to identify your drives in Linux: How to identify failing drives in Linux.

Always double-check which drive is source and which is destination before running safecopy, because mixing them up can destroy your only copy of the data.

The canonical simple pattern is: first quick pass with no retries to grab all easy data, then optional later passes to retry bad areas.

Example: source /dev/sdX, destination image /mnt/backup/disk.img

Terminal window
sudo safecopy -f 10% -R 0 /dev/sdX /mnt/backup/disk.img -o stage1.badblocks

This command tells safecopy to:

  • -f 10%: Skip 10% of the drive when it encounters a bad area, which allows it to quickly bypass large unreadable regions.
  • -R 0: Do not retry bad areas on the first pass, to avoid getting stuck.
  • -o stage1.badblocks: Output a list of bad blocks encountered during this pass, which can be used for targeted retries later.

Stage presets:

Safecopy has built-in presets for progressive recovery.

StageCommandPurpose
1 (Quick)sudo safecopy /dev/sdX /mnt/backup/disk.img --stage1Grabs most data quickly, outputs stage1.badblocks
2 (Strict)sudo safecopy /dev/sdX /mnt/backup/disk.img --stage2Finds exact bad area edges using stage1.badblocks
3 (Deep)sudo safecopy /dev/sdX /mnt/backup/disk.img --stage3Maximum retries/low-level access on remaining bad blocks

Naturally the higher the stage, the more time it will take, but it can recover more data from bad areas. You can also customize the parameters for each stage further if needed.

This is an example of a custom command that allows 1 retry with a smaller skip size on bad areas:

Terminal window
sudo safecopy -f 1* -r 1* -R 3 -Z 1 -I stage1.badblocks /dev/sdX /mnt/backup/disk.img -o stage2.badblocks

This command tells safecopy to:

  • -f 1*: Reduce the skip size to 1% for retries,
  • -r 1*: Allow 1 retry on bad areas,
  • -R 3: Allow up to 3 retries on bad areas,
  • -Z 1: Enable low-level access for retries,
  • -I stage1.badblocks: Use the list of bad blocks from the first pass to focus retries on those areas,
  • -o stage2.badblocks: Output a new list of bad blocks after this pass, which can be used for further passes if needed.

To spot corrupted files later: add -M BaDbLoCk (fills unreadable areas with pattern).

Example:

Terminal window
sudo safecopy --stage1 -M BaDbLoCk /dev/sdX disk.img

Then run:

Terminal window
grep -r BaDbLoCk /mnt/image_mount # Do after mounting image.
Warning

Using -M with -I may overwrite prior data in targeted blocks. Use with caution and only if you understand the implications.

Running Safecopy: Cloning directly disk-to-disk

Section titled “Running Safecopy: Cloning directly disk-to-disk”

Sometimes you want a clone on another physical drive rather than an image file. The command is similar, but the destination is a disk instead of an image. Do note this method is riskier because if you accidentally choose the wrong destination disk, you could overwrite important data.

Terminal window
sudo safecopy --stage1 /dev/sdX /dev/sdY

Where /dev/sdX is the failing source disk and /dev/sdY is the healthy destination disk (must be same size or larger). The format is similar to the image cloning method, but you specify a disk instead of an image file as the destination.

The same commands for retries and marking bad blocks can be used in disk-to-disk cloning as well, just replace the destination image with the destination disk.

After cloning: Working with the image or clone

Section titled “After cloning: Working with the image or clone”

Once you have an image or clone, you generally stop touching the failing disk and work only on the image or clone. You can mount the image, run filesystem checks, or use recovery tools like testdisk or photorec on the image or clone to try to recover files.

Always keep the original failing disk untouched after cloning to preserve it as a last resort if needed.