Can ddrescue's sparse option facilitate cloning a drive to a smaller destination drive?
Solution 1:
Short general answer: no.
The --sparse
option writes a sparse file (image) in a filesystem that supports this feature. From Wikipedia:
A sparse file is a type of computer file that attempts to use file system space more efficiently when the file itself is mostly empty. This is achieved by writing brief information (metadata) representing the empty blocks to disk instead of the actual "empty" space which makes up the block, using less disk space. The full block size is written to disk as the actual size only when the block contains "real" (non-empty) data.
When reading sparse files, the file system transparently converts metadata representing empty blocks into "real" blocks filled with zero bytes at runtime. The application is unaware of this conversion.
I use sparse files as images a lot, mainly with dd
. It's true you can save some space and you can optimize for that (see my answer to another question; note that if you use ddrescue
because you suspect your drive to be faulty, or you do forensics or data recovery, then you shouldn't "optimize" it this way). It is also true that sparse image may be small enough to be saved even on substantially smaller partition, but this is not cloning; this is just saving a large file in a clever way.
A sparse file that exists inside a filesystem on a disk can be the right way to store the data, because you can mount the underlying partitions and work with them (at least in Linux, Windows seems not that smart; some useful tools: kpartx
, mount -o offset=…
). Still neither the file nor the disk that holds it can replace your source drive in BIOS/UEFI – I mean you cannot boot from it and run the operating system that was on the source drive (unless with virtualization, I guess). To boot you need to truly clone one device to the other. In this case there is no filesystem layer that understands sparse files, so you need your target drive to be at least as big as the source drive. (Surprisingly even a larger drive may cause some trouble: secondary GUID Partition Table is supposed to be at the very end; simple cloning to a larger drive will place it in a wrong position.)
In short: if you need to clone in order to replace one disk with the other and boot from the latter or use Windows with it – then the "sparse file" concept won't help you. On the other hand if you want to archive the data, metadata, partition table, MBR, all together, then creating a sparse file is a way to go. The sparse file will also be a good idea as a temporary storage if you plan to indirectly clone to a large enough disk later.
To fit all your data onto a smaller disk that will replace the source one, you need a tool that understands partitions and filesystems, with ability to shrink them. (So strictly speaking this would not be cloning either.) ddrescue
is not such a tool.
Two scenarios where ddrescue
or dd
may successfully copy the data to a smaller disk:
- There is unpartitioned space at the end of the source disk, so all partitions fit into the target.
- Some partitions (irrelevant to the boot process, if any) won't fit, but you plan to discard them (remove from partition table) from the target drive anyway.
Neither of these scenarios has anything to do with sparse files.