Virtualization With KVM On A Fedora 11 Server - Page 3

7 Creating An LVM-Based Guest

Fedora 11 KVM Host:

LVM-based guests have some advantages over image-based guests. They are not as heavy on hard disk IO, and they are easier to back up (using LVM snapshots).

To use LVM-based guests, you need a volume group that has some free space that is not allocated to any logical volume. In this example, I use the volume group /dev/vg_server1 with a size of approx. 465GB...


[root@server1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_server1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               465.56 GB
  PE Size               4.00 MB
  Total PE              119184
  Alloc PE / Size       26420 / 103.20 GB
  Free  PE / Size       92764 / 362.36 GB
  VG UUID               aHRSbB-piY1-maoZ-OWPy-DHIy-Bl2F-MPD0y2

[root@server1 ~]#

... that contains the logical volume /dev/vg_server1/lv_root with a size of approx. 98GB and the logical volume /dev/vg_server1/lv_swap (about 5.5GB) - the rest is not allocated and can be used for KVM guests:


[root@server1 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_server1/lv_root
  VG Name                vg_server1
  LV UUID                QCl4x8-zR8r-yYZE-dNp1-leQk-ei9n-vTCcb4
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                97.66 GB
  Current LE             25000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/vg_server1/lv_swap
  VG Name                vg_server1
  LV UUID                rRg2Ua-WBbi-8bjn-TC0E-DBf2-Gcr2-k1nivK
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.55 GB
  Current LE             1420
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@server1 ~]#

I will now create the virtual machine vm11 as an LVM-based guest. I want vm11 to have 20GB of disk space, so I create the logical volume /dev/vg_server1/vm11 with a size of 20GB:

lvcreate -L20G -n vm11 vg_server1

Afterwards, we use the virt-install command again to create the guest:

virt-install --connect qemu:///system -n vm11 -r 512 --vcpus=2 --disk path=/dev/vg_server1/vm11 -c ~/debian-500-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debianlenny --accelerate --network=bridge:br0 --hvm

Please note that instead of -f ~/vm11.qcow2 I use --disk path=/dev/vg_server1/vm11, and I don't need the -s switch to define the disk space anymore because the disk space is defined by the size of the logical volume vm11 (20GB).

Now follow chapter 5 to install that guest.


8 Converting Image-Based Guests To LVM-Based Guests

Fedora 11 KVM Host:

No let's assume we want to convert our image-based guest vm10 into an LVM-based guest. This is how we do it:

First make sure the guest is stopped:

virsh --connect qemu:///system

shutdown vm10


Then create a logical volume (e.g. /dev/vg_server1/vm10) that has the same size as the image file - the image has 12GB, so the logical volume must have 12GB of size as well:

lvcreate -L12G -n vm10 vg_server1

Now you can convert the image:

dd bs=1M if=/dev/zero of=/dev/vg_server1/vm10
qemu-img convert ~/vm10.qcow2 -O raw /dev/vg_server1/vm10

Afterwards you can delete the disk image:

rm -f ~/vm10.qcow2

Now we must open the guest's xml configuration file /etc/libvirt/qemu/vm10.xml...

vi /etc/libvirt/qemu/vm10.xml

... and change the following section...

    <disk type='file' device='disk'>
      <source file='/root/vm10.qcow2'/>
      <target dev='vda' bus='virtio'/>

... so that it looks as follows:

    <disk type='block' device='disk'>
      <source dev='/dev/vg_server1/vm10'/>
      <target dev='vda' bus='virtio'/>

Afterwards we must redefine the guest:

virsh --connect qemu:///system

define /etc/libvirt/qemu/vm10.xml

Still on the virsh shell, we can start the guest...

start vm10

... and leave the virsh shell:



9 Links

Share this page:

3 Comment(s)

Add comment


From: Adam at: 2009-06-18 19:02:18

For the bridge you can also do that:

dont create the br0 and edit your ifcfg-eth0 as follows:


And when you install virtual machines with virt-manager use  select network as default and it will create the vnet0,vnet1 etc for you.

 (I use that on my fedora 11 workstation because I couldn't bridge eth0 for my vms. I run win xp and centos.)



From: jiri at: 2009-12-18 12:42:41

Why are you creating network bridge when you already have one created by libvirtd? See virbr0 in ifconfig output.

From: Anonymous at: 2009-10-23 17:06:42

I think it should be 

 egrep -w '(vmx|svm)' --color=always /proc/cpuinfo