Linux – How to create a fixed size virtual disk with qemu-img


What's the best way to create a fixed size disk with qemu-img ?
I tried doing this., and it always seems to be creating a virtual /growing disk, doing a ls returns the actual small size of the vmdk.

is there a way to create a "fixed size" disk?

root@local:/tmp# qemu-img create -f vmdk test.vmdk 2G
Formatting 'test.vmdk', fmt=vmdk size=2147483648 compat6=off zeroed_grain=off

root@local:/tmp# qemu-img info test.vmdk
image: test.vmdk
file format: vmdk
virtual size: 2.0G (2147483648 bytes)
disk size: 12K

root@local:/tmp# ls -lah test.vmdk
-rw-r--r-- 1 root root 320K May 13 09:15 test.vmdk

Best Answer

The vmdk disk can be created with -o subformat=monolithicFlat option. A flat disk image fills unused space. Doc: qemu-img create options and vmdk format.