{"id":7730,"date":"2021-01-28T22:26:55","date_gmt":"2021-01-28T19:26:55","guid":{"rendered":"https:\/\/kifarunix.com\/?p=7730"},"modified":"2024-03-19T20:39:31","modified_gmt":"2024-03-19T17:39:31","slug":"start-and-stop-kvm-virtual-machines-from-command-line","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/start-and-stop-kvm-virtual-machines-from-command-line\/","title":{"rendered":"Start and Stop KVM Virtual Machines from Command Line"},"content":{"rendered":"
This guide will take you through how to start and stop KVM virtual machines from command line. As much as KVM provides Virtual Machine Manager (virt-manager<\/strong>), a desktop application for managing virtual machines through libvirt, it also provides a command line utility called To control state of KVM VMs, According to man pages ( The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains.<\/p>\n<\/blockquote>\n\n\n\n The basic structure of most virsh usage is:<\/p>\n\n\n\n Refer to To begin with, list the available virtual machines, either running or stopped or paused;<\/p>\n\n\n\n As you can see, I currently have three KVM virtual machines; one running and two stopped.<\/p>\n\n\n\n You can start KVM virtual machine using The basic usage syntax of the virsh start command is;<\/p>\n\n\n\n Therefore, if you want to start a virtual machine, for example, Ubuntu20.04-clone, as in my case;<\/p>\n\n\n\n You can pass other options as well, if you want.<\/p>\n\n\n\n Your virtual machine should now be running. You can list only running vms using the command below;<\/p>\n\n\n\n It is also possible to stop KVM virtual machine from command line using the For example, to shutdown a vm called, You can as well specify the vm UUID or ID instead of the name when shutting it down.<\/p>\n\n\n\n For example, when you run virsh list command to check running vms, the first column of the output shows the vm ID. To use the ID while shutting down a vm;<\/p>\n\n\n\n for example;<\/p>\n\n\n\n To use UUID while shutting down a vm, you first need to obtain the vm UUID. To get the Universally Unique Identifier (UUID) for a guest virtual machine:<\/p>\n\n\n\n For example;<\/p>\n\n\n\n Or<\/p>\n\n\n\n virsh domuuid ubuntu20.04<\/p>\n\n\n\n Similarly, you can use virsh dominfo to get other details including the UUID of the vm;<\/p>\n\n\n\n The shutdown using the UUID;<\/p>\n\n\n\n You can as well specify other power options while shutting down the vm.<\/p>\n\n\n\n That marks the end of our tutorial on how to control the states KVM virtual machines from command line.<\/p>\n\n\n\n List Running and Stopped VMS on KVM<\/a><\/p>\n\n\n\n How to Clone KVM Virtual Machines<\/a><\/p>\n\n\n\n How to fix QEMU\/KVM Not Connected Error on Ubuntu 20.04<\/a><\/p>\n\n\n\nvirsh<\/code><\/strong> which enables the terminal centric users to manage KVM virtual machines from command line interface.<\/p>\n\n\n\n
Starting and Stopping KVM VMss from Command Line<\/h2>\n\n\n\n
virsh<\/code><\/strong> utility can be used.<\/p>\n\n\n\n
man virsh<\/strong><\/code>);<\/p>\n\n\n\n
\n
virsh [OPTION]... <command> <domain> [ARG]...<\/code><\/pre>\n\n\n\n
man virsh<\/code><\/strong> for more details.<\/p>\n\n\n\n
Start KVM Virtual Machines from Command Line<\/a><\/h3>\n\n\n\n
virsh list --all<\/code><\/pre>\n\n\n\n
Id Name State\n------------------------------------\n 1 ubuntu20.04 running\n - kolla-ansible shut off\n - ubuntu20.04-clone shut off<\/code><\/pre>\n\n\n\n
virsh start<\/strong><\/code> command. The
virsh start<\/code><\/strong> command can be used to start a domain, either from the last managedsave state, or via a fresh boot if no managedsave state is present.<\/p>\n\n\n\n
virsh start --help<\/code><\/pre>\n\n\n\n
NAME\n start - start a (previously defined) inactive domain\n\n SYNOPSIS\n start <domain> [--console] [--paused] [--autodestroy] [--bypass-cache] [--force-boot] [--pass-fds <string>]\n\n DESCRIPTION\n Start a domain, either from the last managedsave\n state, or via a fresh boot if no managedsave state\n is present.\n\n OPTIONS\n [--domain] <string> name of the inactive domain\n --console attach to console after creation\n --paused leave the guest paused after creation\n --autodestroy automatically destroy the guest when virsh disconnects\n --bypass-cache avoid file system cache when loading\n --force-boot force fresh boot by discarding any managed save\n --pass-fds <string> pass file descriptors N,M,... to the guest<\/code><\/pre>\n\n\n\n
virsh start ubuntu20.04-clone<\/code><\/pre>\n\n\n\n
virsh list<\/code><\/pre>\n\n\n\n
Id Name State\n-----------------------------------\n 1 ubuntu20.04 running\n 3 ubuntu20.04-clone running<\/code><\/pre>\n\n\n\n
Stop KVM Virtual Machines from Command Line<\/a><\/h3>\n\n\n\n
virsh shutdown<\/strong><\/code> command.<\/p>\n\n\n\n
virsh shutdown --help<\/code><\/pre>\n\n\n\n
NAME\n shutdown - gracefully shutdown a domain\n\n SYNOPSIS\n shutdown <domain> [--mode <string>]\n\n DESCRIPTION\n Run shutdown in the target domain.\n\n OPTIONS\n [--domain] <string> domain name, id or uuid\n --mode <string> shutdown mode: acpi|agent|initctl|signal|paravirt<\/code><\/pre>\n\n\n\n
ubuntu20.04<\/strong><\/code>;<\/p>\n\n\n\n
virsh shutdown Ubuntu20.04<\/code><\/pre>\n\n\n\n
virsh shutdown <id><\/code><\/pre>\n\n\n\n
virsh shutdown 3<\/code><\/pre>\n\n\n\n
virsh domuuid {domain-id or domain-name}<\/em><\/code><\/pre>\n\n\n\n
virsh domuuid 4<\/code><\/pre>\n\n\n\n
b05cdf0c-8516-4f1e-a517-f52aab45cf61<\/code><\/pre>\n\n\n\n
virsh dominfo ubuntu20.04<\/code><\/pre>\n\n\n\n
Id: -\nName: ubuntu20.04\nUUID: b05cdf0c-8516-4f1e-a517-f52aab45cf61\nOS Type: hvm\nState: shut off\nCPU(s): 2\nMax memory: 2097152 KiB\nUsed memory: 2097152 KiB\nPersistent: yes\nAutostart: disable\nManaged save: no\nSecurity model: none\nSecurity DOI: 0<\/code><\/pre>\n\n\n\n
virsh shutdown b05cdf0c-8516-4f1e-a517-f52aab45cf61<\/code><\/pre>\n\n\n\n
Other Related Tutorials<\/h3>\n\n\n\n