linux - Hex of filesize

05
2014-04
  • Vigneshwaren

    I am following a tutorial on few kernel dev. I encountered an operation where I have to use dd like

    dd ... if=PBL.bin of=... count=block_number
    

    The block_number variable is defined to be as

    The HEX of ($filesize - 1)/512 + 1
    

    where $filesize is the filesize of the input file PBL.bin as given in the dd command above.

    How do I calculate this value? Thanks in advance

  • Answers
  • fede.evol

    What about:

    printf "%x" `stat -c "%b" PBL.bin`
    

    printf will print in hex format (%x) the output from stat which requests just the number of blocks allocated (%b) of the file.

    If you don't trust the number of blocks allocated as reported by stat then by hand:

    printf "%x" $(( (`stat -c "%s" PBL.bin ` - 1) / 512 + 1))
    

    So you get the filesize and then do the maths by hand


  • Related Question

    linux - What number of bytes should I set the bs to in the dd command?
  • ant2009

    I have just created a usb boot disk so that I can install Fedora 14.

    I used the following which was successfully. However, I am left wondering what does the bs parameter actually does. I know it mean bytes and copies these at a time. But how do I know what to set it to?

    dd if=F14-Live-i686.iso of=/dev/sdb bs=8M
    

    In the above example it is set to 8MB. However could I set this to any value that I want?

    Many thanks for any advice,


  • Related Answers
  • Journeyman Geek

    it stands for block size - its simply how many blocks are read and written at a time. Larger block sizes are faster, but if an error occurs, you'd need to redo the whole block

    The optimum blocksize apparently depends on the buffer size for a hard disk - no one seems to know for sure for a external drive

    I'd refer you to this and this for further reference