🛠️ Real incident, fixed with AI

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.

In short

A recovery got dangerous because imaging started with no full device list and no GNU ddrescue mapfile. A later copy used hand-built byte offsets, long similar filenames, and a bad destination. A large seek at the wrong NTFS file tried to create a huge file and failed with No space left on device. Inventory the disks, then use ddrescue with a mapfile. Do that before any write.

What you need

The recovery media was not shown to be the cause of the original failure. Reads that work, and a clean SMART report, describe what you see now. They do not prove the root cause.

Name every disk before you write

  1. Stop writes. Keep every source device as it is.
  2. Record model, capacity, and serial for every disk before you change mounts or run recovery tools.
  3. Leave source volumes unmounted. While you identify and check them, mount the destination read-only too.
  4. Record the exact source size and the current partial-image size. Subtract. Do not estimate.
lsblk -o NAME,MODEL,SIZE,SERIAL,FSTYPE,MOUNTPOINTS
blockdev --getsize64 "$SOURCE_DEVICE"
stat --format='%s' "$PARTIAL_IMAGE"
missing_bytes = exact_source_bytes - partial_image_bytes

If a size or a serial is not what you expect, stop. Disk order, size alone, or a familiar filename is not an identity.

Use a mapfile, then check the write

GNU ddrescue’s mapfile records what is already copied so you can resume. Follow the GNU ddrescue manual. Do not switch to dd just to merge pieces. Any merge needs a plan you can run twice without clobbering bytes you already saved.

  1. Point short variables at the devices and print them:
SRC=/dev/source-device
DST=/recovery/destination-image
MAP=/recovery/recovery.map
printf 'SOURCE=%s\nDESTINATION=%s\nMAPFILE=%s\n' "$SRC" "$DST" "$MAP"
  1. Before any write, check on your own that SRC is the input and DST is the output, the destination path and file size are right, the destination disk and free space are right, the offset and byte count match missing_bytes, and the mapfile belongs to this pair.

Warning: reversing infile and outfile can overwrite the source, write a huge amount, or fill the disk. A large seek at the wrong NTFS name can also ask for a giant allocation and return No space left on device. If that happens, do not “fix” it with another write. Stop, sync, unmount, and go back to the inventory.

  1. Require the same three paths a second time before the write:
test "$CONFIRM_SOURCE" = "$SRC" &&
test "$CONFIRM_DESTINATION" = "$DST" &&
test "$CONFIRM_MAPFILE" = "$MAP"

Run one dangerous command at a time. Say what it should print, look, and do not run the next command if the output differs.

When to stop

Stop all writes if the device is not the one you named, you see No space left on device, a name or size does not match, an offset does not match the plan, or you are unsure.

Then sync, unmount, keep the logs and the mapfile, and start again from the inventory and the recorded sizes.

Do not cat an unknown log into the terminal. Check its file type and encoding first, then use a viewer with a length limit. Piping binary data to a terminal can scramble the display even when the file was opened read-only.

If it doesn’t work

Official sources

Spot something wrong or outdated? Leave a comment below. Every comment is reviewed to keep these posts accurate.

By commenting, you agree to our Terms of use and confirm this is your own work. Short quotes are fine with a credit and link. Copied, unsafe, or abusive comments are removed. See something copied? Say so here.