cuongk6t's Blog

How they do that – step by step

Virtualization With KVM On A Fedora 14 Server – Part 1

leave a comment »


Author: Falko Timme

This guide explains how you can install and use KVM for creating and running virtual machines on a Fedora 14 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 a Fedora 14 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 a Fedora 14 desktop here.

2 Installing KVM

Fedora 14 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:

[root@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 nopl pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy 3dnowprefetch
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 nopl pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy 3dnowprefetch
[root@server1 ~]#

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

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

yum install kvm qemu libvirt python-virtinst qemu-kvm

Then start the libvirt daemon:

/etc/init.d/libvirtd start

To check if KVM has successfully been installed, run

virsh -c qemu:///system list

It should display something like this:

[root@server1 ~]# virsh -c qemu:///system list
Id Name State
———————————-
[root@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…

yum install bridge-utils

… and configure a bridge.

I disable Fedora’s NetworkManager and enable “normal” networking. NetworkManager is good for desktops where network connections can change (e.g. LAN vs. WLAN), but on a server you usually don’t change network connections:

chkconfig NetworkManager off
chkconfig –levels 35 network on
/etc/init.d/network restart
/etc/init.d/NetworkManager stop

Check your /etc/resolv.conf if it lists all nameservers that you’ve previously configured:

cat /etc/resolv.conf

If nameservers are missing, run

system-config-network

and add the missing nameservers again.

To configure the bridge, create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the 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=145.253.2.75
GATEWAY=192.168.0.1
IPADDR=192.168.0.100
NETMASK=255.255.255.0
ONBOOT=yes
DNS2=8.8.8.8
SEARCH="example.com"

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows (comment out BOOTPROTO, DNS1 (and all other DNS servers, if any), GATEWAY, IPADDR, NETMASK, and SEARCH, set NM_CONTROLLED to no, and add BRIDGE=br0):

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
#BOOTPROTO=none
NM_CONTROLLED="no"
ONBOOT=yes
HWADDR=00:1E:90:F3:F0:02
TYPE=Ethernet
#IPADDR=192.168.0.100
PREFIX=24
#GATEWAY=192.168.0.1
#DNS1=145.253.2.75
#DNS2=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
BRIDGE=br0

Then reboot the system:

reboot

After the reboot, run

ifconfig

It should now show the network bridge (br0):

[root@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:31 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3330 (3.2 KiB) TX bytes:9896 (9.6 KiB)
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:50 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7340 (7.1 KiB) TX bytes:5367 (5.2 KiB)
Interrupt:44 Base address:0xe000
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:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:100 (100.0 b) TX bytes:100 (100.0 b)
virbr0 Link encap:Ethernet HWaddr 1A:D9:31:07:5D:6E
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:3229 (3.1 KiB)
[root@server1 ~]#

3 Installing virt-manager On Your Fedora 14 Desktop

Fedora 14 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 a Fedora 14 desktop.

Become root…

su

… and run…

yum install virt-manager libvirt qemu-system-x86

… to install virt-manager.

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

sudo aptitude install virt-manager

)

4 Creating A Debian Lenny Guest (Image-Based)

Fedora 14 KVM Host:

Now let’s go back to our Fedora 14 KVM host.

Take a look at

man virt-install

to learn how to use it.

I want to create my virtual machines in the directory /vm (they cannot be created in the /root directory because the qemu user doesn’t have read permissions in that directory), so I have to create it first:

mkdir /vm

(If you try to create a virtual machine in the /root directory, you will get errors similar to this one:

[root@server1 ~]# virt-install –connect qemu:///system -n vm10 -r 512 –vcpus=2 -f ~/vm10.qcow2 -s 12 -c ~/debian-500-amd64-netinst.iso –vnc –noautoconsole –os-type linux –os-variant debianlenny –accelerate –network=bridge:br0 –hvm
Starting install…
Creating storage file vm10.qcow2 | 12 GB 00:00
ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/2
qemu: could not open disk image /root/vm10.qcow2: Permission denied
Domain installation may not have been
successful. If it was, you can restart your domain
by running ‘virsh start vm10’; otherwise, please
restart your installation.
ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/2
qemu: could not open disk image /root/vm10.qcow2: Permission denied
Traceback (most recent call last):
File “/usr/sbin/virt-install”, line 972, in <module>
main()
File “/usr/sbin/virt-install”, line 834, in main
start_time, guest.start_install)
File “/usr/sbin/virt-install”, line 896, in do_install
dom = install_func(conscb, progresscb, wait=(not wait))
File “/usr/lib/python2.6/site-packages/virtinst/Guest.py”, line 798, in start_install
return self._do_install(consolecb, meter, removeOld, wait)
File “/usr/lib/python2.6/site-packages/virtinst/Guest.py”, line 899, in _do_install
self.domain = self.conn.createLinux(install_xml, 0)
File “/usr/lib64/python2.6/site-packages/libvirt.py”, line 1147, in createLinux
if ret is None:raise libvirtError(‘virDomainCreateLinux() failed’, conn=self)
libvirtError: internal error Process exited while reading console log output: char device redirected to /dev/pts/2
qemu: could not open disk image /root/vm10.qcow2: Permission denied
[root@server1 ~]#

)

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

virt-install –connect qemu:///system -n vm10 -r 512 –vcpus=2 -f /vm/vm10.qcow2 -s 12 -c /dev/cdrom –vnc –noautoconsole –os-type linux –os-variant debianlenny –accelerate –network=bridge:br0 –hvm

Of course, you can also create an ISO image of the Debian Lenny Netinstall CD…

dd if=/dev/cdrom of=/vm/debian-500-amd64-netinst.iso

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

virt-install –connect qemu:///system -n vm10 -r 512 –vcpus=2 -f /vm/vm10.qcow2 -s 12 -c /vm/debian-500-amd64-netinst.iso –vnc –noautoconsole –os-type linux –os-variant debianlenny –accelerate –network=bridge:br0 –hvm

The output is as follows:

[root@server1 ~]# virt-install –connect qemu:///system -n vm10 -r 512 –vcpus=2 -f /vm/vm10.qcow2
-s 12 -c /dev/cdrom –vnc –noautoconsole –os-type linux –os-variant debianlenny –accelerate –network=bridge:br0 –hvm
Starting install…
Creating storage file vm10.qcow2 | 12 GB 00:00
Creating domain… | 0 B 00:01
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@server1 ~]#

TOBE CONTINUES…

source: http://www.howtoforge.com/virtualization-with-kvm-on-a-fedora-14-server

Written by cuongk6t

24/05/2011 at 9:21 am

Posted in Linux Tutorial

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: