{"id":570,"date":"2018-09-02T22:41:22","date_gmt":"2018-09-02T19:41:22","guid":{"rendered":"http:\/\/kifarunix.com\/?p=570"},"modified":"2024-03-11T19:48:36","modified_gmt":"2024-03-11T16:48:36","slug":"how-to-rename-kvm-virtual-machine-with-virsh-command","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-rename-kvm-virtual-machine-with-virsh-command\/","title":{"rendered":"How to Rename KVM Virtual Machine with virsh command"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1061\" height=\"590\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/rename-kvm-virtual-machine.png\" alt=\"How to Rename KVM Virtual Machine with virsh command\" class=\"wp-image-16592\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/rename-kvm-virtual-machine.png?v=1684008090 1061w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/rename-kvm-virtual-machine-768x427.png?v=1684008090 768w\" sizes=\"(max-width: 1061px) 100vw, 1061px\" \/><\/figure>\n\n\n\n<p>Is it possible to rename KVM virtual machine? Yes, follow through this guide to learn how to rename KVM virtual machine with virsh command. <a href=\"https:\/\/linux.die.net\/man\/1\/virsh\" target=\"_blank\" rel=\"noreferrer noopener\">virsh<\/a> program is the main interface for managing virsh guest domains. The program can be used to create, pause, update and shutdown domains. It can also be used to list current domains.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#renaming-kvm-virtual-machine-with-virsh-command\">Renaming KVM Virtual Machine with virsh command<\/a><ul><li><a href=\"#get-the-name-of-the-virtual-machine\">Get the Name of the Virtual Machine<\/a><\/li><li><a href=\"#shut-down-the-virtual-machine\">Shut down the Virtual Machine<\/a><\/li><li><a href=\"#generate-vm-xml-file\">Generate VM XML File<\/a><\/li><li><a href=\"#rename-the-kvm-virtual-machine\">Rename the KVM Virtual Machine<\/a><\/li><li><a href=\"#undefine-the-virtual-machine\">Undefine the Virtual Machine<\/a><\/li><li><a href=\"#recreate-the-virtual-machine-from-the-xml-file\">Recreate the Virtual Machine from the XML file<\/a><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"renaming-kvm-virtual-machine-with-virsh-command\">Renaming KVM Virtual Machine with virsh command<\/h2>\n\n\n\n<p>So, have you created KVM Virtual Machines on your system and feel like the names assigned to them are not up to your taste? Worry not for this is how to simply rename that virtual machine.<\/p>\n\n\n\n<p>Take for example, as in my case, your virtual machine is assigned a name like <strong>generic<\/strong> and you want to rename it to at least reflect the OS type name like <strong>cent-server<\/strong>. Well, lets have a look at how to.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"get-the-name-of-the-virtual-machine\">Get the Name of the Virtual Machine<\/h3>\n\n\n\n<p>You can get the name of the virtual machine either from the Virt-manager or from command line using the virsh command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>virsh list --all<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n Id   Name             State\n---------------------------------\n -    mon01            shut off\n -    vm01             shut off\n -    generic          shut off\n -    stack            shut off\n -    win10            shut off\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"shut-down-the-virtual-machine\">Shut down the Virtual Machine<\/h3>\n\n\n\n<p>Shutdown the Virtual Machine to be renamed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo virsh shutdown generic<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"generate-vm-xml-file\">Generate VM XML File<\/h3>\n\n\n\n<p>Generate the xml configuration file of the VM to some file, say <em>generic.xml<\/em> in the current directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo virsh dumpxml generic &gt; cent-server.xml<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rename-the-kvm-virtual-machine\">Rename the KVM Virtual Machine<\/h3>\n\n\n\n<p>Edit the generated xml file to rename the domain name between the <strong>name tags<\/strong>;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim cent-server.xml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;name&gt;generic&lt;\/name&gt;<\/code><\/pre>\n\n\n\n<p>to your new VM name;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;name&gt;cent-server&lt;\/name&gt;<\/code><\/pre>\n\n\n\n<p>and the disk file in <strong>device section<\/strong> under <strong><code>source file=\/var\/lib\/libvirt\/images\/generic.qcow2<\/code><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;source file=\/var\/lib\/libvirt\/images\/cent-server.qcow2&gt;<\/code><\/pre>\n\n\n\n<p>After making the changes, save the file and exit the xm file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"undefine-the-virtual-machine\">Undefine the Virtual Machine<\/h3>\n\n\n\n<p>Delete all the existing configurations of the Virtual Machine;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo virsh undefine generic<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"recreate-the-virtual-machine-from-the-xml-file\">Recreate the Virtual Machine from the XML file<\/h3>\n\n\n\n<p>Create a <strong>new xml<\/strong> file for the Virtual Machine using the edited xml file. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo virsh define cent-server.xml<\/code><\/pre>\n\n\n\n<p>Finally, list all the Virtual Machines to confirm the changes. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo virsh list --all<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n Id   Name             State\n---------------------------------\n -    mon01            shut off\n -    vm01             shut off\n -    cent-server      shut off\n -    stack            shut off\n -    win10            shut off\n<\/code><\/pre>\n\n\n\n<p>And that that is all about renaming KVM virtual machine through a command line with virsh command.<\/p>\n\n\n\n<p>That concludes our guide on renaming KVM virtual machine with virsh command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h2>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-kvm-on-oracle-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install KVM on Oracle Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/change-windows-boot-device-from-ide-to-virtio-on-kvm\/\" target=\"_blank\" rel=\"noreferrer noopener\">Change Windows Boot Device from IDE to Virtio on KVM<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is it possible to rename KVM virtual machine? Yes, follow through this guide to learn how to rename KVM virtual machine with virsh command. virsh<\/p>\n","protected":false},"author":1,"featured_media":16590,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[36,121,112],"tags":[113,6667,114,6668,6669,6670],"class_list":["post-570","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-virtualization","category-howtos","category-kvm","tag-kvm","tag-rename-kvm-vm-using-virsh-command","tag-virsh-command","tag-virsh-command-rename-vm","tag-virsh-define","tag-virsh-undefine","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/570"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=570"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":21003,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/570\/revisions\/21003"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16590"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}