Is it safe to only partially restore a disk image with dd

backupddhard-disk

I have saved my whole hard-disk with dd to an image file. The hard-disk contained some primary partitions formatted with ntfs, swap and ext4. I did it this way:

dd if=/dev/sda | ssh user@fastmachine "cat - > diskimage.img"

Then I have overwritten the first 5 to 6 GB of my hard-disk for testing purposes with a new system:

  1. I created a swap primary partition with 1.5 GB.
  2. I created an ext4 primary partition with 4 GB.

After testing the test system now I want my old system back. But my local hard-disk is very slow when writing. To save time and energy I want to only restore about 6 GB from the image. Is this enough and safe? Would it work? I would do it this way:

ssh user@fastmachine "dd if=diskimage.img bs=1M count=6000" | dd of=/dev/sda

Update—partially restoring test

It worked to only partially restore the hard-disk.

Update—speedtest of 1.8" pata hard-disk

I just testet the writing speed with

dd if=/dev/zero of=blub count=1000 bs=1M

And

ssh user@fastmachine "dd if=/dev/zero count=1000 bs=1M" | dd of=blub
  • First gave me 14.5 MByte/s as writespeed to my 1.8" hard-disk—not as bad as I thought
  • Second gave me 11.4 MByte/s = 91.2 Mbit/s ≈ 100 Mbit/s = speed of my ethernet connection

But: ssh over WLAN (wireless) only was 1,3 MByte/s! That was the problem.

ssh took 68 % cpu load when copying over ethernet, and only 20 % when copying over WLAN (wireless).

Conclusion: If I had a faster network and hard-disk/flash-drive I would use netcat (nc) to copy the data.

Best Answer

Theoretically this can work, there is a caveat though: you must not change the layout of the disk outside of the area you are intending to reconstruct. The important thing is what partitioning scheme was used on the disk. For MBR this is easy, since the data is contained in the first sector (and in headers of logical partitions). For GPT it is slightly more complicated - there are two copies of the partition data and they should match. Generally speaking, if your partition software supports it (e.g. gdisk does), use it to save the scheme data to a file and to restore it back in addition to the data.

Alternatively, if it is an option, consider putting both of the drives into the same computer since unless you have a rather unusual setup*), ssh will be the bottleneck in the data transfer.

*) a recent processor coupled to an extremely slow hard-drive like a very old or misconfigured ATA HDD, low-end flash device (memory card or flash disk) or anything connected over USB, running only v1.1, or specially patched version of OpenSSH.

Related Question