Linux/KVM

From Wiki

Ubuntu 12.04 KVM Host

Installation

kvm-ok      (cpu ok?)
apt-get install ubuntu-virt-server qemu-kvm kvm-ipxe
apt-get install virtinst libvirt-bin virt-top        (cli)
apt-get install virt-manager                         (gui)

network bridge

  • installation:
apt-get install bridge-utils
  • /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
    address 192.168.111.10
    netmask 255.255.255.0
    gateway 192.168.111.1
    dns-nameservers 192.168.111.1
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0


vm guest setup

  • control
virsh --connect qemu:///system
: help

: list --all
: define /etc/libvirt/qemu/vm-???.xml
: start vm-???
: shutdown vm-???
: destroy vm-???
: quit
  • /etc/libvirt/qemu/win7.xml
<domain type='kvm'>
  <name>Win7</name>
  <uuid>??????</uuid>
  <memory>4194304</memory>
  <currentMemory>4194304</currentMemory>
  <vcpu cpuset='0-3'>4</vcpu>
  <os>
    <type arch='x86_64' machine='pc-1.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu match='exact'>
    <model>Westmere</model>
    <vendor>Intel</vendor>
  </cpu>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/srv/kvm/win7/win7.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='xx:xx:xx:xx:xx:xx'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </interface>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='vga' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
</domain>





Iommu

  • grub.cfg (Ubuntu 12.04)
linux /boot/***  intel_iommu=on