Header image alt text

Kevin's Thoughts!

Maybe you agree, maybe you don't… find out!

KVM Management – Libvirt

Posted by Kevin on August 29, 2011
Posted in Technology  | Tagged With: , , , | No Comments yet, please leave one

KVM Management - Libvirt

Hi all.

I’ve been playing around with KVM for a bit now and have several virtual machines up and running.  Having passed what I considered “first look” stage, I’m ready to start using libvirt as a manager.  For reference, pre-libvirt, I have started this VM with:

kvm -net nic,model=virtio -net tap,ifname=tap5,script=no  -drive file=test1.img,if=virtio,boot=on -curses -no-reboot -m 1g -smp 2

I have a test environment I like to play with, and created the initial domain XML using virt-install:

virt-install –name “Test” –ram 1024 –vcpus=2  –cpu host –description “Test VM” –import –file test1.img –os-type=linux –os-variant=virtio26  –network bridge=br0,model=virtio –graphics=none –autostart –prompt

When I look in /var/log/libvirt/qemu/Test.log  I see the VM is started with the command (edited down to the relevant parts):

/usr/bin/qemu-kvm -S -m 1024 -smp 2 -name Test,process=qemu:Test -nographics -boot c -drive file=/kvms/test1.img,if=none,boot=on

This has two problems:

1) The “-S” is keeping the system from booting
2)  the “if=none” needs to be “if=virtio”

I’ve confirmed both by changing -nographics to -curses and watching what happens.  For #1, its a big fat nothing (no surprise since -S turns off the CPUs), for #2 grub loads and the kernel boots, but my /dev/vda3 isn’t found so “init” can’t start.

I’m anticipating a 3rd problem:  I don’t see where to specify that I want the VM to use “tap5″ of my bridged network.

I have to imagine these things can be corrected by editing the Libvirt XML file for the domain Test.  I’m asking the Libvirt mailing list https://www.redhat.com/mailman/listinfo/libvirt-users for help with this one!

Share

Best Practices for KVM

Posted by Kevin on August 29, 2011
Posted in Tech Talk  | Tagged With: , , , | No Comments yet, please leave one

IBM is, and has been, a great supporter for KVM.  I was quite pleased today to find the following link:

http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/topic/liaat/liaatbestpractices_pdf.pdf

Nice, easy to read, publication on how to optimize the performance of KVM, complete with a few test results to justify their recommendations.

Thank you IBM!

An update:

Being a bit of a computer efficiency enthusiast (read “speed freak”) I decided to migrate one of my VMs from a .img file base directly to an lvm – bypassing the Linux filesystem overhead as IBM suggests.  The process was relatively straight forward, given that I had no issues with the VM being down when I migrated it.  I decided to do this for my new Mail VM, since I was going to have to grow the image size anyhow to handle long term storage of e-mail.

1) Create a new logical disk volume:  lvcreate -L512G -nmail_vm vg

2) Boot my “recovery” minimal boot image passing it the old image file and the new logical volume

kvm  -drive file=mail.img,if=virtio -drive file=/dev/vg/mail_vm,if=virtio,format=raw -cdrom minimal.iso -boot d -curses -no-reboot -m 512 -smp 2

The VM then boots with 2 drives, /dev/vda (old mail.img) and /dev/vdb (new disk).  Within the minimal shell, you then:

A)  Format the new drive with fdisk /dev/vdb (I create 4 partitions, a 64mb /boot in partition   1, a 1GB swap area in partion 2, at 512mb /root in 3, and an LVM area with the rest of the disk in partition 4)

B)  Create a new physical volume group on it via pvcreate /dev/vdb4, a logical volume group on that with vgcreate vg00 /dev/vdb4  and divvy it up as desired with lvcreate commands.  Do note that the volume group name you use needs to be different than what is used on the .img drive.  Confirm everything looks good with vgs and lvs.

C)  Mount the old and new partitions onto new root trees like /or and /nr and use tar to move the files cd or; tar cf – . | (cd /nr; tar xvf -).

D)  Install grub on the new drive to make it bootable.  This was actually just a bit tricky, the key being to create symbolic links for /dev/hda, /dev/hda1, etc. to their /dev/vda counterparts after which the grub root (hd0,0) and setup (hd0) command worked as normal.

E)  Shutdown and start using your new /dev/vg/mail_vm image:

kvm -net nic,model=virtio -net tap,ifname=tap2,script=no  -drive file=/dev/vg/mail_vm,if=virtio,boot=on -curses -no-reboot -m 2g -smp 2 -runas kvm -name mail,process=mail-kvm

 

Share