10.2. Saving a virtual machine using the command line interface
You can save a virtual machine (VM) and its current state to the host’s disk. This is useful, for example, when you need to use the host’s resources for some other purpose. The saved VM can then be quickly restored to its previous running state.
To save a VM using the command line, follow the procedure below.
Conditions préalables
- Ensure you have sufficient disk space to save the VM and its configuration. Note that the space occupied by the VM depends on the amount of RAM allocated to that VM.
- Ensure the VM is persistent.
- Optional: Back up important data from the VM if required.
Procédure
Use the
virsh managedsave
utility.For example, the following command stops the demo-guest1 VM and saves its configuration.
# virsh managedsave demo-guest1 Domain 'demo-guest1' saved by libvirt
The saved VM file is located by default in the /var/lib/libvirt/qemu/save directory as demo-guest1.save.
The next time the VM is started, it will automatically restore the saved state from the above file.
Vérification
List the VMs that have managed save enabled. In the following example, the VMs listed as saved have their managed save enabled.
# virsh list --managed-save --all Id Name State ---------------------------------------------------- - demo-guest1 saved - demo-guest2 shut off
To list the VMs that have a managed save image:
# virsh list --with-managed-save --all Id Name State ---------------------------------------------------- - demo-guest1 shut off
Note that to list the saved VMs that are in a shut off state, you must use the
--all
or--inactive
options with the command.
Résolution de problèmes
- If the saved VM file becomes corrupted or unreadable, restoring the VM will initiate a standard VM boot instead.
Ressources supplémentaires
-
The
virsh managedsave --help
command - Restoring a saved VM using the command-line interface
- Restoring a saved VM using the web console