VM lifecycle

From Libvirt Wiki
Revision as of 10:21, 17 January 2011 by Mprivozn (talk | contribs)
(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Virtual Machine Lifecycle

This page describes a beasics of virtual machine lifecycle. It's aim is to have basic info about creating, running, stopping, migrating virtual machine in one page.

Creating a virtual machine

In order to run a virtual machine it is first needed to have one. So in the beginig is creation of a virtual machine. This can be done several ways. The folowing page take you through the process in Virtual Machine Manager GUIT. The second way is using virt-install command line tool.

# virt-install \
             --connect qemu:///system \
             --virt-type kvm \
             --name MyNewVM \
             --ram 512 \
             --disk path=/var/lib/libvirt/images/MyNewVM.img,size=8 \
             --vnc \
             --cdrom /var/lib/libvirt/images/Fedora-14-x86_64-Live-KDE.iso \
             --network default,mac=52:54:00:9c:94:3b \
             --os-variant fedora14

This command creates new virtual machine called 'MyNewVM', with 512 MB RAM, 8 GB disk using KVM. Please read manual page for any further information.

The last way is to create XML definition of domain and volume(s) and run virsh with appropiate commands: vol-create and define.

Example of volume XML definition (new_volume.xml):

<volume>
 <name>sparse.img</name>
 <capacity unit="G">10</capacity>
</volume>

This defines a new volume with capacity of 10 GB. To create volume:

# virsh vol-create default new_volume.xml

Example of domain XML definition (MyNewVM.xml):

<domain type='kvm'>
  <name>MyNewVM</name>
  <currentMemory>524288</currentMemory>
  <memory>524288</memory>
  <uuid>30d18a08-d6d8-d5d4-f675-8c42c11d6c62</uuid>
  <os>
    <type arch='x86_64'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/><apic/><pae/>
  </features>
  <clock offset="utc"/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <vcpu>1</vcpu>
  <devices>
    <emulator>/usr/bin/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/MyNewVM.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <disk type='block' device='cdrom'>
      <target dev='hdc' bus='ide'/>
      <readonly/>
    </disk>
    <interface type='network'>
      <source network='default'/>
      <mac address='52:54:00:9c:94:3b'/>
      <model type='virtio'/>
    </interface>
    <input type='tablet' bus='usb'/>
    <graphics type='vnc' port='-1'/>
    <console type='pty'/>
    <sound model='ac97'/>
    <video>
      <model type='cirrus'/>
    </video>
  </devices>
</domain>