KVM virtual machines in ubuntu

From HeepyWiki
(Redirected from Linux KVM virtual machines)
Jump to navigation Jump to search

Install the packages:

aptitude install ubuntu-virt-server virt-manager kvm python-vm-builder python-virtinst virt-viewer virt-top virt-goodies

Make sure virtualization is enabled in host machine's BIOS; it usually isn't.

If you don't want the default network config of a private network with a local dhcp server, get rid of libvirt's default nat setup:

virsh -c qemu:///system
# net-destroy default
# net-edit default


To use bridging to a local interface, make it look like this:

<network>
  <name>default</name>
  <uuid>18eb5edc-7b46-0f44-ac24-33028d540251</uuid>
  <bridge name='virbr0' stp='on' forwardDelay='0' />
</network>

Then run (in virsh):

# net-start default


If there isn't a default storage pool defined already (I think the gui "virt-manager" will make one if it doesn't exist?) you can import an xml configuration using "virsh pool-define whatever.xml" of which an example is here:

<pool type='dir'>
  <name>default</name>
  <capacity>0</capacity>
  <allocation>0</allocation>
  <available>0</available>
  <source>
  </source>
  <target>
    <path>/var/lib/libvirt/images</path>
    <permissions>
      <mode>0700</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

You can use the virt-manager gui to create a VM, or do it on the command line with virt-install to have an initial configuration created for you.

# virt-install \
        --connect qemu:///system \
        -n testvm3 /
        -r 512 /
        --disk path=/var/lib/libvirt/images/testvm3.img,size=30 /
        --cdrom /home/eric/ubuntu-9.04-server-amd64.iso /
        --network bridge:br0 /
        --vnc /
        --accelerate --hvm

This will try to spawn a console for the vm so you can do the install. You can also manipulate configs and create new VMs directly with virsh commands.

Dump the config of an existing vm:

virsh -c qemu:///system dumpxml testvm > testvm.xml

edit testvm.xml to suit, for example, have it point to a disk image you've already put in place, etc. Make sure to change name, vnc port, etc. If you just remove the uuid definition, it will generate a new one for you. Then,

virsh -c qemu:///system create testvm.xml

This will configure, create, and start the new VM.

To use existing disk with virt-install:

virt-install --connect=qemu:///system --name blah --ram 256 --os-type=linux \
        --import --disk vol=default/blah.img ...

Note: The default network device emulation is rtl8139, which appears to not support vlan tags. If you try to pass tagged packets through it, the host system will see your packets with the tags stripped off. If you use e1000 emulation instead, by adding

<model type='e1000'/>

to the "interface" section of the VM xml config, vlan tags will pass through to the host.