Chapter 6. Basic VM Guest Management

Contents

6.1. Listing VM Guests
6.2. Opening a Graphical Console
6.3. Changing a VM Guest's State: Start, Stop, Pause
6.4. Saving and Restoring VM Guests
6.5. Deleting a VM Guest

Basic management tasks such as starting or stopping a VM Guest, can either be done using the graphical application Virtual Machine Manager or on the command line using virsh. Connecting to the graphical console via VNC is only possible from a graphical user interface.

6.1. Listing VM Guests

In order to be able to list VM Guests, you need to connect to a VM Host Server first. If you start the management tool on the VM Host Server itself, you are automatically connected. When operating from remote, refer to Section 7.3, “Connecting to a VM Host Server” for instructions.

6.1.1. Listing VM Guests with Virtual Machine Manager

The main Window of the Virtual Machine Manager shows a list of all VM Guests for each VM Host Server it is connected to. Each VM Guest entry contains the machine's name, its status (Running, Paused, or Shutoff) displayed as icon and literal, and a CPU usage bar.

6.1.2. Listing VM Guests with virsh

Use the command virsh list to get a list of VM Guests:

# list running guests on localhost
virsh -c qemu:///system list
# list running + inactive guests on mercury over TLS connection
virsh -c qemu+tls://mercury.example.com/system list --all
# list running + inactive guests on mercury over SSH connection
virsh -c qemu+ssh://tux@mercury.example.com/system list --inactive

6.2. Opening a Graphical Console

Opening a Graphical Console to a VM Guest lets you interact with the machine like a physical host via a VNC connection. If accessing the VNC server requires authentication, you are prompted to enter a user name (if applicable) and a password.

Once you click into the VNC console, the cursor is grabbed and cannot be used outside the console anymore. To release it, press Alt+Ctrl.

[Tip]Absolute Cursor Movement

In order to prevent the console from grabbing the cursor and to enable absolute (seamless) cursor movement, add a tablet input device to the VM Guest.

Certain key combinations such as Ctrl+Alt+Del are interpreted by the host system and are not passed to the VM Guest.

To pass such key combinations to a VM Guest, open the Send Key menu from the VNC window and choose the desired key combination entry.

[Note]Supported VNC Viewer

Principally all VNC viewers are able to connect to the console of a VM Guest. However, if you are using SASL authentication and/or TLS/SSL connection to access the guest, the options become limited. Common VNC viewers such as tightvnc or tigervnc support neither SASL authentication or TSL/SSL. The only supported alternative to Virtual Machine Manager and virt-viewer is vinagre.

6.2.1. Opening a Graphical Console with Virtual Machine Manager

  1. In the Virtual Machine Manager, right-click on a VM Guest entry.

  2. Choose Open from the pop-up menu.

6.2.2. Opening a Graphical Console with virt-viewer

virt-viewer is a simple VNC viewer with added functionality for displaying VM Guest consoles. It can, for example, be started in wait mode, where it waits for a VM Guest to start before it connects. It also supports automatically reconnecting to a VM Guest that is rebooted.

virt-viewer addresses VM Guests by name, by ID or by UUID. Use virsh list --all to get this data.

To connect to a guest that is running or paused, either use the ID, UUID, or name. VM Guests that are shut off do not have an ID—you can only connect by UUID or name.

# local connect to guest with ID 8
virt-viewer -c qemu:///system 8

# local connect to the inactive guest sles11; will connect once
# the guest starts
virt-viewer --wait sles11
virt-viewer -c qemu:///system --wait sles11

# remote connect via ssh
viewer -c qemu+ssh://tux@mercury.example.com/system 8

# remote connect via ssh wait / reconnect mode:
virt-viewer -c qemu+ssh://root@mercury.example.com/system -w sles11

For more information, see virt-viewer --help or man 1 virt-viewer.

6.3. Changing a VM Guest's State: Start, Stop, Pause

Starting, stopping or pausing a VM Guest can either be done with Virtual Machine Manager or virsh. You can also configure a VM Guest to be automatically started when booting the VM Host Server.

When shutting down a VM Guest, you may either shut it down gracefully, or force the shutdown. The latter is equivalent to pulling the power plug on a physical host and is only recommended if there are no alternatives. Forcing a shutdown may cause file system corruption and loss of data on the VM Guest.

[Tip]Graceful Shutdown

In order to be able to perform a graceful shutdown, the VM Guest must be configured to support ACPI. If you have created the guest with vm-install or with Virtual Machine Manager, ACPI should be available. Use the following procedure in Virtual Machine Manager to check:

Double-click the VM Guest entry in Virtual Machine Manager. Choose View+Details and then Overview+Machine Settings. ACPI should be checked.

Depending on the guest operating system, enabling ACPI may not be sufficient. It is strongly recommended to test shutting down and rebooting a guest before releasing it to production. openSUSE or SUSE Linux Enterprise Desktop, for example, may require PolicyKit authorization for shutdown and reboot. Make sure this policy is turned off on all VM Guests.

If ACPI was enabled during a Windows XP/Server 2003 guest installation, turning it on in the VM Guest configuration alone is not sufficient. See the following articles for more information:

