Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  $ dd if=/dev/zero of=/tmp/disk1.img bs=1024 count=10485760
is a terribly inefficient way of creating a test image. It wastes 10GB of disk space. It takes dozen of seconds to run. Etc. Instead you can create a sparse file of 10GB that takes 0 bytes on disk. The creation of such a file is instantaneous:

  $ dd if=/dev/zero of=/tmp/disk1.img bs=1024 seek=10485760 count=0
The key is seek=XXX. The filesystem will not allocate blocks before this offset. An application reading before this offset will just read virtual zero bytes.

Otherwise, this is a nice succinct article showcasing the snapshot/clone feature and send/receive snapshot deltas between 2 systems.

Edit: on Mac OS X, UFS supports sparse file, but not HFS+. On Linux, all major fs support sparse files.



  $ truncate -s 10485760 /tmp/disk1.img
is another way of doing it.


The bad part is bs=1024. That block size will make it take longer.

Often, a sparse file doesn't really emulate a real file well, and you do want a big file full of zeroes...


Not on a copy on write file system.


What does CoW have to do with anything?


Huh. I didn't know that. Does it work on any filesystem?


I believe the filesystem needs "sparse file" support.


I think about anything newer than fat32 supports sparse files.


The FS people today are likely to come across which doesn't support them is HFS+.


Afaik neither exFat or fat32 support it -- and they are still(?) popular for flash sticks and/or drives that needs to be shared between OS'.


Unless you want the space to be pre-allocated


Yeah I've seen hosting companies in the past use sparse files for virtual machine storage - all is good unless, or until, they overcommit.

At which point you have filesystem-soup..


Yes, the better way is by using the fallocate program which uses the posix_fallocate syscall, which makes a new file with a given size containing whatever happened to be on disk at the time. Basically malloc for filesystems.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: