20.6. Starting, Resuming, and Restoring a Virtual Machine
20.6.1. Starting a Guest Virtual Machine
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 managedsavecommand, 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
virshto 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
--force-boot- discards any
managedsaveoptions and causes a fresh boot to occur
Example 20.3. How to start a virtual machine
virsh start guest1Domain guest1 started Connected to domain guest1 Escape character is ^]
20.6.2. Configuring a Virtual Machine to be Started Automatically at Boot
virsh autostartcommand will automatically start the guest virtual machine when the host machine boots. Adding the
--disableargument 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
virsh autostart guest1
20.6.3. Rebooting a Guest Virtual Machine
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_rebootelement 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
--modeargument can specify a comma separated list which includes
signal. 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
initctlmethod, but you can choose any mode that suits your needs.
virsh reboot guest1
20.6.4. Restoring a Guest Virtual Machine
virsh restore <file> [--bypass-cache] [--xml /path/to/file] [--running] [--paused]command restores a guest virtual machine previously saved with the
virsh savecommand. See Section 20.7.1, “Saving a Guest Virtual Machine's Configuration” for information on the
virsh savecommand. 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.
virsh restorecommand 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
virsh restore guest1-config.xml
20.6.5. Resuming a Guest Virtual Machine
virsh resume domaincommand 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
virsh resume guest1