Virtualization With KVM On A Debian Lenny Server - Page 3

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2009-03-15 20:38. ::

7 Creating An LVM-Based Guest

Debian Lenny 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/vg0 with a size of approx. 465GB...

vgdisplay

server1:~# vgdisplay
  --- Volume group ---
  VG Name               vg0
  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.28 GB
  PE Size               4.00 MB
  Total PE              119112
  Alloc PE / Size       59842 / 233.76 GB
  Free  PE / Size       59270 / 231.52 GB
  VG UUID               gnUCYV-mYXj-qxpM-PEat-tdXS-wumf-6FK3rA

server1:~#

... that contains the logical volume /dev/vg0/root with a size of approx. 232GB and the logical volume /dev/vg0/swap_1 (about 1GB) - the rest is not allocated and can be used for KVM guests:

lvdisplay

server1:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg0/root
  VG Name                vg0
  LV UUID                kMYrHg-d0ox-yc6y-1eNR-lB2R-yMIn-WFgzSZ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                232.83 GB
  Current LE             59604
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

  --- Logical volume ---
  LV Name                /dev/vg0/swap_1
  VG Name                vg0
  LV UUID                SUI0uq-iTsy-7EnZ-INNz-gjvu-tqLD-rGSegE
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                952.00 MB
  Current LE             238
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1

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/vg0/vm11 with a size of 20GB:

lvcreate -L20G -n vm11 vg0

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/vg0/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/vg0/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

Debian Lenny 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

quit

Then create a logical volume (e.g. /dev/vg0/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 vg0

Now you can convert the image:

qemu-img convert ~/vm10.qcow2 -O raw /dev/vg0/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'/>
    </disk>
[...]

... so that it looks as follows:

[...]
    <disk type='file' device='disk'>
      <source file='/dev/vg0/vm10'/>
      <target dev='vda' bus='virtio'/>
    </disk>
[...]

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:

quit

 

9 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by toto (not registered) on Wed, 2011-03-16 11:53.

hi,

this is a complete and nice tutorial. thank you about all tutorial.

Good luck. But, can you write a tutorial how to install libpf or uipf. thank you

Submitted by Federico Fissore (not registered) on Sun, 2009-05-10 00:49.

I've tried converting a qcow2 image directly to the LVM volume as described by this guide but it does NOT work. The resulting hard drive (from the guest point of view) is corrupted

The solution is to create a raw image
kvm-img convert disk0.qcow2 -O raw disk0.raw
and then put the raw bits into the LVM volume
dd if=disk0.raw of=/dev/vg01/vm1 bs=1M

Reference: http://www.adoleo.com/blog/2009/apr/27/lvm-based-virtualization-kvm-and-jaunty/


 

Submitted by Stoned (registered user) on Thu, 2009-03-26 19:12.

If we try to configure converted vm with

[...]
<disk type='file' device='disk'>
<source file='/dev/vg0/vm10'/>
<target dev='vda' bus='virtio'/>
</disk>
[...]

the virtual machine dosn't start...the right configuration is

[...]
<disk type='block' device='disk'>
<source dev='/dev/vg0/vm10'/>
<target dev='vda' bus='virtio'/>
</disk>
[...]

as it's generated on normal lvm-based vm creation ;-)