backup then restore when drive sizes differ
Solution 1:
-
Do not use
dd conv=noerror,sync
unless you know what you're doing. -
If you suspect your source drive may be faulty then use GNU
ddrescue
. If you don't wantddrescue
and you know the drive is good then usedd
orcat
, orpv
, orcp
, or whatever. -
Your target disk is way larger and you're not going to boot from it. Create a filesystem there, mount it. Then write to a regular file in the filesystem. The filesystem may be NTFS and you may use it for other files as well. If there is already a filesystem you were going to destroy, maybe you don't need to destroy it. The point is: you don't need the whole disk, you can write to a regular file.
If all you know is Windows, the ability to simply copy the content of a block device to a regular file (or the other way around) may seem weird. Spend some time in Linux and you will find it natural. More insight here: A layman's explanation for "Everything is a file" — what differs from Windows? Especially this answer where it elaborates on "Drives vs Device Files".
-
The regular file you're going to write may take less space in the filesystem. See Clone only space in use from hard disk for few (optional) ideas.
-
When the time comes, restore with
ddrescue
ordd
, orcat
, orpv
, orcp
, or … by reading from the regular file and writing to the original device.
However if you decide against a regular file and go for dd if=/dev/sda of=/dev/sdb …
(or equivalent command), and successfully copy /dev/sda
(smaller) directly to /dev/sdb
(larger), then sdb
will contain the exact copy of the data from sda
, plus some old content beyond the size of sda
. Later you can restore by just copying in the opposite direction and at some point you will get something like "no space left on device". This is expected and will only mean the copying process got to the end of the target (smaller) device, i.e. it transferred back the exact amount of bytes you wanted it to write, the whole size of the smaller device. The "excessive" capacity from the larger device won't get to the smaller device because there will be no space for it.