I'm curious to know the difference between these two commands in Linux:
$ cat ./boot.bin ./kernel.bin /dev/zero | dd bs=512 count=2880 of=devos.img
and
$ cat ./boot.bin ./kernel.bin > devos.img
I'm curious to know the difference between these two commands in Linux:
$ cat ./boot.bin ./kernel.bin /dev/zero | dd bs=512 count=2880 of=devos.img
and
$ cat ./boot.bin ./kernel.bin > devos.img
dd copies exactly count blocks of bs bytes, or 2880*512 bytes in total in this case(but see below). That will truncate or pad the concatenation of the two files to a fixed size (since /dev/zero gives as many zero bytes as required). 1440 kB is looks like the size of a 3.5" HD floppy disk, so perhaps someone wanted to make images that fit the floppy exactly.
The plain cat on your second example will just concatenate the files, and the result will of whatever size it is.
Smaller example:
$ echo hello > a; echo world > b
$ cat a b | od -c
0000000 h e l l o \n w o r l d \n
$ cat a b /dev/zero | dd bs=1 count=8 2>/dev/null | od -c
0000000 h e l l o \n w o
$ cat a b /dev/zero | dd bs=1 count=16 2>/dev/null | od -c
0000000 h e l l o \n w o r l d \n \0 \0 \0 \0
Actually, dd will read and write less if it gets less data than the block size on a single read() call. This might happen with large block sizes but probably isn't an issue with 512 since cat will write the data in blocks of at least that size. In GNU dd, this can be prevented with iflag=fullblock.
We could do the same with head -c:
$ cat a b /dev/zero | head -c 16 ...