Changes between Initial Version and Version 1 of Tutorials/i0Net/KVM


Ignore:
Timestamp:
Jun 1, 2012, 4:18:35 PM (12 years ago)
Author:
seskar
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Tutorials/i0Net/KVM

    v1 v1  
     1[[TOC(heading=KVM tutorial TOC, Tutorials/KVM)]]
     2
     3= KVM Tutorial =
     4== Installing KVM ==
     5
     6Check if your CPU supports hardware virtualization via command:
     7{{{
     8egrep '(vmx|svm)' --color=always /proc/cpuinfo
     9}}}
     10       
     11If nothing is displayed CPU doesn't support virtualization.
     12
     13Instal packages ubuntu-virt-server, python-vm-builder and kvm-pxe via command (but just in case, first update the package repository on the node):
     14{{{
     15apt-get update
     16apt-get install ubuntu-virt-server python-vm-builder kvm-pxe
     17}}}
     18               
     19Add the current user to the group:
     20{{{
     21adduser `id -un` libvirtd
     22adduser `id -un` kvm
     23}}}
     24       
     25Logout and login again:
     26{{{
     27logout
     28ssh root@node1-1
     29}}}
     30       
     31Check users group by comamand:
     32{{{
     33groups
     34}}}
     35
     36Output should be similar to:
     37{{{
     38root kvm libvirtd
     39}}}
     40
     41To list all running KVMs use:
     42{{{
     43virsh -c qemu:///system list
     44}}}
     45
     46== Setup network bridge on the host ==
     47
     48Install the package bridge-utils:
     49{{{
     50apt-get install bridge-utils
     51}}}
     52
     53Create the bridge interface named br0:
     54{{{
     55brctl addbr br0
     56}}}
     57
     58Edit the network interfaces configuration with editor (for example nano):
     59{{{
     60nano /etc/network/interfaces
     61}}}
     62
     63and add persistent configuration for br0 interface:
     64{{{
     65# This file describes the network interfaces available on your system
     66# and how to activate them. For more information, see interfaces(5).
     67
     68# The loopback network interface
     69auto lo
     70iface lo inet loopback
     71
     72# The primary network interface
     73auto eth1
     74iface eth1 inet dhcp
     75
     76# The secondary network interface
     77auto eth0
     78iface eth0 inet manual
     79
     80#Bridge 0 interface
     81auto br0
     82iface br0 inet static
     83  address 10.28.1.1
     84  netmask 255.255.0.0
     85  broadcast 10.28.255.255
     86  network 10.28.0.0
     87  bridge_ports eth0
     88  bridge_fd 9
     89  bridge_hello 2
     90  bridge_maxage 12
     91  bridge_stp off
     92}}}
     93
     94Restart networking with command:
     95{{{
     96/etc/init.d/networking restart
     97}}}
     98
     99For bridge verification open the new ssh window and run:
     100{{{
     101tcpdump -i br0
     102}}}
     103
     104and then, in the other window, try to ping some adress in same subnet, for example:
     105{{{
     106ping 10.28.0.1
     107}}}
     108
     109In the second windows you should see logging ofrequest/reply messages.
     110
     111It is recommended to reboot the machine once the bridge is configured.
     112
     113== Create and run KVM image using vmbuilder ==
     114
     115Folder /var/lib/libvirt/images/ will be created for storing images. Each image will have
     116separate folder for example /var/lib/libvirt/images/virtual-machine1
     117
     118Create necessary folders:
     119{{{
     120mkdir -p /var/lib/libvirt/images/vm1/mytemplates/libvirt
     121}}}     
     122'-p' option of mkdir command means that all parent folders will be created if they do not exist.
     123
     124vmbuilder tool uses templates for creating of images so copy the template:
     125{{{
     126cp /etc/vmbuilder/libvirt/* /var/lib/libvirt/images/vm1/mytemplates/libvirt/
     127}}}
     128       
     129Open partition configuration file with command:
     130{{{
     131nano /var/lib/libvirt/images/vm1/vmbuilder.partition
     132}}}
     133
     134and add the following lines:
     135{{{
     136root 8000
     137swap 4000
     138---
     139/var 20000
     140}}}
     141       
     142Copied text defines three partitions - root, swap and var and their sizes.
     143"---" means that var partition will be separate image file.
     144
     145Go to folder vm1:
     146{{{
     147cd /var/lib/libvirt/images/vm1/
     148}}}
     149
     150Execute vmbuilder command:
     151{{{
     152vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=10.28.4.4 --gw=10.28.0.1 --mask=255.255.0.0 --bcast=10.28.255.255 --net=10.28.0.0 --dns=10.0.0.9 --part=vmbuilder.partition --templates=mytemplates --user=guest --name=Guest --pass=guest --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --mem=256 --hostname=vm1 --bridge=br0 --addpkg openssh-server --addpkg nano
     153}}}     
     154
     155== Create and run KVM image using KVM directly ==
     156
     157Download ubuntu server ISO file:
     158{{{
     159wget -O ubuntu-server.iso http://www.ubuntu.com/start-download?distro=server&bits=64&release=latest
     160}}}
     161
     162Create Disk:
     163{{{
     164qemu-img create -f qcow2 vm-oneric-amd64-serial 10G
     165}}}
     166
     167Setup network bridge (see part III).
     168
     169Install tool for Tun:
     170{{{
     171apt-get install uml-utilities
     172}}}
     173
     174Create the tap interface:
     175{{{
     176tunctl
     177}}}
     178
     179Output of the name is (tap0).
     180
     181Add tap interface to the bridge as a port:
     182{{{
     183brctl addif br0 tap0
     184}}}
     185
     186Bring up tap0 interface:
     187{{{
     188ifconfig tap0 up
     189}}}
     190
     191Boot and Install Ubuntu using VNC:
     192{{{
     193kvm -daemonize -m 1024 -hda vm-oneric-amd64-serial -cdrom ubuntu-server.iso -boot d -smp 2 -cpu qemu64 -net nic,model=virtio -net tap,ifname=tap0,script=no -vnc :0
     194}}}     
     195
     196To run already created image you can enter:
     197{{{
     198kvm -daemonize -m 1024 -hda vm-oneric-amd64-serial  -smp 2 -cpu qemu64 -net nic,model=virtio -net tap,ifname=tap0,script=no -vnc :0
     199}}}
     200
     201Use VNC client to connect to virtual machine.
     202       
     203Kill Virtual machine (KVM process):
     204{{{
     205pkill -9 kvm
     206}}}
     207
     208Remove tap0 in as a bridge interface:
     209{{{
     210brctl delif br0 tap0
     211}}}
     212
     213Delete tap interface:
     214{{{
     215tunctl -d tap0
     216}}}
     217
     218{{{
     219kvm -daemonize -m 1024 -hda vm-oneric-amd64-serial -smp 2 -cpu qemu64 -net nic,model=virtio -net tap,ifname=tap0,script=no -vnc :0
     220}}}
     221
     222{{{
     223kvm -daemonize -m 1024 -hda vm-oneric-amd64-serial -cdrom ubuntu-11.10-server-amd64.iso -boot d -smp 2 -cpu qemu64 -net nic,model=virtio -net tap,ifname=tap0,script=no -vnc :0
     224}}}
     225