{"id":3155,"date":"2021-01-10T15:41:50","date_gmt":"2021-01-10T14:41:50","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=3155"},"modified":"2021-01-10T15:51:27","modified_gmt":"2021-01-10T14:51:27","slug":"live-resizing-kvm-vm-disk-backed-by-qcow2-file","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2021\/01\/live-resizing-kvm-vm-disk-backed-by-qcow2-file\/","title":{"rendered":"live-resizing KVM VM disk backed by qcow2 file"},"content":{"rendered":"<p>let&#8217;s say you have KVM VM with Linux and you&#8217;d like to resize its qcow2-backed disk without shutting down VM.<br \/>\n<!--more--><br \/>\nVM in this example is called mlt0. first &#8211; on the KVM server level I&#8217;ll find out the location and current size of the qcow2 file:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@gkvm0:\/mnt\/big\/kvm\/mlt0# virsh\r\nWelcome to virsh, the virtualization interactive terminal.\r\n\r\nType:  'help' for help with commands\r\n       'quit' to quit\r\n\r\nvirsh # domblklist mlt0\r\n Target   Source\r\n---------------------------------------\r\n vda      \/mnt\/big\/kvm\/mlt0\/vda.qcow2\r\n hda      -\r\n\r\nvirsh # domblkinfo mlt0 \/mnt\/big\/kvm\/mlt0\/vda.qcow2\r\nCapacity:       34359738368\r\nAllocation:     22932295680\r\nPhysical:       34365243392\r\n<\/pre>\n<p>then i&#8217;ll increase size of it [ be careful, take backup in advance ]:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@gkvm0:\/mnt\/big\/kvm\/mlt0# virsh\r\nWelcome to virsh, the virtualization interactive terminal.\r\n\r\nType:  'help' for help with commands\r\n       'quit' to quit\r\n\r\nvirsh # blockresize mlt0 \/mnt\/big\/kvm\/mlt0\/vda.qcow2 64G\r\nBlock device '\/mnt\/big\/kvm\/mlt0\/vda.qcow2' is resized\r\nvirsh # domblkinfo mlt0 \/mnt\/big\/kvm\/mlt0\/vda.qcow2\r\nCapacity:       68719476736\r\nAllocation:     22932299776\r\nPhysical:       34365244416\r\n<\/pre>\n<p>given new-enough kernel the VM should already &#8216;notice&#8217; increased disk size, if not &#8211; partprobe should help:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@mlt0:\/# dmesg\r\n&#x5B;5988323.071764] virtio_blk virtio1: &#x5B;vda] new size: 134217728 512-byte logical blocks (68.7 GB\/64.0 GiB)\r\n<\/pre>\n<p>now we just need to increase partition and file system:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@mlt0:\/# apt-get install cloud-guest-utils\r\nroot@mlt0:\/# echo 1 &gt; \/sys\/class\/block\/vda\/device\/rescan \r\nroot@mlt0:\/# growpart \/dev\/vda 1 # grow the 1st partition to use all of available disk space\r\nroot@mlt0:\/# resize2fs \/dev\/vda1\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>let&#8217;s say you have KVM VM with Linux and you&#8217;d like to resize its qcow2-backed disk without shutting down VM.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-3155","post","type-post","status-publish","format-standard","hentry","category-unimportant"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=3155"}],"version-history":[{"count":4,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3155\/revisions"}],"predecessor-version":[{"id":3159,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3155\/revisions\/3159"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=3155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=3155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=3155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}