http://support.microsoft.com/kb/314088/EN-US/
http://support.microsoft.com/?kbid=309283

A graceful shutdown is of course always possible from within the guest operating system, regardless of the VM Guest's configuration.

6.3.1. Changing a VM Guest's State with Virtual Machine Manager

Changing a VM Guest's state can either be done from Virtual Machine Manager's main window, or from a VNC window.

Procedure 6.1. State Change from the Virtual Machine Manager Window

  1. Right-click on a VM Guest entry.

  2. Choose Run, Pause, or one of the Shutdown options from the pop-up menu.

Procedure 6.2. State change from the VNC Window

  1. Open a VNC Window as described in Section 6.2.1, “Opening a Graphical Console with Virtual Machine Manager”.

  2. Choose Run, Pause, or one of the Shut Down options either from the toolbar or from the Virtual Machine menu.

6.3.1.1. Autostarting a VM Guest

Automatically starting a guest when the VM Host Server boots is not enabled by default. This feature needs to be turned on for each VM Guest individually. There is no way to activate it globally.

  1. Double-click the VM Guest entry in Virtual Machine Manager to open its console.

  2. Choose View+Details to open the VM Guest configuration window.

  3. Choose Boot Options and check Start virtual machine on host boot up.

  4. Save the new configuration with Apply.

6.3.2. Changing a VM Guest's State with virsh

In the following examples the state of a VM Guest named sles11 is changed. All commands are run directly on the VM Host Server.

virsh -c qemu:///system start sles11                # start
virsh -c qemu:///system suspend sles11              # pause
virsh -c qemu:///system reboot sles11               # reboot
virsh -c qemu:///system shutdown sles11             # graceful shutdown
virsh -c qemu:///system destroy sles11              # force shutdown
virsh -c qemu:///system autostart sles11            # turn on autostart
virsh -c qemu:///system autostart --disable sles11  # turn off autostart

6.4. Saving and Restoring VM Guests

Saving a VM Guest preserves the exact state of the guest’s memory. The operation is slightly similar to hibernating a computer. A saved VM Guest can be quickly restored to its previously saved running condition.

When saved, the VM Guest is paused, its current memory state saved to disk, and then the guest is stopped. The operation does not make a copy of any portion of the VM Guest’s virtual disk. The amount of time to save the virtual machine depends on the amount of memory allocated. When saved, a VM Guest’s memory is returned to the pool of memory available on the VM Host Server.

The restore operation loads a VM Guest’s previously saved memory state file and starts it. The guest is not booted but rather resumes at the point where it was previously saved. The operation is slightly similar to coming out of hibernation.

The VM Guest is saved to a state file. Make sure there is enough space on the partition you are going to save to. Issue the following command on the guest to get a rough estimation of the file size in megabytes to be expected:

free -m | awk '/^Mem:/ {print $3}'
[Warning]

After using the save operation, do not boot, start, or run the saved VM Guest. Doing so would cause the machine's virtual disk and the saved memory state getting out of sync and can result in critical errors when restoring the guest.

6.4.1. Saving / Restoring with Virtual Machine Manager

Procedure 6.3. Saving a VM Guest

  1. Open a VNC connection window to a VM Guest. Make sure the guest is running.

  2. Choose Virtual Machine+Save

  3. Choose a location and a file name.

  4. Click Save. Saving the guest's state may take some time. After the operation has finished, the VM Guest will automatically shut down.

Procedure 6.4. Restoring a VM Guest

  1. Start the Virtual Machine Manager.

  2. Type Alt+R or choose File+Restore Saved Machine.

  3. Choose the file you want to restore and proceed with Open. Once the file has been successfully loaded, the VM Guest is up and running.

6.4.2. Saving / Restoring with virsh

Save a running VM Guest with the command virsh save:

# save the guest named opensuse11
virsh save opensuse11 /virtual/saves/opensuse11.vmsave
   
# save the guest with Id 37
virsh save 37 /virtual/saves/opensuse11.vmsave

To restore it, use virsh restore:

virsh restore /virtual/saves/opensuse11.vmsave

6.5. Deleting a VM Guest

Deleting a VM Guest removes its XML configuration by default. Since the attached storage is not deleted, you will be able to use it with another VM Guest. With Virtual Machine Manager you may also delete a guest's storage files as well—this will completely erase the guest.

In order to delete a VM Guest, it has to be shut down first (refer to Section 6.3, “Changing a VM Guest's State: Start, Stop, Pause” for instructions). It is not possible to delete a running guest.

6.5.1. Deleting a VM Guest with Virtual Machine Manager

  1. In the Virtual Machine Manager, right-click on a VM Guest entry.

  2. Choose Delete from the pop-up menu.

  3. A confirmation window opens. Clicking Delete will permanently erase the VM Guest. The deletion is not recoverable.

    You may also choose to permanently delete the guest's virtual disk by ticking Delete Associated Storage Files. The deletion is not recoverable either.

6.5.2. Deleting a VM Guest with virsh

To delete a VM Guest with virsh run virsh undefine VM_NAME. There is no option to automatically delete the attached storage files.