VirtWithKVM

From T2B Wiki
Revision as of 12:29, 26 August 2015 by Maintenance script (talk | contribs) (Created page with " == KVM installation and configuration on dom02 == === Short description of the software and hardware === The KVM host will be named dom02. The operating system is SL 5.5 x8...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

KVM installation and configuration on dom02

Short description of the software and hardware

The KVM host will be named dom02. The operating system is SL 5.5 x86_64. There are three ports :

  • iLO3 port (IP 192.168.9.222);
  • eth0 : as usual, public NIC, without IP address;
  • eth1 : private NIC with IP 192.168.10.35.

The machine is an HP DL360G7 with CPU L5640 (12 cores) and 24 GB of memory.

Network configuration

Two bridges must be created : one for the public network and another for the private network. Here is the content of the needed network scripts in /etc/sysconfig/network-scripts/ :

# cat ifcfg-eth0
----------------
DEVICE=eth0
BRIDGE=br0
BOOTPROTO=static
ONBOOT=yes
HOTPLUG=no
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
----------------

# cat ifcfg-br0
----------------
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
----------------

# cat ifcfg-eth1
----------------
DEVICE=eth1
BRIDGE=br1
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
PEERDNS=yes
USERCTL=no
IPV6INIT=no
IPV6_AUTOCONF=no
----------------

# cat ifcfg-br1
----------------
DEVICE=br1
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.10.35
NETMASK=255.255.0.0
BROADCAST=192.168.10.255
----------------

After editing these files, restart the network :

service network restart

Now, let us control that everything is ok :

# brctl show
----------------
bridge name	bridge id		STP enabled	interfaces
br0		8000.68b599bd46bc	no		eth0
br1		8000.68b599bd46be	no		eth1
----------------

# ifconfig
----------------
br0       Link encap:Ethernet  HWaddr 68:B5:99:BD:46:BC  
          inet6 addr: fe80::6ab5:99ff:febd:46bc/64 Scope:Link
          ...

br1       Link encap:Ethernet  HWaddr 68:B5:99:BD:46:BE  
          inet addr:192.168.10.35  Bcast:192.168.10.255  Mask:255.255.0.0
          inet6 addr: fe80::6ab5:99ff:febd:46be/64 Scope:Link
          ...

eth0      Link encap:Ethernet  HWaddr 68:B5:99:BD:46:BC  
          inet6 addr: fe80::6ab5:99ff:febd:46bc/64 Scope:Link
          ...

eth1      Link encap:Ethernet  HWaddr 68:B5:99:BD:46:BE  
          inet6 addr: fe80::6ab5:99ff:febd:46be/64 Scope:Link
          ...
----------------

Now, iptables must be configured to allow forwarding across the bridges :

# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# service iptables save
# service iptables restart

SElinux must be disabled, otherwise you'll get strange error messages when trying to start your virtual machines :

/usr/sbin/setenforce 0
vim /etc/selinux/config
--> you must set the following : SELINUX=disabled

We still have to add a default route through ccq :

route add default gw 192.168.10.100

And then configure the DNS resolution by adding the following in /etc/resolv.conf :

search wn.iihe.ac.be
nameserver 192.168.10.100
nameserver 193.190.247.140

RPMs installation

We simply did a :

yum groupinstall KVM

Configuration of daemons

Start libvirtd :

service libvirtd start

Doing a "brctl show" or and an "ifconfig", you should see new interface virbr0.

Example of a VM installation from CD/DVD ISO

We used the GUI virt-manager (don't forget the X forwarding when you connect to dom02 !). Here are the steps in the wizard :

  • First screen : Virtual machine name : cream02;
  • Second screen : Virtualization method : "Fully virtualized";
  • Third screen : Installation method : we have worked with ISOs; and for OS type and variant, Linux-RHEL5.4 or later was the closest to SL5.5;
  • Fourth screen : Storage : we used a file (disk image), keeping the suggested location and rising the size to 40000 MB and pre-allocating the entire virtual disk space;
  • Fifth screen : Network : we chose the option "Shared physical device", which corresponds to the bridging solution, and as a device, we took "eth0 (Bridge br0)";
  • Sixth screen : Memory and CPU allocation : max. memory to 4096 MB and 2 virtual CPUs;

After VM creation, we still had to add a second NIC for the private network, and of course we linked it to the bridge br1.

Example of a VM installation from PXE

In this example, we used command line (virsh) instead of the GUI virt-manager :

  1. Login to dom02.
  2. Each VM has a universal unique identifier (uuid). This number is generated with the command uuid.
  3. With the command :
virsh edit <Name of KVM>

you can create and edit the XML profile of the machine. For example :

<domain type='kvm'>
  <name>submit</name>
  <uuid>e8e837ed-22a9-8a65-feba-0ef6784d8ccf</uuid>
  <memory>1048576</memory>
  <currentMemory>1048576</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='rhel5.4.0'>hvm</type>
    <boot dev='network'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <source file='/var/lib/libvirt/images/submit.img'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <interface type='bridge'>
      <mac address='54:52:00:12:64:7a'/>
      <source bridge='br1'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/>
  </devices>
</domain>

The XML file will be created in /etc/libvirt/qemu. If you want more info about editing this XML, just read this.

4. You can now define your new VM from the XML file :
virsh define <Name of XML definition file>
5. Then, you can create the image file for the hard drive of the VM :
qemu-img create /var/lib/libvirt/images/submit.img 10G
6. We can now start the machine :
virsh start <Name of KVM>

and check that it is running :

virsh list

Convert IDE/SCSI/SATA HD to virtio HD

Installation of a VM with virtio drive through PXE does not work with SL5 because the initrd doesn't load virtio modules during first reboot. To avoid this issue, we can create and install the VM with an IDE hard drive. In the machine xml the disk specification should read like

    <disk type='file' device='disk'>
      <source file='/var/lib/libvirt/images/submit.img'/>
      <target dev='hda' bus='ide'/>
    </disk>

When the installation is finished, convert the HD of the machine to a virtio device. Here are the steps in brief :

  1. Log on the VM
2. Create a new initrd with virtio support :
3. Modify init script in initrd, and replace references to hda by vda.
4. Modify the grub device map file (/boot/grub/device.map)
5. On the host machine, change the XML definition of the VM (virsh edit <VM>).
6. Reboot the VM

To make this conversion easier, we have written a script that you can find in the attachments. Just run this script on the VM, and then type the following on the host :

virsh edit <VM>
--> edit the XML : change <target dev='hda' bus='ide'/> to <target dev='vda' bus='virtio'/>
virsh define <VM_XML>

There is a script dom03:/root/convert_vm_hd_to_virtio.pl to ease this procedure

Useful links


Template:TracNotice