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
- Every source disk still untouched
- GNU ddrescue (not
dd, and notdd_rescue). Those are different tools. - A destination with free space you have already measured
- Short shell variables for the source, the image, and the mapfile
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
- Stop writes. Keep every source device as it is.
- Record model, capacity, and serial for every disk before you change mounts or run recovery tools.
- Leave source volumes unmounted. While you identify and check them, mount the destination read-only too.
- 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.
- 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"
- Before any write, check on your own that
SRCis the input andDSTis the output, the destination path and file size are right, the destination disk and free space are right, the offset and byte count matchmissing_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.
- 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
- You do not have a mapfile yet. Stop and start a ddrescue run that has one. Do not invent byte offsets by hand.
No space left on deviceappeared. The destination was wrong or too small. Unmount and recheck sizes before any other write.SRCandDSTlook similar. Print the variables and the serials again. Do not continue on filenames alone.- You were about to use
ddordd_rescueto merge. They are not GNU ddrescue. Stay with the mapfile plan. - A log looks empty or the terminal acts strange after you displayed a file. Treat that file as binary until you know its type.
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.