1

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'.
Zim3r
  • 1,384
  • 5
  • 23
  • 45

3 Answers3

2

raw images do not support preallocation, qcow2 and qed-images do:

preallocation=full instead of preallocation=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.

leoben
  • 41
  • 7
  • Thanks but: `Unknown option 'preallocation' Invalid options for file format 'raw'.` and I heard [bad things](http://www.ilsistemista.net/images/stories/kvm_storage_rhel6_201103/ide_raw.png) about write-through. – Zim3r Sep 16 '12 at 12:45
  • I've edited my previous answer. Regarding writethrough: That enhances performance distinctly, of course the performance improvment depends on many other variables. You may have heard something bad about writeback-caching, as mentioned this is a risk if your physical machine crashes, but this imrpoves perfomance even more. – leoben Sep 16 '12 at 13:10
  • 1
    It may seem counterintuitive, but `cache=writethrough` really does dramatically _reduce_ performance in a lot of situations. – Michael Hampton Sep 16 '12 at 13:30
  • In my experience this only has an impact when creating snapshots (which is a known bug) of a qcow2 image, so I deactivate it only for systems I know I will make a lot of snapshots of. I have not experienced a performance decrease in my practical experience, the contrary. It may be that in different enviroments the experience is not good or even worse than without caching, using up to date software may remedy the deficiencies. – leoben Sep 16 '12 at 13:37
1

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.

Zim3r
  • 1,384
  • 5
  • 23
  • 45
0
qemu-img create -f qcow2 -o size=199G,preallocation=full file.img
mv file.img file.raw
qemi-img resize -f raw file.raw 200G

( The last command is needed to align the file to block size 512b )

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47