Basic Xen guest management

Starting a guest domain

Now that we have installed and configured a guest domain you are probably eager to start it running and see what all this work has been for. The example below shows how to start the guest domain we created in the previous section. As you can see we have used the xm application with the create command to specify that we wish to create a domain. We have also specified the name of our domain, someguest in the example below. The final component of the command, the -c option instructs the xm application to bind a virtual console to the domain and display it immediately the domain has been created allowing us to see any boot-time messages in case something goes wrong.

lisa xm create someguest -c
Information:
You can exit from the guest console by pressing CTRL ] and reconnect to the guest console using xm console someguest should you need to do so. An alternative is to use the screen application to multiplex the consoles of all guests to a single screen session.
 

Once the guest domain has stated correctly you can either log in using the virtual console or disconnect, using the CTRL ] key combination, and connect over a network using an ssh client.

lisa ssh root@192.168.1.1

Listing running guest domains

The xm application provides a variety of management functions besides domain creation. The next function we shall examine allows an administrator to display a list of the running domains along with some basic information regarding their state.

lisa xm list
Name                                        ID   Mem VCPUs      State   Time(s) 
Domain-0                                     0  2333     1     r-----   2777.8 
backup1                                      6   512     1     -b----    208.3 
dns1                                         2   512     1     -b----    268.4 
mail                                         3  1024     2     -b----   2596.6 
portage                                      1  2048     3     -b----  30638.4 
vcs                                          4   512     1     -b----     70.6 
web                                          5   512     1     -b----   1163.5 

The above example shows the output from the xm list command on a system with several running guest domains. As you can see the host domain is listed as Domain-0 and will always have an ID of zero. The Mem column indicates the allocated memory for the domain and the VCPUs column indicates how many virtual CPUs have been assigned to that guest domain. The next column, titled State, displays the current state of the domain which in the above example is either r to indicate a running domain or b indicating a domain which is blocked, probably with nothing to do. The final column details the total CPU time in seconds that the domain has consumed since it was created.

Terminating guest domains

There are two methods of gracefully shutting down a Xen guest domain. The first is to connect to that domain over ssh or the virtual console and issue the shutdown command as one would when shutting down a normal system. The second method is to use the xm application as shown below.

lisa xm shutdown someguest

Both of these methods assume that the guest domain is running normally and will cooperate with the shutdown request. Unfortunately this is not always the case and an errant guest domain, whether through a fault or through malicious action, can sometimes not respond to the shutdown request. In this case the xm application can be instructed to be more forceful and terminate the guest domain immediately by using the destroy command.

lisa xm destroy someguest

Pausing and un-pausing guest domains

In addition to allowing a guest domain to be started and shutdown the Xen virtualisation environment also supports pausing and un-pausing a running guest domain.

lisa xm pause someguest
lisa xm list
Name                                        ID   Mem VCPUs      State   Time(s) 
Domain-0                                     0  6941     1     r-----   2777.8 
someguest                                    1   512     1     --p---     22.9 
lisa xm unpause someguest
lisa xm list
Name                                        ID   Mem VCPUs      State   Time(s) 
Domain-0                                     0  6941     1     r-----   2777.8 
someguest                                    1   512     1     -b----     23.0 

As you can see from the above example paused domains have a p displayed in the State column. As the domain is still running, simply paused, the domain will continue to occupy memory on the host system and any devices, such as disk volumes, will still be in use. As the guest domain is still resident in memory it will not survive a reboot of the host system.