Virtualization With KVM On Ubuntu 8.10
Version 1.0
Author: Falko Timme
This guide explains how you can install and use KVM for creating and running virtual machines on an Ubuntu 8.10 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 machine with the hostname server1.example.com and the IP address 192.168.0.100 here as my KVM host.
Because we will run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing
sudo su
2 Installing KVM And vmbuilder
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:
[email protected]:~# 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
[email protected]:~#
If nothing is displayed, then your processor doesn't support hardware virtualization, and you must stop here.
To install KVM and vmbuilder (a script to create Ubuntu-based virtual machines), we run
apt-get install ubuntu-virt-server python-vm-builder
Afterwards we must add the user as which we're currently logged in (root) to the group libvirtd:
adduser `id -un` libvirtd
You need to log out and log back in for the new group membership to take effect.
To check if KVM has successfully been installed, run
virsh -c qemu:///system list
It should display something like this:
[email protected]:~# virsh -c qemu:///system list
Connecting to uri: qemu:///system
Id Name State
----------------------------------
[email protected]:~#
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...
apt-get install bridge-utils
... and configure a bridge. Open /etc/network/interfaces:
vi /etc/network/interfaces
Before the modification, my file looks as follows:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
|
I change it so that it looks like this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.0.100
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
|
(Make sure you use the correct settings for your network!)
Restart the network...
/etc/init.d/networking restart
... and run
ifconfig
It should now show the network bridge (br0):
[email protected]:~# 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:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1580 (1.5 KB) TX bytes:2356 (2.3 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:13539 errors:0 dropped:0 overruns:0 frame:0
TX packets:7684 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19476849 (19.4 MB) TX bytes:647692 (647.6 KB)
Interrupt:251 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:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vnet0 Link encap:Ethernet HWaddr 3e:7c:6f:ab:0e:8c
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
inet6 addr: fe80::3c7c:6fff:feab:e8c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:468 (468.0 B)
[email protected]:~#
Sub pages
Suggested articles
4 Comment(s)
Comments
The first problem I encountered while going through this HOWTO was in trying to follow the example for the configuration of br0 in the /etc/network/interfaces examples.
Like many readers my existing configuration was being managed by NetworkManager ... and is using DHCP. Naturally my attempt to follow the example past this point (thinking I was creating a new virtual network and chosing an suitable RFC1918 block of static addresses to assign to that) left my system disconnected from the 'net.
It appears that all I needed to do was:
- Add an entry for eth0 identifying it as "inet manual" (presumably meaning: "managed by the bridge-utils").
-
Replace all the static addressing directives in the example with an "inet dhcp" entry for br0
The results look like:
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
iface eth0 inet manual
# managed by bridge-utils?
Perhaps adding an alternative for those on DHCP and a link to the best info we can find on bridge-utils would help.
The best info I was able to find so far is at: LinuxFoundation: Net:Bridge. But I didn't have to dive far into it before I figured out what I was supposed to be doing by taking a closer look at the before and "after" examples.
I hope the maintainer of this HOWTO will read this.
If virtualization does not show up after
egrep '(vmx|svm)' --color=always /proc/cpuinfo
You may have to enable virtualization in the bios, I have found that this function is disabled by default in Dell servers and may also be in others.
Canonical recommends that you not use the following:
- sudo su
- sudo /bin/<insert shell here>
- ...etc.
The recommended way of getting a root shell is:
sudo -i
--Matt
Nice article. Very good explanations.
There are a lot management tools will make KVM deployment much easier:
http://www.linux-kvm.org/page/Management_Tools
Since IBM and Redhat start to support KVM, many companies are deploying KVM cloud farms now.
English |
Deutsch