Storage & Data Recovery ADVANCED Linux โฑ๏ธ 4 min read ๐Ÿ“… Updated: 13 Sep 2026

Advanced Data Recovery: Reconstructing Deleted Files from Overwritten Sectors using Foremost & Scalpel

This advanced guide details how to use forensic tools like Foremost and Scalpel on Linux to carve and reconstruct deleted files from raw disk images, even when the file system structure has been overwritten.

Gurveer Singh
Gurveer Singh โœ“ Verified Specialist
Founder & Chief Architect ยท hSECURITIES Labs
โšก FAST-TRACK PROTOCOL

Direct Diagnostic & Remediation Summary

  • Preparation: Create a bit-for-bit image of the suspect media (e.g., dd if=/dev/sdX of=disk_image.img bs=4M).
  • Foremost Run: Execute Foremost against the raw image to carve known file headers: foremost -t {file_types} -i disk_image.img -o output_dir.
  • Scalpel Run: Use Scalpel for targeted recovery based on specific file signatures: scalpel /t /k /o output_dir disk_image.img.
๐Ÿ› ๏ธ Tools & Prerequisites: A Linux environment (Ubuntu/Kali recommended), administrative root privileges, the suspect storage media (External Drive, USB Stick, SSD) connected read-only, and the following tools installed: foremost, scalpel, and dd.
๐Ÿ” Root Cause & Diagnostic Overview:When files are deleted on NTFS or FAT32 file systems, the operating system typically only removes the pointer (metadata) in the Master File Table (MFT) or directory structure. The actual data blocks remain until they are overwritten by new data. If sectors have been partially overwritten, standard OS recovery tools fail because they rely on intact filesystem journals. Forensic carving tools like Foremost and Scalpel bypass the file system entirely, reading raw data signatures (headers/footers) to reconstruct files block-by-block, treating the entire disk image as a continuous stream of bytes.
Warning: This process is destructive if run on the original media. ALWAYS work on a bit-for-bit forensic copy (image).
STEP 1

Imaging the Suspect Media (The Golden Rule)

Never run recovery tools directly on the source drive. The first step is creating a forensic image using dd. This captures every bit, including empty or corrupted sectors.

  • Identify Device: Use lsblk to correctly identify the device name (e.g., /dev/sdb, not a partition like /dev/sdb1).
  • Execute Imaging Command: Run dd. Replace /dev/sdX with your actual disk identifier and output_image.img with your desired filename.
  • sudo dd if=/dev/sdX of=output_image.img bs=4M status=progress conv=noerror,sync
STEP 2

Foremost Execution (Signature-Based Carving)

Foremost reads the image sequentially and attempts to identify known file headers, carving out data chunks based on predefined signatures. It is excellent for recovering common file types.

  • Determine Types: Check Foremost documentation for supported types (e.g., jpg, doc, zip).
  • Run Command: Execute Foremost against the image. The -t flag specifies file types, and -o sets the output directory.
  • sudo foremost -t jpg,pdf,zip -i output_image.img -o ./foremost_recovery
  • Review Output: Files will appear in the foremost_recovery directory, categorized by type.
STEP 3

Scalpel Execution (Advanced Signature Matching)

Scalpel is often more precise than Foremost because it allows the user to customize the header signatures (.scalpel.conf). This step assumes you have customized a configuration file for specific, unique data patterns.

  • Configure Scalpel: Ensure your .scalpel.conf file contains the correct header signatures (e.g., for a proprietary database format).
  • Run Command: Execute Scalpel using the configuration file, targeting the image.
  • sudo scalpel -c /path/to/.scalpel.conf -o ./scalpel_recovery output_image.img
  • Analyze Results: Check the scalpel_recovery directory for reconstructed files matching your signatures.
TROUBLESHOOTING

Common Pitfalls & Advanced Diagnostics

