Derwynd's Weblog

Derwynd's Weblog

KVM on centos5

Disable Selinux

Make sure that SELinux is disabled. Open /etc/selinux/config…

$ vi /etc/selinux/config

… set SELINUX to disabled:

$ reboot

or

Run

$ setenforce 0
[edit] Installing KVM

check if your CPU supports hardware virtualization

$ egrep ‘(vmx|svm)’ –color=always /proc/cpuinfo

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm

install KVM and virtinst

$ yum install zlib-devel alsa-lib-devel SDL-devel gnutls-devel dev86 texi2html glibc-devel kvm qemu\
libvirt python-virtinst virt-manager libvirt libvirt-python python-virtinst qemu

$ yum install kvm qemu libvirt python-virtinst
$ yum install virt-manager libvirt libvirt-python python-virtinst

In case rpmforge repo is recquired for qemu

$ rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

[edit] Service Starting

Then start the libvirt daemon:

$ /etc/init.d/libvirtd start

To check if KVM has successfully been installed, run

$ virsh -c qemu:///system list

Id Name State
———————————-

Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.

$ yum install bridge-utils

… and configure a bridge. Delete the system startup links for NetworkManager and create system startup links for network:

$ chkconfig –del NetworkManager
$ chkconfig –levels 235 network on

[edit] Networking

Then create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the BOOTPROTO, DNS1 (plus any other DNS settings, if any), GATEWAY, IPADDR, NETMASK and SEARCH values from the /etc/sysconfig/network-scripts/ifcfg-eth0 file):

$ vi /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
DNS1=192.168.2.234
GATEWAY=192.168.2.234
IPADDR=192.168.40.112
NETMASK=255.255.0.0
ONBOOT=yes

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 by keeping these lines and hashing everything else

DEVICE=eth0
HWADDR=00:1E:C9:B5:0D:51
ONBOOT=yes
BRIDGE=br0

Then reboot the system:

$ reboot

[edit] Starting Hosts

Use graphical installation and run “Creating guests with virt-manager”

$ virt-manager &

Open the File -> Open Connection. The dialog box below appears. . Select a hypervisor and click the Connect button

OR

$ virt-install –accelerate –hvm –connect qemu:///system –network bridge:br0 –name rhel5support –ram=512 –file=/xen/rhel5support.img –file-size=6 –vnc –cdrom=/dev/cdrom

Using virt-install with KVM to create a Red Hat Enterprise Linux 5 guest using cdrom –hvm (full virt)

$ virt-install –name fedora11 –ram 512 –file=/var/lib/libvirt/images/fedora11.img –file-size=3 –vnc –cdrom=/var/lib/libvirt/images/fedora11.iso

Using virt-install to create a fedora 11 guest

[edit] Info

the xml files are loacted at

$ cd /etc/libvirt/qemu/

Starting the virt machines

$ virsh create kvm2.xml

List domains

$ virsh -c qemu:///system list
Id Name State
———————————-
1 kvm2 running
2 kvm1 running

Connect to kvm

$ virsh console kvm1

[edit] Managing Virtual Machines from the command line with `virsh`

Virtual machines can be managed on the command line with the virsh utility. The virsh utility is built around the libvirt management API and has a number of advantages over the traditional Xen xm tool:

virsh has a stable set of commands whose syntax & semantics will be preserved across updates to Xen.
virsh can be used as an unprivileged user for read-only operations (eg listing domains, getting info, etc)
virsh will (in future) be able to manage QEMU, VMWare, etc machines in additional to Xen, since libvirt is hypervisor agnostic.

To start a new virtual machine from an XML vm definition:

$ virsh create

To list the virtual machines currently running, use:

$ virsh list

To gracefully power off a guest use:

$ virsh shutdown

To save a snapshot of the machine to a file of your choosing:

$ virsh save

To restore a previously saved snapshot:

$ virsh restore

To export the XML config associated with a virtual machine:

$ virsh dumpxml <virtual machine (name | id | uuid)

For a complete list of commands available for use with virsh run:

$ virsh help

Or consult the manual page virsh(1)

Advertisements

July 14, 2010 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: