Virtualization With KVM On An OpenSUSE 12.1 Server

Document Sample
Virtualization With KVM On An OpenSUSE 12.1 Server Powered By Docstoc
					Virtualization With KVM On An OpenSUSE 12.1 Server


Version 1.0


This guide explains how you can install and use KVM for creating and running virtual machines
on an OpenSUSE 12.1 server. I will show how to create image-based virtual machines and also
virtual machines that use a logical volume (LVM). KVM is short for Kernel-based Virtual
Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware
virtualization, e.g. Intel VT or AMD-V.

I do not issue any guarantee that this will work for you!



1 Preliminary Note

I'm using an OpenSUSE 12.1 server with the hostname server1.example.com and the IP address
192.168.0.100 here as my KVM host.

We also need a desktop system where we install virt-manager so that we can connect to the
graphical console of the virtual machines that we install. I'm using an OpenSUSE 12.1 desktop
here.



2 Installing KVM

OpenSUSE 12.1 KVM Host:

First check if your CPU supports hardware virtualization - if this is the case, the command

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

should display something, e.g. like this:

server1:~ # 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
mmx fxsr sse sse2 ht syscall
 nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good extd_apicid pni cx16 lahf_lm cmp_le
gacy svm extapic cr8_legacy 3dnowprefetch lbrv
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush
mmx fxsr sse sse2 ht syscall
 nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good extd_apicid pni cx16 lahf_lm cmp_le
gacy svm extapic cr8_legacy 3dnowprefetch lbrv
server1:~ #

If nothing is displayed, then your processor doesn't support hardware virtualization, and you
must stop here.

One of the dependencies that gets installed when we install KVM is Python 2.7, but Python 2.7
conflicts with the package patterns-openSUSE-minimal_base-conflicts. Therefore we must
uninstall that package first. To do so, start YaST:

yast2

In YaST, go to Software > Software Management:




Type patterns-openSUSE-minimal_base-conflicts in the Search field and press ENTER. The
package should be listed as installed (i) in the main window. Mark the package and press the
ENTER key until there's a minus (-) sign in front of the package (the minus stands for uninstall),
then hit [Accept]:
Leave YaST afterwards.

To install KVM and virtinst (a tool to create virtual machines), we run

yast2 -i kvm libvirt libvirt-python qemu virt-manager

Then create the system startup links for libvirtd...

systemctl enable libvirtd.service

... and start the libvirt daemon:

systemctl start libvirtd.service

To check if KVM has successfully been installed, run

virsh -c qemu:///system list

It should display something like this:

server1:~ # virsh -c qemu:///system list
WARNING: no socket to connect to
 Id Name                State
----------------------------------
server1:~ #

If it displays an error instead, then something went wrong.

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.

To do this, we install the package bridge-utils...

yast2 -i bridge-utils

... and configure a bridge.

To configure the bridge, create the file /etc/sysconfig/network/ifcfg-br0 as follows (make sure
you use the IPADDR setting from the /etc/sysconfig/network/ifcfg-eth0 file):

vi /etc/sysconfig/network/ifcfg-br0

     STARTMODE='auto'
     BOOTPROTO='static'
     IPADDR='192.168.0.100/24'
     MTU=''
     NETMASK=''
     NETWORK=''
     BROADCAST=''
     USERCONTROL=no
     NAME='Bridge 0'
     NM_CONTROLLED=no
     BRIDGE='yes'
     BRIDGE_PORTS='eth0'
     BRIDGE_AGEINGTIME='300'
     BRIDGE_FORWARDDELAY='0'
     BRIDGE_HELLOTIME='2'
     BRIDGE_MAXAGE='20'
     BRIDGE_PATHCOSTS='19'
     BRIDGE_PORTPRIORITIES=
     BRIDGE_PRIORITY=
     BRIDGE_STP='on'


(If you get the message You do not have a valid vim binary package installed. Please install
either "vim", "vim-enhanced" or "gvim"., please run

yast2 -i vim

to install vi and try again. )

