Xen virtual machines: Management options

After you set up a Xen virtual machine, you need to know how to manage it. This tip goes over the management options offered by the xm utility, a powerful command line tool.

In the previous article in this series, you learned how to set up Xen virtual machines. Here, we will explore the

management options that are offered by the xm utility.

The xm utility offers a command line that allows you to do virtually everything you ever need to do with a virtual machine. Graphical utilities are available as well, but they are not half as powerful as the xm command line tool.

Working with the xm tool normally starts with the xm list command. This command shows you a list of available virtual machines and their settings:

lin:~ # xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1885 2 r----- 123.2
main   512 1   33.9
sled10   1024 1   85.1
sles10   512 1   0.0

In the xm list output, you can see a summary of the most important information for operating the virtual machine. In the first column is the name of the virtual machine, followed by status information which includes the ID of the machine, memory allocation, CPU allocation and the current state. In the above listing, you can see that only the domain-0 system is active.

To activate virtual machines, you need xm create. According to command xm help, which displays useage information about the xm command, the xm create command "creates a domain based on <ConfigFile>." Normally, the result of this is that the virtual machine that you refer to is started:

 lin:~ # xm create main Using config file "/etc/xen/vm/main". Started domain main

Now the funny thing is that you don't see anything on your console that would indicate that the machine is started. Only the result of xm list would show you that. You really have two machines that are active. The new virtual machine has an ID now and its current state is indicated as well.

If you really want to see what the virtual machines are doing, I can recommend the xm top command. Like the Linux top command, this command gives a perfectly detailed overview of what your virtual machines are doing, even if the xm top screen is not very well organized.

***xmtop.tif With xm top you'll get a detailed overview of what your virtual machines are doing.

Don't worry if in the result window of xm top you see an indication that at least one machine is blocked. This is no problem at all. A blocked machine is just a machine that hasn't caused any action on the CPU in the last polling loop. This is something that you could typically see on, for example, a not so busy web server.

Of particular interest is the information that you can find on the percentage of CPU usage caused by a virtual machine and the total memory usage. You'll see that the total memory usage is always related to the MAXMEM parameter. This is the maximal amount of memory that a virtual machine can use (which can be easily increased – more about this later.)

At this point you have your virtual machine up and running but without a console attached to it. If you want to see what is happening, you can use the xm console command. This command attaches you to the text based console of the virtual machine. From there, you can perform all the management tasks that you want to on the machine.


***xmconsole.tif The xm console command gives access to the text based console of your virtual machine.

Ready to work from the virtual machine's console? Use the ctrl-] keysequence to return to the console of the domain-0 machine.

Managed or not?
Up to this point, we have been talking about the commands that you would use in an unmanaged environment. Modern Linux distributions like Red Hat Advanced Server and SUSE Linux Enterprise Server work with Xen in a managed environment, called Xenstore. This means that there is a database being used by the xm command line utility and also by graphical utilities like Virtual Machine Manager. If you want your virtual machine to appear in this managed environment, there are some additional xm commands that you should know.

First, after creating the virtual machine, you need the xm new command to add the machine to the managed environment. Once this has been done, use xm start to start the domain. The result of this command is exactly the same as the result of the xm create command, with the exception that tools that depend on the managed environment are also capable of interacting with the virtual machine properly. Finally, you can use the xm delete command to remove the virtual machine from the managed environment.

Stopping and pausing a domain
When working with Xen virtual machines, there are many ways to tell the virtual machine to cease its activities. One of the toughest ways to do this, is by using the xm destroy command. This will terminate a virtual machine immediately, comparable to pulling the power plug from a real server. Using xm destroy is a rather drastic way to stop a machine. As you might imagine, files that were open at the moment that you used this command don't get a chance to be closed decently, so it is more than likely that you'll lose data. It is much better to use the xm shutdown command instead. This will shut down a domain nicely, like using the shutdown command in a Linux environment. You can also use xm reboot to restart a virtual machine.

In a Xen environment, it is possible to pause virtual machines as well. To really pause a virtual machine, you should use xm pause. This stops the machine, but keeps it resident in memory. Use this option if you don't need the virtual machine now but expect to need it soon. After pausing a domain, use the xm unpause command to reactivate the virtual machine.

Saving a virtual machine is a little tougher. In this case, saving means that the current state as it exists in memory is written to a file. After that, the machine is no longer memory resident. This has two advantages over the xm pause command: you can use your physical machine's memory for something else and it is very easy to move or copy the virtual machine to another physical machine. After saving a virtual machine with the xm save command (xm save main main.saved) you can put it back in action using the xm restore command. When using xm restore, you should also refer to the file that you've created when saving the machine.


Overview of commands in this article
xm list Gives a list of all known virtual machines.
xm create Starts an unmanaged virtual machine
xm help Gives an overview of all xm commands that are available
xm top Provides a status overview of all virtual machines
xm console Opens a console that allows you to manage a virtual machine
xm new Adds a virtual machine to the Xenbase managed environment
xm start Starts a virtual machine from the Xenbase managed environment
xm destroy Like pulling the power plug, stops a virtual machine
xm shutdown Shuts down a virtual machine properly
xm reboot Reboots a virtual machine
xm pause Pauses the activity of a virtual machine wihtout liberating used memory resources
xm unpause Activates a virtual machine that has been stopped with the xm pause command
xm save Saves the state of a virtual machine to a file
xm restore Restarts a virtual machine of which the state has been saved to a file

Summary
You now know how to perform basic Xen virtual machine management using the xm command. Next in this series you will find out how to perform more advanced tasks, like hardware management, using the xm command.

About the author: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability (HA) clustering and performance optimization, as well as an expert on SUSE Linux Enterprise Desktop 10 (SLED 10) administration.


This was first published in October 2007

Dig deeper on Citrix XenServer

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close