Recover Files from dd Image: Full Guide
Yes, you can recover files from a dd image, and the process is straightforward if you use the right tools. A dd image is a raw, bit-for-bit copy of a storage device, so it contains all the file system structure and data you need to extract individual files or entire directories. This guide explains how to mount the image, recover deleted files, and handle common issues.
What Is a dd Image?
dd is a command-line utility available on Unix-like systems (Linux, macOS) that copies data from a source to a destination at the block level. It reads and writes raw data, ignoring file system boundaries. A dd image is a single file that contains an exact replica of the original device—including the partition table, boot sector, file system metadata, and all file contents. Because it is a raw copy, the image can be mounted and analyzed just like a physical disk.
Common uses for dd images include:
- Forensic analysis and evidence preservation
- Backup of a complete disk or partition
- Recovering data from a failing drive (after creating the image)
- Cloning a system to new hardware
How to Mount a dd Image and Copy Files
If the dd image contains a file system (e.g., ext4, NTFS, FAT32), you can mount it as a loop device and copy files normally. This works for both whole-disk images and partition images.
- Identify the partition offset (if the image is of a whole disk). Use
fdisk -l image.ddto list partitions and their start sectors. Multiply the start sector by 512 (sector size) to get the byte offset. - Mount the image with the offset:
sudo mount -o loop,offset=1048576 image.dd /mnt/recovery
(Replace1048576with your computed offset. For a partition-only image, omit the offset.) - Copy files from
/mnt/recoveryto a safe location usingcp,rsync, or your file manager. - Unmount when done:
sudo umount /mnt/recovery.
If the file system is damaged, mounting may fail. In that case, use recovery tools that read the image directly.
Recovering Deleted Files from a dd Image
Deleted files are not immediately erased from the file system; only the directory entry is removed, and the space is marked as available. To recover them, you need a tool that scans the raw image for file signatures or file system metadata.
- PhotoRec – A free, cross-platform tool that scans for file signatures (carving) and recovers files even when the file system is corrupt. It works directly on the dd image.
- testdisk – Often used to repair partition tables, but it can also recover deleted files from FAT, NTFS, ext2/3/4, and other file systems.
- extundelete – For ext3/ext4 file systems, it can recover files by inode information.
- foremost – Another file-carving tool that works on raw images.
Example using PhotoRec:
photorec image.dd
Follow the interactive menu to select the file types and destination folder. PhotoRec will save recovered files with generic names, so you may need to sort them by type or content.
Choosing the Right Recovery Method
Your choice depends on the state of the file system and what you need:
- File system intact – Mount the image and copy files normally. This is fastest and preserves names and folder structure.
- File system damaged or deleted files – Use a recovery tool like PhotoRec or testdisk. These scan the raw data and can recover files even if the file system is unreadable.
- Whole disk image with multiple partitions – You can mount each partition separately using the correct offset, or use tools that handle partition tables automatically (e.g.,
kpartx).
Always recover to a different physical disk than the one the image came from, to avoid overwriting data.
Common Problems and How to Fix Them
- Mount fails with “wrong fs type” – The image may be a whole disk, not a partition. Use
fdiskto find the offset, or trymount -o loop,offset=...with the correct value. - Image is compressed – If the image was compressed (e.g.,
dd | gzip), decompress it first:gunzip image.dd.gz. Alternatively, use tools that support compressed images, likeguestfish. - File system is encrypted – You must decrypt the image first (e.g., with
cryptsetupfor LUKS) before mounting or recovering. - Recovered files have generic names – File carving tools often lose original names. Use metadata (timestamps, content) to identify them.
- Image is larger than the destination disk – You can still mount it and copy files, but you cannot restore the entire image to a smaller disk.
Comparison of Recovery Tools
| Tool | Best For | File System Support | Cost |
|---|---|---|---|
| PhotoRec | File carving, corrupt file systems | Many (FAT, NTFS, ext, HFS+, etc.) | Free |
| testdisk | Partition recovery, deleted files | FAT, NTFS, ext2/3/4, and more | Free |
| extundelete | Deleted files on ext3/ext4 | ext3/ext4 | Free |
| foremost | File carving from raw images | File-type signatures | Free |
For most users, PhotoRec is the most reliable free option because it does not rely on the file system structure.
Best Practices and Safety Considerations
- Never mount a dd image read-write unless you intend to modify it. Use
mount -o ro,loopto avoid accidental changes. - Work on a copy if the original image is critical, because some recovery tools may modify the image.
- Use a separate storage device for recovered files to prevent overwriting the image.
- Verify the image integrity with
md5sumorsha256sumbefore and after recovery to ensure no corruption. - For forensic cases, follow legal procedures and use write-blockers when creating the image.
Alternatives to dd for Imaging
While dd is universal, other tools offer compression, progress display, and error handling:
- ddrescue – Designed for failing drives; it skips bad sectors and retries, and can resume interrupted copies.
- Clonezilla – A disk-imaging tool that compresses data and supports many file systems.
- GNU ddrescue – Not to be confused with dd; it is more robust for recovery.
These tools create images that are often compatible with the same recovery methods described above.
Frequently Asked Questions
Can I mount a dd image on Windows?
Yes, you can use tools like OSFMount or 7-Zip (which can extract files from raw images). Alternatively, use a Linux live USB to mount the image with standard tools.
How do I find the partition offset in a dd image?
Use fdisk -l image.dd on Linux. Look for the “Start” column; multiply that number by 512 (sector size) to get the byte offset for mounting.
Can I recover files from a dd image of a failing hard drive?
Yes, but you should first create the dd image using a tool like ddrescue to handle bad sectors. Then perform recovery on the image, not the physical drive.
Why do recovered files have no names?
File carving tools like PhotoRec identify files by their content signatures, not by the file system metadata. Original names are often lost. You can try to identify files by their type and content.
Is it possible to recover files from a dd image after formatting?
Yes, if the format was quick (not a full overwrite). The old data may still exist, and tools like PhotoRec can often recover it. However, if the disk was securely wiped, recovery is impossible.
Can I recover files from a compressed dd image?
Yes, you can decompress it first (e.g., gunzip), or use tools that support compressed images, such as guestfish or qemu-nbd with compression options.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.