Chapter 10. Saving and restoring virtual machines To free up system resources, you can shut down a virtual machine (VM) running on that system. However, when you require the VM again, you must boot up the guest operating system (OS) and restart the applications, which may take a considerable amount of time. To reduce this downtime and enable the VM workload to start running sooner, you can use the save and restore feature to avoid the OS shutdown and boot sequence entirely. This section provides information about saving VMs, as well as about restoring them to the same state without a full VM boot-up. 10.1. How saving and restoring virtual machines works Saving a virtual machine (VM) saves its memory and device state to the host's disk, and immediately stops the VM process. You can save a VM that is either in a running or paused state, and upon restoring, the VM will return to that state. This process frees up RAM and CPU resources on the host system in exchange for disk space, which may improve the host system performance. When the VM is restored, because the guest OS does not need to be booted, the long boot-up period is avoided as well. To save a VM, you can use the command line (CLI). For instructions, see Saving virtual machines by using the command line . To restore a VM you can use the CLI or the web console GUI . You can also save and restore the state of a VM by using snapshots. For more information, see Saving and restoring virtual machine state by using snapshots . 10.2. Saving a virtual machine by using the command line 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 running state. To save a VM by using the command line, follow the procedure below. Prerequisites 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. Procedure Use the virsh managedsave utility. For example, the following command stops the demo-guest1 VM and saves its configuration. The saved VM file is located by default in the /var/lib/libvirt/qemu/save directory as demo-guest1.save . The time the VM is started , it will automatically restore the saved state from the above file. Verification List the VMs that have managed save enabled. In the following example, the VMs listed as saved have their managed save enabled. To list the VMs that have a managed save image: 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. Troubleshooting If the saved VM file becomes corrupted or unreadable, restoring the VM will initiate a standard VM boot instead. Additional resources The virsh managedsave --help command Restoring a saved VM by using the command line Restoring a saved VM by using the web console 10.3. Starting a virtual machine by using the command line You can use the command line (CLI) to start a shut-down virtual machine (VM) or restore a saved VM. By using the CLI, you can start both local and remote VMs. Prerequisites An inactive VM that is already defined. The name of the VM. For remote VMs: The IP address of the host where the VM is located. Root access privileges to the host. Procedure For a local VM, use the virsh start utility. For example, the following command starts the demo-guest1 VM. For a VM located on a remote host, use the virsh start utility along with the QEMU+SSH connection to the host. For example, the following command starts the demo-guest1 VM on the 192.0.2.1 host. Additional resources The virsh start --help command Setting up easy access to remote virtualization hosts Starting virtual machines automatically when the host starts 10.4. Starting virtual machines by using the web console If a virtual machine (VM) is in the shut off state, you can start it by using the RHEL 9 web console. You can also configure the VM to be started automatically when the host starts. Prerequisites You have installed the RHEL 9 web console. You have enabled the cockpit service. Your user account is allowed to log in to the web console. For instructions, see Installing and enabling the web console . The web console VM plug-in is installed on your system . An inactive VM that is already defined. The name of the VM. Procedure In the Virtual Machines interface, click the VM you want to start. A new page opens with detailed information about the selected VM and controls for shutting down and deleting the VM. Click Run . The VM starts, and you can connect to its console or graphical output . Optional: To configure the VM to start automatically when the host starts, toggle the Autostart checkbox in the Overview section. If you use network interfaces that are not managed by libvirt, you must also make additional changes to the systemd configuration. Otherwise, the affected VMs might fail to start, see starting virtual machines automatically when the host starts . Additional resources Shutting down virtual machines in the web console Restarting virtual machines by using the web console

Commands:
virsh managedsave demo-guest1 Domain 'demo-guest1' saved by libvirt
virsh list --managed-save --all Id Name State ---------------------------------------------------- - demo-guest1 saved - demo-guest2 shut off
virsh list --with-managed-save --all Id Name State ---------------------------------------------------- - demo-guest1 shut off
virsh start demo-guest1 Domain 'demo-guest1' started
virsh -c qemu+ssh://root@192.0.2.1/system start demo-guest1 root@192.0.2.1's password: Domain 'demo-guest1' started