{"id":1948,"date":"2018-10-29T22:25:26","date_gmt":"2018-10-29T22:25:26","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1948"},"modified":"2018-10-31T10:04:27","modified_gmt":"2018-10-31T10:04:27","slug":"virsh-kvm-commands-for-management","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/29\/virsh-kvm-commands-for-management\/","title":{"rendered":"Virsh KVM Commands For Management"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxadmin.io\/wp-content\/uploads\/2017\/04\/kvm-virsh-commands.png\" alt=\"Virsh Commands for KVM\" width=\"667\" height=\"147\" \/><\/p>\n<p>Virsh is a command line executable to control existing virtual machines. It includes a number of commands to help manage <a href=\"https:\/\/www.linux-kvm.org\/page\/Main_Page\">KVM(kernel-based virtual machine)<\/a> instances. It allows for easy command line management often remotely of virtual machines through SSH access.<\/p>\n<p>To enter the command shell over ssh just type the following:<\/p>\n<p>virsh<\/p>\n<p>From there you can type the help command to view all of the possible commands. We will cover some of the more common commands for managing virtual machines. Virsh commands can also be executed directly from the command line as opposed to starting the virsh enviroment by prefixing each command with virsh.<\/p>\n<h3>View all of the virtual machines on this system<\/h3>\n<p># virsh list &#8211;all<\/p>\n<p>and you will see a similar output:<\/p>\n<p>Id Name State<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n5 centos7-1 running<br \/>\n84 centos7-2 running<br \/>\n85 centos7-3 running<\/p>\n<h3>Start a virtual machine<\/h3>\n<p># virsh start server-name<\/p>\n<p>Replace server-name with the virtual machine you are attempting to start<\/p>\n<h3>Stopping a virtual machine<\/h3>\n<p>Shutdown a virtual machine:<\/p>\n<p># virsh shutdown server-name<\/p>\n<p>This will attempt to gracefully stop a virtual machine and power it off.<\/p>\n<p>Power off a virtual machine<\/p>\n<p># virsh destroy server-name<\/p>\n<p>This will immediately power off a virtual machine. This is the equivalent to removing the power cord on a running physical server.<\/p>\n<p>Reboot a virtual machine<\/p>\n<p># virsh reboot server-name<\/p>\n<h3>Auto start configuration for virtual machines<\/h3>\n<p>To have a virtual machine start every time a server reboots type the following:<\/p>\n<p># virsh autostart server-name<\/p>\n<p>To prevent a virtual machine from starting every time a server reboots type the following<\/p>\n<p># virsh autostart &#8211;disable server-name<\/p>\n<p>Attach a console to a virtual machine<\/p>\n<p>To view the console output of a virtual machine type the following<\/p>\n<p># virsh console server-name<\/p>\n<p>There are many more things virsh can do, this is just the basics to get you through power management of a virtual machine on the command line. If you have not already, please check out multi-part series on setting up KVM:<\/p>\n<p>Part 1: <a href=\"https:\/\/linuxadmin.io\/install-configure-kvm-on-centos\/\">KVM Installation On CentOS<\/a><br \/>\nPart 2: <a href=\"https:\/\/linuxadmin.io\/bridged-networking-kvm-virtualization\/\">Bridged Networking Setup For KVM Virtualization<\/a><br \/>\nPart 3: <a href=\"https:\/\/linuxadmin.io\/create-virtual-machine-kvm\/\">Creating A New Virtual Machine With KVM<\/a><\/p>\n<p>May 1, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/virsh-kvm-commands\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Virsh is a command line executable to control existing virtual machines. It includes a number of commands to help manage KVM(kernel-based virtual machine) instances. It allows for easy command line management often remotely of virtual machines through SSH access. To enter the command shell over ssh just type the following: virsh From there you can &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/29\/virsh-kvm-commands-for-management\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Virsh KVM Commands For Management&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1948","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1948"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1948\/revisions"}],"predecessor-version":[{"id":2176,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1948\/revisions\/2176"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}