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):

 <capacity unit="G">10</capacity>

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'>
    <type arch='x86_64'>hvm</type>
    <boot dev='hd'/>
  <clock offset="utc"/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/MyNewVM.img'/>
      <target dev='vda' bus='virtio'/>
    <disk type='block' device='cdrom'>
      <target dev='hdc' bus='ide'/>
    <interface type='network'>
      <source network='default'/>
      <mac address='52:54:00:9c:94:3b'/>
      <model type='virtio'/>
    <input type='tablet' bus='usb'/>
    <graphics type='vnc' port='-1'/>
    <console type='pty'/>
    <sound model='ac97'/>
      <model type='cirrus'/>