Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have a sparse file representing a block device, then how can I efficiently restore the file over a network? Ideally, I'd use rsync -S host:file /dev/sdb, but rsync won't write to block devices. I am using ssh host dd if=file | dd of=/dev/sdb, but that's not efficient as the zero bytes will come over the network and be written to the device. Can I use tar -S or cp --sparse=always somehow? Can I do this without storing the file locally (even temporarily)? Can sshfs recognise sparse files?

share|improve this question

migrated from serverfault.com Aug 3 '12 at 12:57

This question came from our site for system and network administrators.

I haven't tested it, but there is a write-devices patch to rsync, which would solve your problem. You can find the patch in the rsync-patches repository.

share|improve this answer

You can install the iSCSI Enterprise Target software and setup an iSCSI LUN from the sparse-file like so:

In /etc/iet/ietd.conf:

Target iqn.my.iscsi.test:disk1
        Lun 0 Path=/path/to/my/sparse_file,Type=fileio

Then initiate the target from the host you need to restore on. Since the target will show as a local device (eg. /dev/sdd), you can dd from that device to your local device.

share|improve this answer
How is this more efficient then what I have now? Once I use dd, won't it read and write the zero bytes? – Jayen Aug 3 '12 at 22:50
No more hassle from "middle man" programs. – Tim Aug 7 '12 at 16:01

Have you tried compressing/decompressing the data in flight? Batches of zeroes should compress well.

Actually, having thought about it again, it's very simple. On the remote host, create a pipe with mkfifo. scp/dd to that pipe as usual and cp --sparse=always from it to the actual target file.

Tested on my installation and it does produce a sparse file on output. Thanks for a nice question!

share|improve this answer
ssh will compress for me. that's not the issue. – Jayen Aug 3 '12 at 13:14

Your Answer


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.