Managing Xen on RHEL 5 using the xm and virsh Command-line Tools

From Techotopia
Jump to: navigation, search
PreviousTable of ContentsNext
Configuring a New RHEL 5 Xen Virtual NetworkInstalling KVM Virtualization on RHEL 5


You are reading a sample chapter from the RHEL 5 Edition book.

Purchase the fully updated Red Hat Enterprise Linux 8 (RHEL 8) Edition of this publication in eBook ($9.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book


In previous chapters we have covered the steps necessary to install and configure Xen and Xen based guest operating systems on Red Hat Enterprise Linux 5. This chapter is dedicated to explaining the xm and virsh tools, and how they may be used to manage Xen based guest operating systems from the command-line.


Contents


xm Command-line vs virsh Shell

Many of the tasks covered in this chapter can be performed using either the xm or virsh though in some cases the actual wording of the option may differ slightly. The primary difference is that the virsh command can be run in shell mode in addition to being used as a command line tool and that it is general in nature, allowing the same tool to be used to manage different virtualization technologies in addition to Xen (such as KVM).

To use the options as command-line arguments, use them at a Terminal command prompt as shown in the following example:

su - 
xm list

A similar result can be achieved using virsh as a command-line tool:

virsh list

To run commands in the virsh shell, run the following command:

[root@rhel5 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

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

virsh #

At the virsh> prompt enter the options you wish to run, for example the following virsh session lists the current virtual machines, starts a virtual machine named MyXenVM and then obtains another listing to verify the VM is running:

su –
[root@rhel5 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

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

virsh # list
 Id Name                 State
----------------------------------
  0 Domain-0             running

virsh # start MyXenVM
Domain MyXenVM started

virsh # list
 Id Name                 State
----------------------------------
  0 Domain-0             running
  3 MyXenVM              idle

In the remainder of this chapter we will focus on using the xm command as opposed to the virsh command. This is simply to avoid duplication since many options used with xm can also be used with virsh. In the event that an option has a different name the equivalent virsh option can be found using the help keyword.

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
    edit            edit XML configuration for a domain
    find-storage-pool-sources discover potential storage pool sources
    find-storage-pool-sources-as find potential storage pool sources
    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-edit        edit XML configuration for a network
    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
    nodedev-list    enumerate devices on this host
    nodedev-dumpxml node device details in XML
    nodedev-dettach dettach node device its device driver
    nodedev-reattach reattach node device its device driver
    nodedev-reset   reset node device
    nodedev-create  create a device defined by an XML file on the node
    nodedev-destroy destroy a device on the node
    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-edit       edit XML configuration for a storage pool
    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

Listing Guest System Status

The status of the RHEL host and its guest systems may be viewed at any time using the list option of the xm tool. For example:

su - 
xm list

The above command will display output containing a line for the host system and a line for each guest similar to the following:

Name                                      ID   Mem VCPUs      State   Time(s)
Domain-0                                   0   389     1     r-----   1414.9
MyXenVM                                        305     1               349.9
WindowsVM                                      300     1                 0.0

The State column uses a single character to specify the current state of the corresponding guest. These are as follows:

  • r - running - The domain is currently running and healthy
  • b - blocked - The domain is blocked, and not running or runnable. This can be caused because the domain is waiting on I/O (a traditional wait state) or has gone to sleep because there was nothing else for it to do.
  • p - paused - The domain has been paused, typically as a result of the administrator running the xm pause command. When in a paused state the domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor.
  • s - shutdown - The guest has requested to be shutdown, rebooted or suspended, and the domain is in the process of being destroyed in response.
  • c - crashed - The domain has crashed. Usually this state can only occur if the domain has been configured not to restart on crash.
  • d - dying - The domain is in process of dying, but hasn't completely shutdown or crashed.

You are reading a sample chapter from the RHEL 5 Edition book.

Purchase the fully updated Red Hat Enterprise Linux 8 (RHEL 8) Edition of this publication in eBook ($9.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book


Starting a Xen Guest System

A guest operating system can be started using the xm tool combined with the start option followed by the name of the guest operating system to be launched. For example:

su -
xm start myGuestOS

Connecting to a Running Xen Guest System

Once the guest operating system has started, a connection to the guest may be established using either the vncviewer tool or the virt-manager console. To use virt-manager, select Applications -> System Tools -> Virtual Machine Manager, select the desired system and click Open.

To connect using vncviewer to the default virtual machine, enter the following command in Terminal window:

vncviewer

When prompted for a server enter localhost:5900. A VNC window will subsequently appear containing the running guest system. If you have multiple virtual machines running, the VNC port of virtual machine may be identified using the virsh command:

virsh vncdisplay WindowsVM
:4

In order to connect to the console for the WindowsVM, therefore, the following command could be used:

vncviewer :4

Shutting Down a Guest System

The shutdown option of the xm tool is used to shutdown a guest operating system:

xm shutdown guestName

where guestName is the name of the guest system, to be shutdown. Note that the shutdown option allows the guest operating system to perform an orderly shutdown when it receives the shutdown instruction. To instantly stop a guest operating system the destroy option may be used (with all the attendant risks of filesystem damage and data loss):

xm destroy myGuestOS

You are reading a sample chapter from the RHEL 5 Edition book.

Purchase the fully updated Red Hat Enterprise Linux 8 (RHEL 8) Edition of this publication in eBook ($9.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book

Pausing and Resuming a Guest System

A guest system can be paused and resumed using the xm tool's pause and restore options. For example, to pause a specific system named myXenGuest:

xm pause myXenGuest

Similarly, to resume the paused system:

xm resume myXenGuest

Note that a paused session will be lost if the host system is rebooted. Also, be aware that a paused system continues to reside in memory. To save a session such that it no longer takes up memory and can be restored to its exact state after a reboot, it is necessary to either suspend and resume or save and restore the guest.

Suspending and Resuming an RHEL Guest OS

A running guest operating system can be suspended and resumed using the xm utility. When suspended, the current status of the guest operating system is written to disk and removed from system memory. A suspended system may subsequently be restored at any time (including after a host system reboot):

To suspend a guest OS named myGuestOS:

xm suspend myGuestOS

To restore a suspended guest OS:

xm resume myGuestOS

Saving and Restoring Xen Guest Systems

Saving and restoring of a Xen guest operating system is similar to suspending with the exception that the file used to contain the suspended operating system memory image can be specified by the user:

To save a guest:

xm save myGuestOS path_to_save_file

To restore a saved guest operating system session:

xm restore path_to_save_file

Rebooting a Guest System

To reboot a guest operating system:

xm reboot myGuestOS

Configuring the Memory Assigned to a Xen Guest OS

To configure the memory assigned to a guest OS, use the mem-set option of the xm command (the equivalent option for virsh is setmem). For example, the following command reduces the memory allocated to a guest system named myGuestOS to 256Mb:

xm mem-set myGuestOS 256

Note that acceptable memory settings must fall within the memory available to the current Domain. This may be increased using the mem-max option to xm.

Migrating a Domain to a Different Host

The migrate option allows a Xen managed domain to be migrated to a different physical server.

In order to use migrate, Xend must already be running on the target host machine, and must be running the same version of Xen as the local host system. In addition, the remote host system must have the migration TCP port open and accepting connections from the source host. Finally, there must be sufficient resources for the domain to run (memory, disk space, etc).

xm migrate domainName host

Optional flags available with this command are:

-l, --live           Use live migration.
-p=portnum, --port=portnum
                     Use specified port for migration.
-r=MBIT, --resource=MBIT
                     Set level of resource usage for migration.

For more information on performing Xen based live migrations, review Virtuatopia.com’s Migrating Xen domainU Guests Between Host Systems tutorial.

You are reading a sample chapter from the RHEL 5 Edition book.

Purchase the fully updated Red Hat Enterprise Linux 8 (RHEL 8) Edition of this publication in eBook ($9.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book



PreviousTable of ContentsNext
Configuring a New RHEL 5 Xen Virtual NetworkInstalling KVM Virtualization on RHEL 5