Is there a disk image file format that only store sectors which are filled (non empty)?

1

I have a 500GB hard drive that contains several NTFS partitions. I would like to create a single disk image of all partitions. My ultimate goal is to mount that drive later and scan it for possible file recovery.

I would like to know if there is a disk image file format that allow to "compress" the disk image (it would be smaller than the actual size of the drive) by only storing the sectors which are not empty. I only know about the ISO file format but AFAIK this is a raw copy of the disk. I could compress that image later (eg : using gz compression) but it would make the image unusable (non mountable) unless the actual image is fully uncompressed first.

I ask this because the used space of the drive is only about 80GB. If I open the disk using an tool (eg : HxD) I see that about almost all sectors beyond a certains point (about 65%) contains null bytes (those sectors are empty).

EDIT: I am on Windows 10.

tigrou

Posted 2019-10-31T19:13:24.547

Reputation: 759

2Any good hard drive imaging software does this by default. – Moab – 2019-10-31T19:36:35.397

@Moab : good to know. Does it work even if disk image format is ISO ? (if not what should I select ?). Will I still be able to mount the image afterwards ? – tigrou – 2019-10-31T20:00:29.810

They each have their own format. – Moab – 2019-10-31T21:12:32.063

Answers

2

Some imaging programs do have their own formats which are made sparse at format level, not at filesystem level. Common image formats used by VM software (VHD, VHDX, Qcow2) almost always support holding partial data, as part of the "dynamically growing disk image" feature.

The same formats can usually be used for imaging physical drives and restoring them back, without having to involve a VM at all. (For example Microsoft distributes Disk2Vhd for imaging a physical disk into a VHD(X) image, which can then be restored onto another physical disk with various tools.)

However, you specifically asked for a mountable image. What is mountable heavily depends on the OS: for example, Windows can natively mount VHD(X) images but not raw dd images, while Linux is the opposite and its "loop device" system only supports raw images.

(Not sure about macOS capabilities, but it also has its own .dmg format.)

So with current OS versions (and avoiding third-party tools) a good choice would be:

  • For Windows 7 or later – create a VHDX image using Microsoft Disk2Vhd.
  • For Linux in general – create a filesystem-sparse "raw" image using dd or cp or ddrescue, as mentioned in Kamil's post. Note that if you losetup and mount it, you can use fstrim (yes, the same fstrim as used with SSDs) to turn a non-sparse image into a sparse one.
  • For Linux when imaging an NTFS partition, you can also use ntfsclone which intelligently skips all areas which NTFS would consider "free", even if they happen to contain leftover non-zero data, allowing the image to be more sparse than what dd could produce. (This is what CloneZilla uses to create NTFS images as well.)

user1686

Posted 2019-10-31T19:13:24.547

Reputation: 283 655

2

Saving a raw image as a sparse file will automatically take advantage of sectors that are filled with zeros. Some possibilities in Linux:

  • dd conv=sparse (mind this)
  • ddrescue -S
  • cp --sparse=always

I don't know Windows tools. I know NTFS supports sparse files, so the general concept should work in Windows as well.


The method gets more effective if one overwrites the empty space with zeros first. By "empty space" I mean sectors not allocated to any file or metadata according to the filesystem(s) you want to store. But since your goal is to scan for possible file recovery, you shouldn't overwrite anything. This paragraph is for users interested in cloning/storing only non-deleted data.

Kamil Maciorowski

Posted 2019-10-31T19:13:24.547

Reputation: 38 429

Thanks for the answer. I did not specify the operating system because I thought (I was wrong) that it wasn't necessary (since i was asking for a file format, not a tool). I am on Windows 10. – tigrou – 2019-10-31T19:59:14.333

@tigrou Sparse files conceptually belong to filesystems (some filesystems support them, other filesystems don't). Windows is impaired (or "chauvinistic") when it comes to filesystems but AFAIK its beloved NTFS does support sparse files. – Kamil Maciorowski – 2019-10-31T20:14:48.967

0

All respectable backup products can create a disk image with only used sectors, but the format of the backup file not disclosed.

You may find a list of such products with reviews in the article Best Free Drive Cloning Software.

The product Clonezilla is open-source, so conceivably its format can be extrapolated from the sources (but what's the point).

harrymc

Posted 2019-10-31T19:13:24.547

Reputation: 306 093