KVM: Starting / Stopping Guest Operating Systems With virsh Command

You can use the virsh command in KVM (Kernel-based Virtual Machine) to manage guest operating systems, including starting, stopping, and restarting them. Here’s how to do it:

  1. Open a terminal window on your KVM host machine.
  2. Type the following command to display a list of all running and stopped virtual machines:
    virsh list --all

    This will show a list of all virtual machines that are currently defined on your KVM host, along with their current status.

  3. Press Enter to execute the command. You should see output similar to the following:
    Id Name State
    ----------------------------------------------------

    1 vm1 running
    2 vm2 running
    - vm3 shut off

    This output shows three virtual machines, two of which are currently running (vm1 and vm2) and one that is currently shut off (vm3).

  4. To start a virtual machine, type the following command:
    virsh start vm_name

    Replace vm_name with the name of the virtual machine that you want to start. For example, to start vm3, you would type:

    virsh start vm3

    This will start the virtual machine, and you should see its status change to running when you run the virsh list --all command again.

  5. To stop a virtual machine, type the following command:
    virsh shutdown vm_name

    Replace vm_name with the name of the virtual machine that you want to stop. For example, to stop vm1, you would type:

    virsh shutdown vm1

    This will send a shutdown signal to the virtual machine, and it will begin the shutdown process. You can use the virsh list --all command to check the status of the virtual machine and see when it has fully shut down.

  6. To restart a virtual machine, type the following command:
    virsh reboot vm_name

    Replace vm_name with the name of the virtual machine that you want to restart. For example, to restart vm2, you would type:

    virsh reboot vm2

    This will send a restart signal to the virtual machine, and it will begin the restart process. You can use the virsh list --all command to check the status of the virtual machine and see when it has fully restarted.

Using the virsh command, you can easily manage your KVM virtual machines from the command line, including starting, stopping, and restarting them, as well as performing more advanced management tasks like migrating virtual machines between hosts or changing their configuration.

Leave a Comment