I was trying to create a raw image with this command:
qemu-img create -f raw -o size=200G,preallocation=metadata file.img
but seem that it raw images doesn't support preallocation. if so why there is raw + preallocation in this chart?
# qemu-img create -f raw -o size=200G,preallocation=full file.img
Unknown option 'preallocation'
Invalid options for file format 'raw'.
raw images do not support preallocation, qcow2 and qed-images do:
preallocation=full
instead ofpreallocation=metadata
does not only allocate metadata for the raw image, but also writes zeros to it, thus creating a non-sparse image file.If your filesystems supports sparse-files (e.g. ext, xfs, btrfs), blocks filled only with zeros are not stored physically, that saves space at the beginning of using this image.
If you would like to allocate all space on the raw image, you can use the
dd
command:dd if=/dev/zero of=file.img bs=1M count=204800
If you are working towards speed, also use
cache=writethrough
with e.g. libvirt, this enhanced speed without loss of data if your physical machine crashes.According to this manual, I don't see any preallocation options for raw images.
And also it might be good to take a look at these benchmarks, It seems that any kind of raw images have better performance than qcow2.
and also I've seen many suggestions to avoid write-through caching because of performance issues but I didn't test it myself.
( The last command is needed to align the file to block size 512b )