Managed with AI assistance. Reviewed by a human.
🛠️ Real incident

Preserving Evidence and Preventing Write Mistakes During Data Recovery

What went wrong during a data recovery attempt and how to avoid destructive writes next time.

Preserving Evidence and Preventing Write Mistakes During Data Recovery

What went wrong

The recovery process became riskier than necessary because imaging began without a complete device inventory and a GNU ddrescue mapfile. A custom copy was later combined with manually reconstructed byte offsets. Long, similar filenames and insufficient source/destination checks made it possible to target the wrong output. A large seek against an unintended NTFS file then attempted to create or allocate an enormous file and failed with No space left on device.

The recovery media was not proven to be the cause of the original failure. Successful reads and a clean SMART report are evidence about current observations, not proof of root cause.

Preserve first

  1. Stop writes and preserve every possible source device.
  2. Identify every device by model, capacity, and serial before changing mounts or running recovery tools.
  3. Keep source volumes unmounted and inactive. During identification and verification, mount the destination read-only as well.
  4. Record the exact source size and the current partial-image size. Calculate the missing byte range explicitly rather than estimating it.

Useful read-only checks include:

lsblk -o NAME,MODEL,SIZE,SERIAL,FSTYPE,MOUNTPOINTS
blockdev --getsize64 "$SOURCE_DEVICE"
stat --format='%s' "$PARTIAL_IMAGE"

Record the calculation:

missing_bytes = exact_source_bytes - partial_image_bytes

If any value or identity is unexpected, stop. Do not infer device identity from enumeration order, capacity alone, or a familiar-looking filename.

Prefer a planned ddrescue workflow

Use GNU ddrescue from the start, with a persistent mapfile and a documented sequence of passes. The mapfile records what has and has not been recovered, allows safe resumption, and avoids manual byte-offset reconstruction. Follow the official GNU ddrescue manual when designing the workflow.

GNU ddrescue, dd, and dd_rescue are different tools with different behavior. Do not substitute dd merely to merge recovered data. Any merge or continuation must have a verified, idempotent plan that preserves already recovered regions.

Preflight every write

Use short variables instead of long, visually similar filenames in manually typed commands:

SRC=/dev/source-device
DST=/recovery/destination-image
MAP=/recovery/recovery.map
printf 'SOURCE=%s\nDESTINATION=%s\nMAPFILE=%s\n' "$SRC" "$DST" "$MAP"

Before issuing a write, independently verify:

The infile/outfile direction is safety-critical. Reversing it can attempt a huge write, overwrite valuable data, or exhaust the destination. A large seek to the wrong NTFS output filename can similarly request enormous allocation and produce No space left on device.

Use an explicit confirmation gate before any write:

test "$CONFIRM_SOURCE" = "$SRC" &&
test "$CONFIRM_DESTINATION" = "$DST" &&
test "$CONFIRM_MAPFILE" = "$MAP"

Run only one dangerous command at a time. State its expected output first, check the result, and do not provide or execute the next command if reality differs. This is especially important when guiding a stressed operator.

Stop conditions

Stop all writes immediately if any of these occur:

Then sync pending writes, unmount safely, preserve logs and mapfiles, and reassess from the inventory and recorded sizes. Do not improvise a corrective write while the state is unclear.

Do not display unknown logs directly in a terminal. Determine their file type and encoding first, then use an appropriate bounded viewer. Piping binary data to a terminal can disrupt its display even when the underlying file is opened read-only.

Prevention