<chapter id="gfwlm"><title>xVM System Administration</title><highlights><para>This chapter covers xVM system administration topics.</para>
</highlights><sect1 id="gfxwb"><title>Printing Kernel and Machine Information</title><para>Use <literal>uname</literal> to determine the kernel you are running.</para><screen>hostname% <userinput>uname -a</userinput>
SunOS hostname 5.11 snv_80 i86pc i386 i86xpv</screen><para>Use the <command>isainfo</command> command to print the basic application
environments supported by the currently running system.</para><screen>hostname% <userinput>isainfo -x</userinput>
amd64: sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov cx8 tsc fpu
i386: ahf sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov cx8 tsc fpu</screen><para>Use the <command>psrinfo</command> command to display information about
processors.</para><screen>hostname% <userinput>psrinfo -vp</userinput>
The physical processor has 1 virtual processor (0)
x86 (Authentic AMD family 15 model 5 step 10 clock 2200 MHz)
Dual Core AMD Opteron(tm) Processor 275</screen>
</sect1><sect1 id="gfwvl"><title><command>virsh</command> Command and Domain Management</title><para>The main command
interface used to control both Solaris xVM and guest domains is the <command>virsh</command> command. <command>virsh</command> provides a generic and stable
interface for controlling virtualized operating systems. Use <command>virsh</command> instead
of <command>xm</command> wherever possible.</para><para>Many <command>virsh</command> commands act asynchronously. This means
that the system prompt can return before the operation has completed.</para><para>If you modify CPUs or memory by using the <command>virsh</command> command,
these changes will be saved in the configuration file and persist across reboots.</para><sect2 id="gfyiv"><title><command>virsh</command> Command Structure</title><para>Most <command>virsh</command> commands follow the format:</para><screen># <userinput>virsh subcommand domain-id | name | uuid [options]</userinput></screen><variablelist><varlistentry><term><replaceable>subcommand</replaceable></term><listitem><para>One of the subcommands listed in the <olink targetdoc="group-refman" targetptr="virsh-1m" remap="external"><citerefentry><refentrytitle>virsh</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> man page</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>domain-id</replaceable>, <replaceable>name</replaceable>,
or <replaceable>uuid</replaceable></term><listitem><para>A domain identifier</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>options</replaceable></term><listitem><para>An option to a subcommand</para>
</listitem>
</varlistentry>
</variablelist><example id="gfyib"><title>Using a <command>virsh</command> Command</title><para>This line connects to a domU named <replaceable>sxc18</replaceable>.</para><screen># <userinput>virsh console sxc18</userinput></screen>
</example>
</sect2><sect2 id="ggcnd"><title><command>virsh</command>Command</title><para>The <command>virsh</command> is used to manage domains. You must run
the commands as the root user or by assuming the Primary Administrator role
on the host operating system. The commands cannot be run in the guest domain.</para><informaltable frame="topbot"><tgroup cols="2" colsep="0" rowsep="0"><colspec colwidth="50*"/><colspec colwidth="50*"/><thead><row rowsep="1"><entry><para><command>virsh</command> Command</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><command>virsh</command><literal>attach-device</literal></para>
</entry><entry><para>Attach device from an XML file </para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>attach-disk</literal></para>
</entry><entry><para>Attach disk device</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>autostart</literal></para>
</entry><entry><para>Configure a domain to automatically start at boot time.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>capabilities</literal></para>
</entry><entry><para>Return capabilities of the hypervisor and drivers.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>connect</literal></para>
</entry><entry><para>Connect to the hypervisor.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>connect</literal><literal>--readonly</literal></para>
</entry><entry><para>Connect to the hypervisor in read-only mode.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>console</literal><literal>domain</literal></para>
</entry><entry><para>Connect to a guest console</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>create</literal> <replaceable>file</replaceable></para>
</entry><entry><para>Create a domain based on the parameters contained in the
XML file, where <replaceable>file</replaceable> is an absolute pathname. Such
a file can be created using <command>virsh</command> <literal>dumpxml</literal> subcommand.
The XML configuration file should not be directly edited.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>define</literal> <replaceable>file</replaceable></para>
</entry><entry><para>Define a domain from an XML file, but do not start the domain</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>destroy</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Terminate a domain immediately</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>detach-device</literal> <replaceable>domain-id</replaceable><replaceable>file</replaceable></para>
</entry><entry><para>Detach a device defined by the given XML file from the specified domain.</para>
</entry>
</row><row><entry><para><command>virsh</command> <replaceable>domid</replaceable> <replaceable>domain_name</replaceable></para>
</entry><entry><para>Converts a domain name to a numeric domain ID.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>dominfo</literal> <replaceable>domain_id</replaceable></para>
</entry><entry><para>Return basic info about a domain</para>
</entry>
</row><row><entry><para><command>virsh</command> <replaceable>domname</replaceable> <replaceable>domain_id</replaceable></para>
</entry><entry><para>Converts a numeric domain ID to a domain name.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>domstate</literal> <replaceable>domain_id</replaceable></para>
</entry><entry><para>Returns the state of a running domain. See the <literal>list</literal> subcommand.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>domuuid</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Convert the specified domain name or ID to a domain UUID. </para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>dump</literal> <replaceable>domain</replaceable><replaceable>file</replaceable></para>
</entry><entry><para>Dump the core of the domain specified by <replaceable>domain</replaceable> to
the file specified by file for analysis.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>dumpxml</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Obtain domain information in XML</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>help</literal></para>
</entry><entry><para>Display descriptions of the subcommands. Include a subcommand at the
end of the command line to display help about that subcommand.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>list</literal> </para>
</entry><entry><para>List domains. By
default, only running domains are displayed. Use <literal>--inactive</literal> to
display only non-running domains.  Use <literal>--all</literal> to display
both running and non-running domains.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>nodeinfo</literal> </para>
</entry><entry><para>Print basic information about a node.</para><screen># virsh nodeinfo
CPU model:           i86pc
CPU(s):              2
CPU frequency:       2391 MHz
CPU socket(s):       2
Core(s) per socket:  1
Thread(s) per core:  1
NUMA cell(s):        1
Memory size:         4127744 kB</screen>
</entry>
</row><row><entry><para><command>virsh</command> <literal>quit</literal> </para>
</entry><entry><para>Quit this interactive terminal</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>reboot</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Reboot a domain.</para><para>This command is
identical
to the effect of running <literal>init 6</literal>. The command returns
immediately, but the entire reboot process might
take a minute or more.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>restore</literal> <replaceable>state-file</replaceable></para>
</entry><entry><para>Restore a domain from a saved state file.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>resume</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Moves a domain out of the paused state, making the
domain eligible for scheduling by the hypervisor.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>reboot</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Reboot a domain</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>restore</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Restore a domain from a saved state</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>resume</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>Resume running a suspended domain.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>save</literal> <replaceable>domain</replaceable> <replaceable>state-file</replaceable></para>
</entry><entry><para>Save a running domain to a state file so that it can be restored by
using the <command>restore</command> subcommand at a later time. In this state,
the domain is not running on the
system, thus the memory allocated for the domain will be
free for use br other domains.</para><para>Note that network connections present before the save
operation might be severed because TCP timeouts might have
expired.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>setvcpus</literal> <replaceable>domain</replaceable><replaceable>count</replaceable></para>
</entry><entry><para>Change the number of virtual CPUs active in the specified guest domain.
The <replaceable>count</replaceable> parameter is the number of virtual CPUs.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>schedinfo</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Show or set the scheduling paramaters for the specified
domain name, ID, or UUID. This subcommand takes the options <literal>--weight
number</literal> and <literal>--cap number</literal>.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>setmaxmem</literal> <replaceable>domain</replaceable> <replaceable>kilobytes</replaceable></para>
</entry><entry><para>Change the maximum memory allocation limit in the specified
guest domain. The <replaceable>kilobytes</replaceable> parameter is the maximum
memory limit in kilobytes.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>setmem</literal> <replaceable>domain</replaceable> <replaceable>kilobytes</replaceable></para>
</entry><entry><para>Change the current memory allocation in the specified
guest domain. The <replaceable>kilobytes</replaceable> parameter is the number
of kilobytes in
memory.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>setvcpus</literal> <replaceable>domain</replaceable> <replaceable>count</replaceable></para>
</entry><entry><para>Change the number of virtual CPUs active in the specified
guest domain. The <replaceable>count</replaceable> parameter is the number
of
virtual CPUs.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>shutdown</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Coordinates with the domain operating system to perform graceful shutdown.
The effect of this command is identical to the effect of running <literal>init
5</literal>.</para><para>The shutdown might take an unexpected
length of time, depending on the services that must be shut down
in the domain. In addition, it is possible that the
subcommand will not succeed.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>start</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Start a previously defined inactive domain.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>suspend</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Suspend a domain. A domain in this state still
consumes allocated resources, such as memory, but is not
eligible for scheduling by the hypervisor.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>undefine</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Undefine the configuration for the inactive domain by specifying either
its domain name or UUID.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>vcpuinfo</literal> <replaceable>domain</replaceable></para>
</entry><entry><para>Return basic information about the domain's virtual CPUs.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>vcpupin</literal> <replaceable>domain</replaceable> <replaceable>vcpu</replaceable> <replaceable>cpulist</replaceable></para>
</entry><entry><para>Pin domain's virtual CPUs to the host's physical CPUs. The <replaceable>domain</replaceable> parameter is the domain name, ID, or UUID. The <replaceable>vcpu</replaceable> parameter
is the VCPU number. The <replaceable>cpulist</replaceable> parameter is a
list of host CPU numbers, separated by commas.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>version</literal> </para>
</entry><entry><para>Display version information.</para>
</entry>
</row><row><entry><para><command>virsh</command> <literal>vncdisplay</literal> <replaceable>domain-id</replaceable></para>
</entry><entry><para>VNC display</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect2><sect2 id="gfyhp"><title>Suspend and Resume Functions and Commands</title><para>Some xVM operations are not yet implemented in the <command>virsh</command> command.
In those cases, the equivalent <command>xm</command> command can be used.
Subcommand terminology differs between the <command>xm</command>and <command>virsh</command> commands. In particular, the <literal>suspend</literal> and <literal>resume</literal> commands have different meanings.</para><table frame="topbot" id="gfydj"><title>Equivalent <command>virsh</command> and <command>xm</command>Commands</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colwidth="50*"/><colspec colwidth="50*"/><thead><row rowsep="1"><entry><para><command>virsh</command></para>
</entry><entry><para><command>xm</command></para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>suspend</literal></para>
</entry><entry><para><literal>pause</literal></para>
</entry>
</row><row><entry><para><literal>resume</literal></para>
</entry><entry><para><literal>unpause</literal></para>
</entry>
</row><row><entry><para><literal>save</literal></para>
</entry><entry><para><literal>suspend</literal> without an output file argument</para>
</entry>
</row><row><entry><para><literal>restore</literal></para>
</entry><entry><para><literal>resume</literal> without an output file argument</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
</sect1><sect1><title>Cloning ZFS-Based Solaris Domains</title><para>If you are using a ZFS volume as the root disk for a domU, you can use
the ZFS snapshot facilities to clone another domU with the same configuration.
By taking a clone of the root disk, you can quickly provision similar domains.</para><para>For example, you might install Solaris as a guest domain, run <olink targetdoc="group-refman" targetptr="sys-unconfig-1m" remap="external"><citerefentry><refentrytitle>sys-unconfig</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink>, then clone that disk image for use in new Solaris
domains. Installing a Solaris domain in this way requires only the configuration
step, rather than a full install. The only extra storage used for the cloned
domain is the amount needed for the differences between the domains.</para><para>You also have the capability to revert to a previous configuration if
necessary.</para><note><para>Any clones created from a snapshot must be destroyed before the
snapshot can be destroyed.</para>
</note><task id="gfwlt"><title>How to Use ZFS Snapshot to Clone a Solaris DomU</title><tasksummary><para>If you use a ZFS volume as the virtual disk for your guest domain, you
can take a snapshot of the storage. The snapshot is used to create clones.</para><para>Note that you might want to use the <command>sys-unconfig</command> command
described in <olink targetdoc="group-refman" targetptr="sys-unconfig-1m" remap="external"><citerefentry><refentrytitle>sys-unconfig</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> in the domain before you take the snapshot. The resulting
clones would not have host names or name services configured, which is also
known as "as-manufactured." When it comes up, the new clone displays the configuration
screens.</para>
</tasksummary><procedure><step><para>Become superuser, or assume the Primary Administrator role.</para>
</step><step><para>(Optional) To create a snapshot to produce domains that require <literal>sysidcfg</literal> to complete system identification, use the <command>sys-unconfig</command> command in a domain named <literal>domain1</literal>.</para>
</step><step><para>Shut down <literal>domain1</literal>.</para><screen># <userinput>virsh shutdown domain1</userinput></screen>
</step><step><para>Take a snapshot of the root disk used by <literal>domain1</literal>.</para><screen># <userinput>zfs snapshot pool/domain1-root@clone</userinput></screen>
</step><step><para>Create a clone named <literal>domain2</literal> from the snapshot <literal>domain1-root@clone</literal>.</para><screen># <userinput>zfs clone pool/domain1-root@clone pool/domain2-root</userinput></screen>
</step><step><para>(Optional) Display the snapshot and clone.</para><screen># <userinput>zfs list</userinput>
NAME                   USED  AVAIL  REFER  MOUNTPOINT
pool                  92.0K  67.0G   9.5K  /pool
pool/domain1          8K  67.0G     8K     /pool/domain1
pool/domain2          8K  67.0G     8K     /pool/domain2</screen>
</step><step><para>Dump the configuration of <literal>domain1</literal>.</para><screen># <userinput>virsh dumpxml domain1 >domain1.xml</userinput></screen>
</step><step><para>Copy the configuration file <literal>domain1.xml</literal> to
a file named <literal>domain2.xml</literal>.</para><screen># <userinput>cp domain1.xml domain2.xml</userinput></screen>
</step><step><para>Make the following changes in the <literal>domain2.xml</literal> file.</para><substeps><step><para>Replace <literal>domain1</literal> in this line:</para><screen>&lt;name>domain1&lt;/name></screen><para>With the new name, <literal>domain2</literal>:</para><screen>&lt;name>domain2&lt;/name></screen>
</step><step><para>So that <command>virsh</command> will generate a new domain configuration,
remove the UUID line, which looks like this:</para><screen>&lt;uuid>72bb96b6e6cf13594fb0cd1290610611&lt;/uuid></screen>
</step><step><para>Point to the new disk by editing the following line:</para><screen>&lt;source dev='/dev/zvol/dsk/export/domain1-root'/></screen><para>Change <literal>domain1&ndash;root</literal> to <literal>domain2&ndash;root</literal> so that the line appears as follows:</para><screen>&lt;source dev='/dev/zvol/dsk/export/domain2-root'/></screen>
</step>
</substeps>
</step><step><para>Inform <literal>virsh</literal> about the new domain:</para><screen># <userinput>virsh define domain2.xml</userinput></screen>
</step><step><para>Boot the cloned domain.</para>
</step>
</procedure><taskrelated-custom><title>More Information on ZFS Snapshot Features</title><para>Also see <olink targetdoc="zfsadmin" targetptr="gavvx" remap="external">Chapter 7, <citetitle remap="chapter">Working With ZFS Snapshots and Clones,</citetitle> in <citetitle remap="book">Solaris ZFS Administration Guide</citetitle></olink>.</para>
</taskrelated-custom>
</task><sect2 id="gfwlu"><title>Recovery</title><para>Thus, you can keep snapshots of the guest domain OS installations that
are known to be good images, and use ZFS rollback to revert to a snapshot
if the domain has a problem. For more information, see <olink targetdoc="zfsadmin" targetptr="gbcxk" remap="external"><citetitle remap="section">Rolling
Back to a ZFS Snapshot</citetitle> in <citetitle remap="book">Solaris ZFS
Administration Guide</citetitle></olink>.</para>
</sect2>
</sect1><sect1 id="gfwzt"><title>Communication From xVM Hypervisor to Dom0 Using <command>xm</command></title><para>Although the hypervisor
and dom0 work closely together to manage a running system, the dom0 operating
system has little direct visibility into the hypervisor. The hypervisor's
entire address space is inaccessible to the dom0.</para><para>The only source of information is provided by the <command>xm</command> command,
a user-space tool that communicates with the hypervisor via hypercalls.</para><para>Some of the commonly used <command>xm</command> commands are:</para><variablelist><varlistentry><term><literal>xm info</literal></term><listitem><para>Report static information about the machine, such as number
of CPUs, total memory, and xVM version.</para><screen># xm info
host                   : test
release                : 5.11
version                : onnv-userj
machine                : i86pc
nr_cpus                : 2
nr_nodes               : 1
sockets_per_node       : 2
cores_per_socket       : 1
threads_per_core       : 1
cpu_mhz                : 2391
hw_caps                : 078bfbff:e1d3fbff:00000000:00000010
total_memory           : 4031
free_memory            : 1953
xen_major              : 3
xen_minor              : 1
xen_extra              : .2-xvm
xen_caps               : xen-3.0-x86_64 xen-3.0-x86_32p
xen_scheduler          : credit
xen_pagesize           : 4096
platform_params        : virt_start=0xffff800000000000
xen_changeset          : Thu Dec 20 20:11:49 2007 -0800 15623:41d827ccece7
cc_compiler            : gcc version 3.4.3 (csl-sol210-3_4-20050802)
cc_compile_by          : userj
cc_compile_domain      : lab.sun.com
cc_compile_date        : Thu Dec 20 20:24:36 PST 2007
xend_config_format     : 4</screen>
</listitem>
</varlistentry><varlistentry><term><literal>xm list</literal></term><listitem><para>List all domains and some high-level information.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xm top</literal></term><listitem><para>Analogous to the Linux <command>top</command> command, but
it reports domain information instead of process information. Information
about the xVM system and domains is displayed in a continuously updating manner
through the <literal>xentop</literal> command. See <literal>xentop</literal>.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xm log</literal></term><listitem><para>Display the contents of the <literal>xend</literal> log.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xm help</literal></term><listitem><para>List all the available commands.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xentrace</literal></term><listitem><para>Capture trace buffer data from xVM.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xentop</literal></term><listitem><para>Display information about the xVM system and domains in a
continuously updating manner. See <literal>xm top</literal>.</para>
</listitem>
</varlistentry><varlistentry><term><literal>xm start</literal> <replaceable>domain</replaceable></term><listitem><para>Start a managed domain that was created by <command>virt-install</command>.</para>
</listitem>
</varlistentry>
</variablelist><para>If you modify guest domain CPUs or memory by using the <command>xm</command> command,
these changes will be saved in the configuration file and persist across reboots.</para><para>See the <command>xm</command>(1M) man page for more information.</para>
</sect1><sect1 id="gfwug"><title>About Crash Dumps</title><para>On a running system, the hypervisor's memory is completely off-limits
to dom0. If the hypervisor crashes, however, the resulting panic dump will
generate a <command>core</command> file that provides a unified view of both
xVM and dom0. In this <command>core</command> file, xVM appears as a Solaris
kernel module named <literal>xpv</literal>. For example:</para><screen> > $c
                xpv`panic+0xbf()
                xpv`do_crashdump_trigger+0x19()
                xpv`keypress_softirq+0x35()
                xpv`do_softirq+0x54()
                xpv`idle_loop+0x55()</screen><itemizedlist><para>The following applies to crash dumps:</para><listitem><para>If a dom0 crashes with a standard Solaris panic, the dump
will include only the dom0.</para>
</listitem><listitem><para>When the hypervisor itself panics, the resulting dump includes
the xVM state as well as the dom0 state.</para>
</listitem>
</itemizedlist>
</sect1>
</chapter>