Introduction of configure virtual network and KVM based on libvirt.
This is a reference document of building KVMs with certain networks to support BMC deployment virtualization.
It requires the basic knowledge of Linux bridge, net-configure interface, qemu-kvm and libvirt.

To make a check your machine supports KVM, use grep as below
grep -E '(vmx|svm)' /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 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good unfair_spinlock pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes hypervisor lahf_lm vnmi ept
<!-- more information is ignored -->
If the output is not empty, use yum to install dependencies and tools as below
yum install qemu-kvm qemu-kvm-tools libguestfs-tools -y
yum groupinstall Virtualization-Platform Virtualization-Clients Virtualization-Tools -y
To verify the installation, execute
/usr/libexec/qemu-kvm --version
The output message should be like “QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2), Copyright (c) 2003-2008 Fabrice Bellard”.
service NetworkManager status and if get message as “NetworkManager (pid $pid_numb) is running…” then execute service NetworkManager stopservice iptables stopGo into network configuration directory.
cd /etc/sysconfig/network-scripts
Create a configure file named as ifcfg-br*, * must be a number. Here use ifcfg-br1 as an example.
Example 1:
#This is used when there's a DHCP server.
DEVICE=br1
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Bridge
STP=on
Example 2:
#This is used when there's no DHCP server.
DEVICE=br1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.100.16
NETMASK=255.255.255.0
TYPE=Bridge
STP=on
Here assume that eth1 is linked to the br1 above.
Create a configure file named as ifcfg-eth1.
DEVICE=eth1
TYPE=Ethernet
BRIDGE=br1
ONBOOT=yes
BOOTPROTO=none
To now, the linux bridge is completely setted but not in validation. To validate it, execute service network restart.
Ensure that the NetworkManager is closed before doing this.
If any errors occurs, do rm /etc/udev/rules.d/70-persistent-net.rules and try again.
If no errors occur, execute brctl show to get the information as follow:
bridge name bridge id STP enabled interfaces
br1 8000.525400117fda yes eth1
Libvirt use xml format file to define a network. For more
This example showes a bridge forward network. The libvirt will create a tap device and bond it to a bridge. Then the guest virtual machine will use this tap as its ethernet device.
<network>
<name>virnet-1</name>
<forward mode="bridge"/>
<bridge name="br1"/>
</network>
virsh net-list --all to list all and virsh net-info $netname to get more information.ifconfig $netname.virsh net-create $xml_file then a temporaty virtual network is created. If you this net to be automatically started at boot, then virsh net-autostart $netname.
Most of the steps are the same with no bonding one. The difference is as follow steps.
Please refer to the part of setting up a lunix bridge in “no bonding”. They are exactly the same as those steps.
Go into network configuration directory.
cd /etc/sysconfig/network-scripts
Create a configure file named as ifcfg-bond*, * must be a number. Here use ifcfg-bond2 as an example.
DEVICE=bond2
TPYE=Bonding
BRIDGE=br2
BONDING_OPTS="mode=1 miimon=200"
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
Here assume that eth2 and eth3 is bonded to the bond2 above.
Create a configure file named as ifcfg-eth2 first.
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond2
SLAVE=yes
Then a ifcfg-eth3.
DEVICE=eth3
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond2
SLAVE=yes
The rest steps like manage linux bridges and virtual networks are the same as “The Configuration of no bonding”.
Assume that there’s an image named “bmc15b-Fri.qcow2” which is created from some other KVM’s snapshot.
virt-install \
-n BMC-release \
-r 512 \
--vcpus 1 \
--network network=virnet-1 \
--graphics vnc \
--hvm \
--virt-type kvm \
--os-type linux --os-variant rhel6 \
--disk path=/var/tmp/bmc15b-Fri.qcow2,format=qcow2 \
--cdrom /var/tmp/seed.iso \
--boot hd
Then a virtual machine named BMC-release which get 512MB ram, one virtual CPU and virnet-1 as its eth0 is created.
Assume that there’s a official rhel iso named rhel-server-6.5-x86_64-dvd.iso, you can use a premade ks.cfg file to do auto-install.
virt-install \
-n BMC-release \
-r 1024 \
--vcpus 1 \
--network network=virnet-1 \
--graphics vnc \
--hvm \
--virt-type kvm \
--os-type linux --os-variant rhel6 \
--disk path=/var/tmp/bmc15b-Fri.img,size=20G
--location ${ISO_PATH}/rhel-server-6.5-x86_64-dvd.iso \
--initrd-inject=ks.cfg \
--extra-args "ks=file:/ks.cfg"
You can view the installation process in vnc viewer.
Sometimes a image may need to be made some changes before release. The guestfish is a tool to help doing this safely.
Assume that here gets a RHEL qcow2 image called rhel6.5_demo.img. Mount the image in read-write mode as root, as follows:
# guestfish --rw -a centos63_desktop.img
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
><fs>
Then use run command to launch a lightweight virtual machine.
><fs> run
If viewing the file systems in the image is requited, using the list-filesystems command.
><fs> list-filesystems
/dev/vda1: ext4
Mount the disk or volumn and start to edit files.
><fs> mount /dev/vda1 /
><fs> rm /etc/udev/rules.d/70-persistent-net.rules
><fs> edit /etc/sysconfig/network-scripts/ifcfg-eth0
When everything is done, use exit to leave.
>