Search code examples
linuxunixdd

Dd not working correctly?


I'm not too familiar with Linux so please forgive the ignorance. I'm trying to dump a file to a virtual floppy disk using the command:

dd if=a.out of=image bs=1024 count=1 conv=notrunc

It creates the image file with the exact same size of a.out (1kB). However on my friend's laptop, his image file is 1.5MB. His is correct (as said by my professor) however mine isn't. I even tried with his a.out file just to check and it produced the same, wrong results.

Any input on why this is and how to fix it?


Solution

  • It's likely your friend's target file was already 1.5M (or 1.44M for a normal floppy image). The notrunc means that it won't truncate the file before writing to it so that, if you write 1K to a larger file, only the first 1K is over-written and the rest remains as it was.

    If you want a 1.44M file to start with, you can create it first with:

    dd if=/dev/zero of=image bs=1440k count=1
    

    then use your command to overwrite the first bit of it.