I want to write a file at various offsets into the partition

Partition /dev/part2 is mounted at /mypart

I tried the command below:

dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=0 count=15000
dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=15000 count=15000
dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=30000 count=15000

Are they doing what I want to do? Are they writing a file to the partition at offset 0, 15000K and 30000K?

At what offset is the file written if I omit seek from dd

dd if=/dev/urandom of=/mypart/aaa bs=1024 count=15000
  • Why? What are you really trying to do? – psusi Mar 8 '12 at 1:11

You can't "write a file" at an "offset into the partition" using dd this way -- you are just writing data into a file named "aaa" within the mounted file system on that partition.

"seek=" will indeed cause dd to lseek to the given position before beginning its writes -- that means that it will simply create a file called /mypart/aaa and lseek the given number of blocks into that file before writing.

If you omit "seek=", dd will write starting at the beginning of the file named "aaa".

| improve this answer | |
  • I see. If I write directly to the device file at an offset, I basically destroy the filesystem on the partition. I tried that already. So how do I write data to a file at a particular offset in the file system? See my original requirement above. – Ankur Agarwal Mar 7 '12 at 1:10
  • 4
    You're asking how to do something you can't do. Of course if you just write to some arbitrary location in the partition you will destroy it, and there is no API for telling a file system to write at an arbitrary location -- you don't even know if that location is available for data to be written in it and not, say, allocated for metadata. I must confess that I have no idea why you would want to be able to do this. – Perry Mar 7 '12 at 1:15
  • 1
    If you have a filesystem on a device (like partition), you should think that the fs "owns" that device and you shouldn't touch it except by going through the fs. – XTL Mar 7 '12 at 8:25

Re: "are they doing what I want to do"


strace dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=15000 count=15000

and see what system calls are being made.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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