5 ms·
$ 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
by mrb 12y ago
$ 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.
- LeoPanthera 12y agoHuh. I didn't know that. Does it work on any filesystem?
- bashinator 12y agoI believe the filesystem needs "sparse file" support.
- panzi 12y agoI think about anything newer than fat32 supports sparse files.
- misframer 12y ago$ truncate -s 10485760 /tmp/disk1.img is another way of doing it.
- awda 12y agoThe 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...
- khc 12y agoUnless you want the space to be pre-allocated
- stevekemp 12y agoYeah 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..
- anon4 12y agoYes, 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.
- deleted 12y ago[deleted]