If recovered files are corrupted or incomplete, the issue is usually:

  • Pitfall: Partial Overwrite: If data was overwritten in the middle of a file, carving tools cannot magically restore it. The resulting file will be truncated at the point of overwrite.
  • Diagnostic: File Size Mismatch: Compare the recovered file size against expected sizes or metadata (if available from another source). A significant mismatch confirms data loss due to overwriting.
  • Pitfall: Incorrect Signature: If Scalpel fails, the custom signatures in .scalpel.conf are incorrect for the target file type or version.
  • # Common fix: Try different block sizes (bs) with dd if sequential reading is suspect.
    dd if=/dev/sdX of=output_image.img bs=1M conv=noerror,sync
    
FINAL STEP

Verification, Results & Long-Term Stability Validation

After recovery, rigorous validation is necessary. Do not trust the files immediately.

  • Internal Integrity Check: Attempt to open every recovered file using its native application (e.g., Image Viewer for JPG, Word Processor for DOCX). If the program reports corruption, the data loss occurred before recovery.
  • Hashing Comparison (If Possible): If you have a known good version of the file, calculate its SHA256 hash and compare it to any metadata hashes recovered. A match confirms perfect reconstruction.
  • Prevention: For critical data, implement immediate offline backups (3-2-1 Rule). Regularly run disk surface scanners (badblocks) on active drives to preemptively find bad sectors before they become unrecoverable.
Resolution Complete: You have successfully utilized forensic carving techniques. Foremost and Scalpel reconstruct files by signature, bypassing the damaged file system structure. If critical data remains inaccessible, professional hardware/data recovery labs employing specialized firmware analysis may be required.
COMMAND LINE / TERMINAL
sudo dd if=/dev/sdX of=output_image.img bs=4M status=progress conv=noerror,sync
sudo foremost -t jpg,pdf,zip -i output_image.img -o ./foremost_recovery
sudo scalpel -c /path/to/.scalpel.conf -o ./scalpel_recovery output_image.img

Frequently Asked Questions

Can I use these tools on an SSD instead of a mechanical HDD?

Yes, but be extremely cautious. Due to wear-leveling and TRIM commands, data recovery from SSDs is significantly more complex and often requires specialized vendor tools or write-blockers that understand the NAND architecture.

What if I don't know the file type signature?

You must use a Hex Editor (like HxD or Bless) to manually examine a known good sample of the file type you are looking for, and then determine its unique starting byte sequence (the header magic number) to write into your Scalpel configuration file.

Is it safe to run these commands on my primary working drive?

Absolutely not. Always use a hardware write-blocker device or boot from a read-only Live USB environment (like Kali Linux).

Engineering Assistance

Need help implementing this solution?

Our cybersecurity and infrastructure engineers can audit, harden, or configure your systems directly.

Request Technical Assistance โ†’
Gurveer Singh
Gurveer Singh โœ“ Verified Author
Founder & CEO at hSECURITIES | Cybersecurity Educator | Security Researcher | Ethical Hacking Enthusiast | Technology Mentor
Meet the Founder โ†’

Gurveer Singh Saggu is the Founder and CEO of hSECURITIES, a cybersecurity and technology education platform focused on practical learning, digital security awareness, hardware diagnostics, Linux administration, and real-world cybersecurity training.

With a strong passion for technology, ethical hacking, and security education, he has spent years helping students, professionals, and organizations understand modern cyber threats and develop practical technical skills. Through hSECURITIES, he creates hands-on learning resources, technical guides, security awareness content, and community-driven initiatives that make cybersecurity more accessible.

His mission is to bridge the gap between theoretical knowledge and practical implementation by providing step-by-step learning experiences, technical troubleshooting resources, and security-focused educational platforms.

Community Discussion & Confirmations (0)

Technical questions, hardware findings, and verified fix reports.

No reader questions posted yet. Have you tried this solution or experienced an edge case? Post below.

Ask a Question or Share Solution