KVM on Centos
http://isborken.blogspot.com/2012/02/headless-kvm-setup-on-centos-62.html
Add VLAN to KVM guest
http://henroo.wordpress.com/2011/03/25/how-to-add-vlan-network-to-kvm-guest/
[root@root ~]# cat /etc/sysconfig/network-scripts
/ifcfg-br0
DEVICE="br0"
HWADDR="00:15:17:D3:B2:F0"
NM_CONTROLLED="no"
ONBOOT="yes"
IPADDR="192.168.16.191"
NETWORK="192.168.16.0"
NETMASK="255.255.255.0"
GATEWAY="192.168.16.1"
IPV6INIT=no
TYPE=Bridge
ifcfg-eth0 then just has BRIDGE=br0 - to connect to eth0 to this bridge
device
[root@root ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:15:17:D3:B2:F0"
NM_CONTROLLED="no"
ONBOOT="yes"
IPV6INIT=no
BRIDGE=br0
then other VMs can use the bridge device to configure their own virtual
interfaces with own IP numbers
but other VMs configure ifcfg-eth0 as per usual - as if its a separate
physical server
when creating the VM we specify br0 as the device it can use as network
adapter
[root@root ~]# cat scripts/virt-install.sh
virt-install \
-n myguest \
-r 2048 \
--vcpus=2 \
--os-variant=rhel6 \
-v \
--accelerate \
-c /var/lib/libvirt/images/CentOS-6.2-x86_64-minimal.iso \
-w bridge:br0 \
--vnc --vncport=7601 \
--disk path=/vm/guest.img,size=100
i cut and pasted the above as:
KVM Ubuntu
http://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-11.10
actually there is virt-manager or something and nice GUI tools for KVM,
libvirtd etc - altho my steps below are for headless remote server
so use CLI tools like virsh
1. install libvirtd stuff
apt-get install ubuntu-virt-server python-vm-builder kvm-pxe bridge-utils
# virsh -c qemu:///system list
2. then reconfig the network for br0 as follows
# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
#iface eth0 inet static
#address 192.168.15.48
#netmask 255.255.255.0
#gateway 192.168.15.2
auto br0
iface br0 inet static
address 192.168.15.48
netmask 255.255.255.0
network 192.168.15.0
broadcast 192.168.15.255
gateway 192.168.15.2
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
# /etc/init.d/networking restart
3. for convenience, put bootable image(s) in /var/lib/libvirt/images/
$ cp /opt/media/CentOS-6.2-x86_64-minimal.iso /var/lib/libvirt/images/
4. add VM admin users to groups - eg. evans, hentyw, henryh etc
# adduser user libvirtd
# adduser user kvm
5. make disk space for VMs - actually this is ideally on LVM volume so
one can resize VM's disks but i'm not that advanced yet
# mkdir /vm
# chgrp kvm /vm
# chmod 770 /vm
6. create a test VM
# cat scripts/virt-install.sh
virt-install \
-n myguest \
-r 256 \
--vcpus=1 \
--os-variant=rhel6 \
-v \
--accelerate \
-c /var/lib/libvirt/images/CentOS-6.2-x86_64-minimal.iso \
-w bridge:br0 \
--vnc --vncport=7601 \
--disk path=/vm/guest.img,size=10
actually you need to configure network interfaces to allow users to
reconfigure them - otherwise the above gives following permissions error:
ERROR Failed to add tap interface to bridge 'br0': Operation not
permitted
$ ls -lh /vm
total 0
-rwxrwxr-x 1 user user 10G 2012-04-17 15:38 guest.img
root@evans:/home/evans# virsh -c qemu:///system list
Id Name State
----------------------------------
1 myguest running
7. connect VNC console to running VM
see that vnc is up to connect a console to the VM - you should see
install screen as per the ISO we have specified for the CDROM eg. CentOS
above
# netstat -ntl | grep 7601
tcp 0 0 127.0.0.1:7601 0.0.0.0:* LISTEN
# telnet localhost 7601
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
RFB 003.008
# virt-viewer myguest