Modify /etc/sysconfig/network/ifcfg-eth0 as follows (set IPADDR to 0.0.0.0 and change
STARTMODE to hotplug):
vi /etc/sysconfig/network/ifcfg-eth0

       BOOTPROTO='static'
       BROADCAST=''
       ETHTOOL_OPTIONS=''
       IPADDR='0.0.0.0'
       MTU=''
       NAME='MCP77 Ethernet'
       NETMASK=''
       NETWORK=''
       REMOTE_IPADDR=''
       STARTMODE='hotplug'
       USERCONTROL='no'


Then restart the network:

systemctl restart network.service

Afterwards, run

ifconfig

It should now show the network bridge (br0):

server1:~ # ifconfig
br0     Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
      inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
      inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:39 errors:0 dropped:0 overruns:0 frame:0
      TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:4921 (4.8 Kb) TX bytes:1708 (1.6 Kb)

eth0      Link encap:Ethernet HWaddr 00:1E:90:F3:F0:02
        inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
        RX packets:821 errors:0 dropped:0 overruns:0 frame:0
        TX packets:636 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:313341 (305.9 Kb) TX bytes:108982 (106.4 Kb)
        Interrupt:41 Base address:0x8000

lo       Link encap:Local Loopback
        inet addr:127.0.0.1 Mask:255.0.0.0
        inet6 addr: ::1/128 Scope:Host
        UP LOOPBACK RUNNING MTU:16436 Metric:1
        RX packets:20 errors:0 dropped:0 overruns:0 frame:0
       TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
       collisions:0 txqueuelen:0
       RX bytes:2720 (2.6 Kb) TX bytes:2720 (2.6 Kb)

server1:~ #



3 Installing virt-manager On Your OpenSUSE 12.1 Desktop

OpenSUSE 12.1 Desktop:

We need a means of connecting to the graphical console of our guests - we can use virt-manager
for this. I'm assuming that you're using an OpenSUSE 12.1 desktop.

Become root...

su

... and run...

yast2 -i virt-manager libvirt

... to install virt-manager.

(If you're using an Ubuntu 11.10 desktop, you can install virt-manager as follows:

sudo apt-get install virt-manager

)



4 Creating A Debian Squeeze Guest (Image-Based)

OpenSUSE 12.1 KVM Host:

Now let's go back to our OpenSUSE 12.1 KVM host.

Take a look at

virt-install --help

to learn how to use it.
We will create our image-based virtual machines in the directory /var/lib/libvirt/images/ which
was created automatically when we installed KVM in chapter two.

To create a Debian Squeeze guest (in bridging mode) with the name vm10, 512MB of RAM, two
virtual CPUs, and the disk image /var/lib/libvirt/images/vm10.img (with a size of 12GB), insert
the Debian Squeeze Netinstall CD into the CD drive and run

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk
path=/var/lib/libvirt/images/vm10.img,size=12 -c /dev/cdrom --vnc --noautoconsole --os-type
linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm

Of course, you can also create an ISO image of the Debian Squeeze Netinstall CD (please create
it in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual
machines through virt-manager from your OpenSUSE 12.1 desktop, and virt-manager will look
for ISO images in the /var/lib/libvirt/images/ directory)...

dd if=/dev/cdrom of=/var/lib/libvirt/images/debian-6.0.0-amd64-netinst.iso

... and use the ISO image in the virt-install command:

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk
path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.0-amd64-
netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --
network=bridge:br0 --hvm

The output is as follows:

server1:~ # virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --
disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.0-
amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate -
-network=bridge:br0 --hvm
WARNING: no socket to connect to

Starting install...
Allocating 'vm10.img'       | 12 GB 00:00
Creating domain...        | 0 B 00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
server1:~ #

      Virtualization With KVM On An OpenSUSE 12.1 Server - Page 2
      Virtualization With KVM On An OpenSUSE 12.1 Server - Page 3
      Virtualization With KVM On An OpenSUSE 12.1 Server - Page 4
      Virtualization With KVM On An OpenSUSE 12.1 Server - Page 5

				
DOCUMENT INFO
Shared By:
Stats:
views:20
posted:7/31/2012
language:English
pages:7
Description: Virtualization With KVM On An OpenSUSE 12.1 Server