-1

I have destination drive which I know is partitioned in 512b sectors. I want to transfer let's say 150b file with dd to this drive at a given destination, let's say start sector 2099200, and then to read exactly the same amount of bytes as the file size (150b) from the same location sector. I tried something like this:

sudo dd if=my.txt of=/dev/sdb obs=512 seek=2099199

sudo dd if=/dev/sdb of=my.txt obs=150 count=1 ibs=512 skip=2099199

It almost works but I can't make it transfer only 150b:

1+0 records in 3+1 records out 512 bytes (512 B) copied

What is wrong and how to do what I need? May be I get it wrong and some other solution would be better, but I need to be file system independent.

Nikolay
  • 1,111
  • 2
  • 12
  • 16

1 Answers1

2

From the man page:

count=BLOCKS
   copy only BLOCKS input blocks

When you copy the file back from the drive, you are copying 512 bytes because you specify the input to be copied in 512 byte blocks with the ibs option and you copy one whole block with the count option. Instead, you could just specify the number of blocks you wish to copy as your ibs value:

sudo dd if=/dev/sdb of=my.txt ibs=150 count=1 skip=2099199

EDIT: As pointed out in the comments, this method would require recomputing the skip value. An alternative would be this:

sudo dd if=/dev/sdb ibs=512 count=1 skip=2099199 | dd count=150 of=my.txt
Aaron Okano
  • 2,243
  • 1
  • 12
  • 5
  • Except with a different `ibs`, the `skip` number needs to be recalculated, too, and there's no guarantee that the particular input block he wants is aligned... – twalberg Nov 20 '13 at 17:50
  • It worked but like this: sudo dd if=/dev/sdb ibs=512 count=1 skip=2099199 | dd ibs=150 count=1 of=my.txt – Nikolay Nov 21 '13 at 14:11