Changes

Jump to: navigation, search

Managing Xen using the xm Command-line Tool

8,371 bytes added, 20:14, 27 October 2016
m
Text replacement - "<table border="0" cellspacing="0"> " to "<table border="0" cellspacing="0" width="100%">"
<table border="0" cellspacing="0" width="100%"><tr>
<td width="20%">[[Installing a Xen Guest OS from the Command-line (virt-install)|Previous]]<td align="center">[[Fedora Linux Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Fedora KVM Virtualization|Next]]</td>
<tr>
<td width="20%">Installing a Xen Guest OS from the Command-line (virt-install)<td align="center"><td width="20%" align="right">Installing and Configuring Fedora KVM Virtualization</td>
</table>
<hr>
 
<htmlet>fedora</htmlet>
 
In previous chapters we have covered the steps necessary to install and configure Xen and Xen based guest operating systems. This chapter is dedicated to explaining the ''xm'' tool, and how it can be used to manage guest operating systems from the command-line. If you prefer to use the graphical ''virt-manager'' tool to administer your Xen configuration see [[Managing and Monitoring Fedora based Xen Guest Systems]].
 
== xm Command-line vs xm Shell ==
 
The ''xm'' options covered in this chapter may be invoked individually as command-line arguments to ''xm'' or used with ''xm'' in shell mode.
 
To use the options as command-line arguments, use them at a Terminal command prompt as shown in the following example:
 
<pre>
su -
xm list
</pre>
 
To run commands in the xm shell, run the following command:
 
<pre>
[root@fedora7 ~]# xm shell
The Xen Master. Type "help" for a list of functions.
xm>
</pre>
 
At the ''xm>'' prompt enter the options you wish to run, for example:
 
<pre>
su -
[root@fedora7 ~]# xm shell
The Xen Master. Type "help" for a list of functions.
xm> list
Name ID Mem VCPUs State Time(s)
Domain-0 0 384 1 r----- 455.1
XenFed 2 305 1 -b---- 7.7
myFedoraXen 300 1 0.0
myXenGuest 300 1 0.0
xm>
xm> start XenFed
xm> suspend XenFed
xm> restore
</pre>
 
== Listing Guest System Status ==
 
The status of the host and guest systems may be viewed at any time using the ''list'' option of the ''xm'' tool. For example:
 
<pre>
su -
xm list
</pre>
 
The above command will display output containing a line for the host system and a line for each guest similar to the following:
 
<pre>
Name ID Mem VCPUs State Time(s)
Domain-0 0 389 1 r----- 1414.9
XenFed 305 1 349.9
myFedoraXen 300 1 0.0
myXenGuest 6 300 1 -b---- 10.6
</pre>
<htmlet>adsdaqbox_flow</htmlet>
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 IO (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.
 
== 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:
 
<pre>
su -
xm start myGuestOS
</pre>
 
== 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 enter the following command in Terminal window:
 
<pre>
vncviewer
</pre>
 
When prompted for a server enter ''localhost:5900''. A VNC window will subsequently appear containing the running guest system.
 
== Shutting Down a Guest System ==
 
The ''shutdown'' option of the ''xm'' tool is used to shutdown a guest operating system:
 
<pre>
xm shutdown guestName
</pre>
 
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):
 
<pre>
xm destroy myGuestOS
</pre>
 
== 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'':
 
<pre>
xm pause myXenGuest
</pre>
 
Similarly, to resume the paused system:
 
<pre>
xm resume myXenGuest
</pre>
 
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 a 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'':
 
<pre>
xm suspend myGuestOS
</pre>
 
To restore a suspended guest OS:
 
<pre>
xm resume myGuestOS
</pre>
 
== 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:
 
<pre>
xm save myGuestOS path_to_save_file
<pre>
 
To restore a saved guest operating system session:
 
<pre>
xm restore path_to_save_file
</pre>
 
== Rebooting a Guest System ==
 
To reboot a guest operating system:
 
<pre>
xm reboot myGuestOS
</pre>
 
== 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. For example, the following command reduces the memory allocated to a guest system named ''myGuestOS'' to 256Mb:
 
<pre>
xm mem-set myGuestOS 256
</pre>
 
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 other 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).
 
<pre>
xm migrate domainName host
</pre>
 
Optional flags available with this command are:
 
<pre>
-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.
</pre>
 
<htmlet>fedora</htmlet>
 
 
<htmlet>ezoicbottom</htmlet>
<hr>
<table border="0" cellspacing="0" width="100%"><tr>
<td width="20%">[[Installing a Xen Guest OS from the Command-line (virt-install)|Previous]]<td align="center">[[Fedora Linux Essentials|Table of Contents]]<td width="20%" align="right">[[Installing and Configuring Fedora KVM Virtualization|Next]]</td>
<tr>
<td width="20%">Installing a Xen Guest OS from the Command-line (virt-install)<td align="center"><td width="20%" align="right">Installing and Configuring Fedora KVM Virtualization</td>
</table>

Navigation menu