Forensicsdata recoveryforensicsbad blocksddrescuedisk imagingio errors

safecopy

Safecopy is a data recovery tool for problematic or damaged media that extracts as much data as possible by skipping bad areas and using low-level operations. It generates images similar to ddrescue and is useful for forensics and disaster recovery.

Description

Safecopy is designed to rescue data from sources causing IO errors, such as floppy disks, hard disk partitions, CDs, DVDs, and tape devices where tools like dd fail. It identifies damaged areas, skips them, and fills corresponding destination areas with zeros or a recognizable pattern. This makes it valuable in forensics investigations and disaster recovery scenarios.

The tool employs an incremental algorithm to precisely locate the beginning and end of bad areas, balancing minimal access to damaged sectors with thorough data recovery. Multiple passes can be performed, starting with fast recovery of most data and progressing to more aggressive attempts on remaining unreadable sections.

Safecopy includes a low-level I/O layer for raw CDROM reading, device resets, and other operations on specific device classes, enhancing recovery from hardware failures.

How It Works

Safecopy uses an incremental algorithm to detect exact boundaries of bad areas, skipping them with configurable block sizes and resolutions. It supports multiple passes via badblock files, low-level device calls (e.g., CDROM raw reads, resets), retries, head realignment seeks, and synchronized reads. Unrecovered areas are zero-filled or marked, with output symbols indicating progress like successful reads (.), skips (X), and backtracking (<).

Installation

bash
sudo apt install safecopy

Flags

--stage1Preset to rescue most data fast, no retries, avoiding bad areas. Presets: -f 10% -r 10% -R 1 -Z 0 -L 2 -M BaDbLoCk -o stage1.badblocks
--stage2Preset to rescue more data, no retries but searches exact ends of bad areas. Presets: -f 128* -r 1* -R 1 -Z 0 -L 2 -I stage1.badblocks -o stage2.badblocks
--stage3Preset to rescue everything possible using maximum retries, head realignment, low-level access. Presets: -f 1* -r 1* -R 4 -Z 1 -L 2 -I stage2.badblocks -o stage3.badblocks
-b <size>Blocksize for default read operations. Default: hardware block size or 4096
-f <size>Blocksize when skipping badblocks. Default: 16*
-r <size>Resolution when searching exact beginning/end of bad areas. Default: 1*
-R <number>Minimum read attempts on first bad block. Default: 3
-Z <number>Force seek read head from start to end on each error. Default: 1
-L <mode>Low level device calls: 0=off, 1=error recovery, 2=always. Default: 1
--syncUse synchronized read calls (O_DIRECT or O_SYNC)
--forceopenKeep trying to reopen source after read error (e.g., USB)
-s <blocks>Start position. Default: 0
-l <blocks>Maximum length to read. Default: entire input
-I <badblockfile>Incremental mode using existing badblockfile
-i <bytes>Blocksize for -I badblockfile. Default: -b size
-c <blocks>Continue copying at position
-X <badblockfile>Exclusion mode, overrides -I blocks
-x <bytes>Blocksize for -X badblockfile
-o <badblockfile>Write badblocks compatible bad block file
-M <string>Mark unrecovered data with string instead of zeros
--debug <level>Enable debug output with bitfield level. Default: 0
-h | --helpShow help text

Examples

Basic usage: copy from source to target with recovery options
safecopy [options] <source> <target>
Fast first pass to rescue most data, outputs stage1.badblocks
safecopy --stage1 /dev/sdX image.img
Second pass searching exact bad area ends, outputs stage2.badblocks
safecopy --stage2 -I stage1.badblocks /dev/sdX image.img
Aggressive final pass with max retries and low-level access
safecopy --stage3 -I stage2.badblocks /dev/sdX image.img
Incremental recovery using existing badblocks, generates new list
safecopy -I badblocks.txt -o newbadblocks.txt /dev/cdrom image.iso
Custom blocksizes and low-level calls for floppy recovery
safecopy -b 2048 -f 10% -r 512 -L 2 /dev/fd0 floppy.img
Recover specific range starting from block 1000000
safecopy -s 1000000 -l 5000000 /dev/sda damaged_partition.img
Updated 2026-04-16kali.org ↗