User Tools

Site Tools


kvm

Overview

KVM is a virtualization hypervisor for linux

qcow2 vs raw disk

As of November, 2012 and on ubuntu 12.04 disk I/O was actually better with a qcow2 image that had preallocate=metadata option done to it. Raw disk I/O was slightly lower. As cache has been disabled in both instances it's unclear why this is the case when all information online points to a raw disk image would be better.

Converting qcow2 and raw images

Convert qcow2 to raw

  • Shutdown the vm if it's running
  • qemu-img info /path/to/file.qcow2
    • Note the size given for virtual size
  • sudo lvcreate -L 12345678b -n kvm_vm1 vg0 where 12345678 is the size you got from above command. Remember the b at the end
  • sudo qemu-img convert /path/to/file.qcow2 -O host_device /dev/mapper/vg0-kvm_vm1
  • virsh edit vm1 and change it from this
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/srv/kvm/vm1/disk0.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
  • to this
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source dev='/dev/mapper/vg0-kvm_vm1'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>

Convert raw to qcow2

  • Shutdown the vm if it's running
  • sudo lvcreate -L 12345678b -n kvm_vm1 vg0 where 12345678 is the size you got from above command. Remember the b at the end
  • sudo qemu-img convert /dev/mapper/vg0-kvm_vm1 -O qcow2 -o preallocation=metadata /srv/kvm/vm1/disk0.qcow2
  • virsh edit vm1 and change it from this
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source dev='/dev/mapper/vg0-kvm_vm1'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
  • To this:
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/srv/kvm/vm1/disk0.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>

References

kvm.txt · Last modified: 2012/11/28 12:55 by vrillusions