8.3. Restarting a virtual machine by using the command line
Restarting a virtual machine (VM) requires different steps based on whether the VM is responsive.
Procedure
Restarting a responsive VM
- If you are connected to the guest, use a restart command or a GUI element appropriate to the guest operating system.
Alternatively, use the
virsh rebootcommand on the host:If the VM is on a local host:
# virsh reboot demo-guest1 Domain 'demo-guest1' is being rebootedIf the VM is on a remote host, in this example 192.0.2.1:
# virsh -c qemu+ssh://root@192.0.2.1/system reboot demo-guest1 root@192.0.2.1's password: Domain 'demo-guest1' is being rebooted
Restarting an unresponsive VM
Force a VM to shut down.
# virsh destroy demo-guest1 Domain 'demo-guest1' destroyed注意The
virsh destroycommand does not actually delete or remove the VM configuration or disk images. It only terminates the running instance of the VM, similarly to pulling the power cord from a physical machine.In rare cases,
virsh destroymay cause corruption of the VM’s file system, so use this command only if all other shutdown methods have failed.Start the VM again.
# virsh start demo-guest1 Domain 'demo-guest1' started
Verification
On the host, display the list of your VMs to see their status.
# virsh list --all Id Name State ------------------------------------------ 1 demo-guest1 running