When I read the man page for fallocate it is a little unclear (to me) whether it creates a file that to all intents and purposes is filled with zeros.
fallocate - preallocate space to a file
fallocate [-n] [-o offset] -l length filename
fallocate is used to preallocate blocks to a file. For filesystems which support the fallocate sys‐
tem call, this is done quickly by allocating blocks and marking them as uninitialized, requiring no
IO to the data blocks. This is much faster than creating a file by filling it with zeros.
I've run a few tests allocating disk space and reading it to see if there are any remnants of previous unwiped disk contents and did not see anything. But I'd really like to be sure!
fallocate -l 10M myfile.bin
xxd -a myfile.bin
0000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................
09ffff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
My understanding is that fallocate allocates space on the disk but mark the blocks as uninitialized, which the operating system can interpret as 0 without having to fetch the values. It is only after you write to a block that anything actually gets put on the disk.
I noticed another utility called "truncate" does almost exactly the same thing but the difference is it creates a sparse file which only allocates blocks when they are written, so they may end up not being contiguous on the disk.
If my understanding is correct, it seems both should be a safe alternative to initializing the file with zeros (e.g. using fwrite from C or something like that). I'd appreciate any feedback on this interpretation of fallocate and truncate - thanks.