Tuesday, January 20, 2009

20090120 - Poor Man's mkfile -s

In the absence of mkfile(1M) in Linux, the following can be used:

# 1GB file:
# dd /dev/zero bs=1024k of=myfile count=1024

So what?

Well, to make a sparse file (ala mkfile -s), you can still use dd - as long as you seek to the end of the file. count can be zero:

# 1GB file:
# dd if=/dev/zero bs=1024k of=/myfile count=0 seek=1024
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.6e-05 seconds, 0 B/s
# ls -alsh /myfile
0 -rw-r--r-- 1 root root 1.0G Jan 20 00:09 /myfile

To my annoyance, Oracle VM filesystem (OCFS2) doesn't support sparse files:

# dd if=/dev/zero bs=1024k of=/OVS/running_pool/14_big_centos_vm/System.img count=0 seek=1024
0+0 records in
0+0 records out
0 bytes (0 B) copied, 4.9e-05 seconds, 0.0 kB/s
# ls -alsh /OVS/running_pool/14_big_centos_vm/System.img
1.0G -rw-r--r-- 1 root root 1.0G Jan 20 00:11 /OVS/running_pool/14_big_centos_vm/System.img

Crap!