Virtualization With KVM On Ubuntu 8.10 - Page 3

5 Managing A VM

VMs can be managed through virsh, the "virtual shell". To connect to the virtual shell, run

virsh --connect qemu:///system

This is how the virtual shell looks:

root@server1:~/vm1/ubuntu-kvm# virsh --connect qemu:///system
Connecting to uri: qemu:///system
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh #

You can now type in commands on the virtual shell to manage your VMs. Run

help

to get a list of available commands:

virsh # help
Commands:

    help            print help
    attach-device   attach device from an XML file
    attach-disk     attach disk device
    attach-interface attach network interface
    autostart       autostart a domain
    capabilities    capabilities
    connect         (re)connect to hypervisor
    console         connect to the guest console
    create          create a domain from an XML file
    start           start a (previously defined) inactive domain
    destroy         destroy a domain
    detach-device   detach device from an XML file
    detach-disk     detach disk device
    detach-interface detach network interface
    define          define (but don't start) a domain from an XML file
    domid           convert a domain name or UUID to domain id
    domuuid         convert a domain name or id to domain UUID
    dominfo         domain information
    domname         convert a domain id or UUID to domain name
    domstate        domain state
    domblkstat      get device block stats for a domain
    domifstat       get network interface stats for a domain
    dumpxml         domain information in XML
    freecell        NUMA free memory
    hostname        print the hypervisor hostname
    list            list domains
    migrate         migrate domain to another host
    net-autostart   autostart a network
    net-create      create a network from an XML file
    net-define      define (but don't start) a network from an XML file
    net-destroy     destroy a network
    net-dumpxml     network information in XML
    net-list        list networks
    net-name        convert a network UUID to network name
    net-start       start a (previously defined) inactive network
    net-undefine    undefine an inactive network
    net-uuid        convert a network name to network UUID
    nodeinfo        node information
    pool-autostart  autostart a pool
    pool-build      build a pool
    pool-create     create a pool from an XML file
    pool-create-as  create a pool from a set of args
    pool-define     define (but don't start) a pool from an XML file
    pool-define-as  define a pool from a set of args
    pool-destroy    destroy a pool
    pool-delete     delete a pool
    pool-dumpxml    pool information in XML
    pool-info       storage pool information
    pool-list       list pools
    pool-name       convert a pool UUID to pool name
    pool-refresh    refresh a pool
    pool-start      start a (previously defined) inactive pool
    pool-undefine   undefine an inactive pool
    pool-uuid       convert a pool name to pool UUID
    quit            quit this interactive terminal
    reboot          reboot a domain
    restore         restore a domain from a saved state in a file
    resume          resume a domain
    save            save a domain state to a file
    schedinfo       show/set scheduler parameters
    dump            dump the core of a domain to a file for analysis
    shutdown        gracefully shutdown a domain
    setmem          change memory allocation
    setmaxmem       change maximum memory limit
    setvcpus        change number of virtual CPUs
    suspend         suspend a domain
    ttyconsole      tty console
    undefine        undefine an inactive domain
    uri             print the hypervisor canonical URI
    vol-create      create a vol from an XML file
    vol-create-as   create a volume from a set of args
    vol-delete      delete a vol
    vol-dumpxml     vol information in XML
    vol-info        storage vol information
    vol-list        list vols
    vol-path        convert a vol UUID to vol path
    vol-name        convert a vol UUID to vol name
    vol-key         convert a vol UUID to vol key
    vcpuinfo        domain vcpu information
    vcpupin         control domain vcpu affinity
    version         show version
    vncdisplay      vnc display

virsh #

list

shows all running VMs;

list --all

shows all VMs, running and inactive:

virsh # list --all
 Id Name                 State
----------------------------------
  - vm1                  shut off

virsh #

Before you start a new VM for the first time, you must define it from its xml file (located in the /etc/libvirt/qemu/ directory):

define /etc/libvirt/qemu/vm1.xml

Please note that whenever you modify the VM's xml file in /etc/libvirt/qemu/, you must run the define command again!

Now you can start the VM:

start vm1

After a few moments, you should be able to connect to the VM with an SSH client such as PuTTY; log in with the default username and password. After the first login you will be prompted to change the password.

list

should now show the VM as running:

virsh # list
 Id Name                 State
----------------------------------
  1 vm1                  running

virsh #

To stop a VM, run

shutdown vm1

To immediately stop it (i.e., pull the power plug), run

destroy vm1

Suspend a VM:

suspend vm1

Resume a VM:

resume vm1

These are the most important commands.

Type

quit

to leave the virtual shell.

Share this page:

9 Comment(s)

Add comment

Comments

From: Jim Dennis at: 2009-05-16 21:45:47

 

The first problem I encountered while going through this HOWTO was in trying to follow the example for the configuration of br0 in the /etc/network/interfaces examples.

Like many readers my existing configuration was being managed by NetworkManager ... and is using DHCP.  Naturally my attempt to follow the example past this point (thinking I was creating a new virtual network and chosing an suitable RFC1918 block of static addresses to assign to that) left my system disconnected from the 'net.

It appears that all I needed to do was:

  1. Add an entry for eth0 identifying it as "inet manual" (presumably meaning: "managed by the bridge-utils").
  2. Replace all the static addressing directives in the example with  an "inet dhcp" entry for br0
     

The results look like:

auto br0
iface   br0     inet    dhcp
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off

iface   eth0    inet manual
        # managed by bridge-utils?

Perhaps adding an alternative for those on DHCP and a link to the best info we can find on bridge-utils would help.

 The best info I was able to find so far is at: LinuxFoundation: Net:Bridge. But I didn't have to dive far into it before I figured out what I was supposed to be doing by taking a closer look at the before and "after" examples.

 I hope the maintainer of this HOWTO will read this.

 

 

From: at: 2009-02-16 21:12:27

If virtualization does not show up after

egrep '(vmx|svm)' --color=always /proc/cpuinfo

 You may have to enable virtualization in the bios, I have found that this function is disabled by default in Dell servers and may also be in others.

From: Matt Mossholder at: 2009-03-06 02:40:35

Canonical recommends that you not use the following:

  • sudo su
  • sudo /bin/<insert shell here>
  • ...etc.

The recommended way of getting a root shell is:

sudo -i

 

    --Matt

 

From: Tom at: 2011-10-09 16:29:07

Nice article. Very good explanations.

There are a lot management tools will make KVM deployment much easier:
http://www.linux-kvm.org/page/Management_Tools

Since IBM and Redhat start to support KVM, many companies are deploying KVM cloud farms now.

From: Rainbof at: 2009-03-20 06:47:35

when you get

during creating the VM, following error appeared:

in file ~/vm1/mytemplates/libvirt/libvirtxml.tmpl must be this

<interface type='bridge'>
<source bridge='br0'/>
</interface>

The error from vmbuilder really should have been "No <source> 'bridge' attribute[...]".

From: Anonymous at: 2009-03-06 13:12:35

If you get an error like this:

  /proc/misc: No entry for device-mapper found

while running vmbuilder, you need to install the device mapper kernel module:

  modprobe dm_mod

 

From: Anonymous at: 2009-03-07 11:20:31

Great site ! and good tips.

Please include what the user has to type if the chipset is a i386.

--arch=i386

From: Seppe De Loore at: 2009-02-25 08:34:32

This is a great tutorial. Just had to iron out a small "bridge" error:

there seems to be an error in the vmbuiler documentation and the template ( mytemplates/libvirt/libvirtxml.tmpl) should be adapted to read:

<interface type='bridge'>
<source bridge='br0'/>
</interface>

 The interface type should also be changed to 'bridge' instead of network.

Further installing a more complete PERL (I added perl-debug) will remove the PERL error messages the vmbuilder script spawns.

Anyway, I got my KVM server running. Thank you.

From: Anonymous at: 2010-02-10 11:01:12

You can omit the config file entirely and instead use the command line option --bridge=br0