Sparse files. Quickly create huge files on disk.
- July 27th, 2010
- Posted in Uncategorized
- Write comment
Recently i felt the sudden urge to allocate four 50 gigabyte large files on my disk. Without thinking about it too much, i fired up dd and sipped my coke while my server nearly died under the added IO-load…
I searched the web for clues with keywords like ‘quickly allocate space for large file’ and such, but this did not bring me to the widely know concept of ‘sparse files‘. Ofcourse i knew about sparse files, my favorite torrent client uses sparse-files to pre-allocate space for downloads! Why didn’t i think of that immediately…
For the sake of findability, i’m posting how to quickly create huge files on disk when you dont care about the contents:
[root@comma:~] # dd if=/dev/zero of=bigfile1 bs=1M count=0 seek=50K [root@comma:~] # ls -la bigfile1 -rw------- 1 root root 53687091200 2010-07-27 21:01 bigfile1 [root@comma:~] # du -h bigfile1 0 bigfile1
While ‘ls‘ sees a 50G large file, the actual on-disk size of the file is 0 bytes. It’s a sparse file.
Perhaps this helps someone in the future.