KVM virtualization

I will use kvm with libvirt and qemu:

- install next packages: kvm libvirt-bin python-virtinst bridge-utils
- adduser $YOURUSERNAME libvirtd
- reboot
- user@kvmhost:~$ virsh -c qemu:///system list --all
Id Name State
---------------------------------- 

if we have linux ubuntu, then bridge network will install very simply:
- edit /etc/network/interfaces

before modification:

auto eth0
iface eth0 inet static
       address 172.16.4.24
       netmask 255.255.255.192
       network 172.16.4.0
       broadcast 172.16.4.63
       gateway 172.16.4.1

after modification:

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
        address 172.16.4.24
        netmask 255.255.255.192
        network 172.16.4.0
        broadcast 172.16.4.63
        gateway 172.16.4.1
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off


Install VM:

root@kvmhost# virt-install -n kvmhostU1 -r 2048 -f /vz/kvmhostU1.img -s 150 -c /distr/ubuntu-10.10-server-amd64.iso \
--accelerate --os-type=linux --os-variant=generic26 -v --vnc -w bridge:br0 --vcpus=2 --cpuset=1-2

-n kvmhostU1 - VM name;
-r 2048 - RAM in megabytes;
-f /vz/kvmhostU1.img - file, which is a virtual hard disk for the guest OS;
-c /distr/ubuntu-10.10-server-amd64.iso - image of installation system;
--accelerate --os-type=linux --os-variant=generic26 - read "man virt-install" about this acceleration options;
-v - This parameter is implied if connecting to a QEMU based hypervisor;
--vcpus=2 - number of CPUs for guest VM;
--cpuset=1-2 - set of CPUs that will be available for VM.

If do you see message like this:
Starting install…
Creating domain… 0 B 00:01
Unable to connect to graphical console: virt-viewer not installed. Please install the 'virt-viewer' package.
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
That means all is well.

root@kvmhost# virsh -c qemu:///system list --all
Id Name                 State
----------------------------------
1 kvmhostU1              running

Install Guest OS:

ssh -N -L 5900:localhost:59000 ssh_user@kvm_server
connect with your favourite vnc client to localhost:59000

How to clone VM:
virt-clone -o kvmhostU1 -n kvmhostU2 -f /vz/kvmhostU2.img --connect=qemu:///system
after that, connect to kvmhostU2
- edit /etc/hosts
- edit /etc/hostname
- delete /etc/udev/rules.d/70-persistent-net.rules
- if you have static ip address, change it