Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
The slow device is a 1.8" hard-disk in a IBM Thinkpad X40. The 100 Mbit/s ethernet connection is faster than this hard-disk when writing. –  erik Feb 5 '13 at 6:15
    
@erik yes, those 4200 RPM Hitachi drives are not the fastest, but the bottleneck really is not in the the network bandwidth - the ssh encryption/decryption is, as X40's Pentium is not that fast. Also consider checking the drive with smartctl - the slowness can easily be due to hardware errors. Speaking from a recent experience here with exactly X40 - the drive plainly is too old and likely has experienced lots of thrashing. As a side note, you might also be interested in thinkwiki.org/wiki/CompactFlash_boot_drive –  peterph Feb 5 '13 at 11:46

If the overwritten/changed partitions were completely in the first part of the disk, and if nothing changed in the remaining disk, this would be safe. It is risky in any case. Why not just leave the restore running overnight?

share|improve this answer
    
Not possible to do this overnight, because the whole process might be done multiple times a day. –  erik Feb 5 '13 at 6:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.