20.6. Starting, Resuming, and Restoring a Virtual Machine

download PDF

20.6.1. Starting a Guest Virtual Machine

The virsh start domain; [--console] [--paused] [--autodestroy] [--bypass-cache] [--force-boot] command starts an inactive virtual machine that was already defined but whose state is inactive since its last managed save state or a fresh boot. By default, if the domain was saved by the virsh managedsave command, the domain will be restored to its previous state. Otherwise, it will be freshly booted. The command can take the following arguments and the name of the virtual machine is required.
  • --console - will attach the terminal running virsh to the domain's console device. This is runlevel 3.
  • --paused - if this is supported by the driver, it will start the guest virtual machine in a paused state
  • --autodestroy - the guest virtual machine is automatically destroyed when virsh disconnects
  • --bypass-cache - used if the guest virtual machine is in the managedsave
  • --force-boot - discards any managedsave options and causes a fresh boot to occur

Example 20.3. How to start a virtual machine

The following example starts the guest1 virtual machine that you already created and is currently in the inactive state. In addition, the command attaches the guest's console to the terminal running virsh:
# virsh start guest1 --console
Domain guest1 started
Connected to domain guest1
Escape character is ^]

20.6.2. Configuring a Virtual Machine to be Started Automatically at Boot

The virsh autostart [--disable] domain command will automatically start the guest virtual machine when the host machine boots. Adding the --disable argument to this command disables autostart. The guest in this case will not start automatically when the host physical machine boots.

Example 20.4. How to make a virtual machine start automatically when the host physical machine starts

The following example sets the guest1 virtual machine which you already created to autostart when the host boots:
# virsh autostart guest1

20.6.3. Rebooting a Guest Virtual Machine

Reboot a guest virtual machine using the virsh reboot domain [--mode modename] command. Remember that this action will only return once it has executed the reboot, so there may be a time lapse from that point until the guest virtual machine actually reboots. You can control the behavior of the rebooting guest virtual machine by modifying the on_reboot element in the guest virtual machine's XML configuration file. By default, the hypervisor attempts to select a suitable shutdown method automatically. To specify an alternative method, the --mode argument can specify a comma separated list which includes acpi and agent. The order in which drivers will try each mode is undefined, and not related to the order specified in virsh. For strict control over ordering, use a single mode at a time and repeat the command.

Example 20.5. How to reboot a guest virtual machine

The following example reboots a guest virtual machine named guest1. In this example, the reboot uses the initctl method, but you can choose any mode that suits your needs.
# virsh reboot guest1 --mode initctl

20.6.4. Restoring a Guest Virtual Machine

The virsh restore <file> [--bypass-cache] [--xml /path/to/file] [--running] [--paused] command restores a guest virtual machine previously saved with the virsh save command. See Section 20.7.1, “Saving a Guest Virtual Machine's Configuration” for information on the virsh save command. The restore action restarts the saved guest virtual machine, which may take some time. The guest virtual machine's name and UUID are preserved, but the ID will not necessarily match the ID that the virtual machine had when it was saved.
The virsh restore command can take the following arguments:
  • --bypass-cache - causes the restore to avoid the file system cache but note that using this flag may slow down the restore operation.
  • --xml - this argument must be used with an XML file name. Although this argument is usually omitted, it can be used to supply an alternative XML file for use on a restored guest virtual machine with changes only in the host-specific portions of the domain XML. For example, it can be used to account for the file naming differences in underlying storage due to disk snapshots taken after the guest was saved.
  • --running - overrides the state recorded in the save image to start the guest virtual machine as running.
  • --paused - overrides the state recorded in the save image to start the guest virtual machine as paused.

Example 20.6. How to restore a guest virtual machine

The following example restores the guest virtual machine and its running configuration file guest1-config.xml:
# virsh restore guest1-config.xml --running

20.6.5. Resuming a Guest Virtual Machine

The virsh resume domain command restarts the CPUs of a domain that was suspended. This operation is immediate. The guest virtual machine resumes execution from the point it was suspended. Note that this action will not resume a guest virtual machine that has been undefined. This action will not resume transient virtual machines and will only work on persistent virtual machines.

Example 20.7. How to restore a suspended guest virtual machine

The following example restores the guest1 virtual machine:
# virsh resume guest1
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.