resize2fs https://forum.ff.co.za/ en Resize qcow2 with blockresize on running VM https://forum.ff.co.za/documentation/resize-qcow2-blockresize-running-vm <span>Resize qcow2 with blockresize on running VM</span> <span><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span>Wed, 09/03/2022 - 05:46</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="body-padding field field--name-body field--type-text-with-summary field--label-hidden field--item"><nav aria-label="Book outline for Install QEMU-KVM on Debian 9" role="navigation"> <nav aria-label="Book outline for Install QEMU-KVM on Debian 9" role="navigation"> <p><strong>Table of Contents</strong></p> <ul> <li><a href="/documentation/install-qemu-kvm-debian-9">Install QEMU-KVM on Debian 9</a></p> <ul> <li><a href="/documentation/allow-users-run-virsh-and-manage-vms">Allow users to run virsh and manage VMs</a></li> <li><a href="/documentation/kvm-bridged-networking">KVM Bridged Networking</a></li> <li><a href="/documentation/kvm-virsh-console-access-debian-and-freebsd-vms">KVM Virsh Console Access for Debian and FreeBSD VMs</a></li> </ul> </li> </ul> </nav> <nav aria-label="Book outline for Elliptic Curve Crypto &amp; LetsEncrypt" role="navigation"> <ul></ul> </nav> <nav aria-label="Book outline for Managing qcow2 images" role="navigation"> <ul> <li> <ul> <li><a href="https://forum.ff.co.za/documentation/managing-qcow2-images" hreflang="en">Managing qcow2 images</a></p> <ul> <li><a href="/documentation/backup-virtual-machine">Backup virtual machine</a></li> <li><a href="/copy-sparse-file-across-network-using-dd-or-rsync" hreflang="en">Copy sparse file across network using dd or rsync</a></li> <li><a href="/documentation/how-mount-qcow2-image-qemu-nbd" hreflang="en">How to mount a qcow2 image with qemu-nbd</a></li> <li><a href="/documentation/reclaiming-space-qcow2-disk-image" hreflang="en">Reclaiming space on qcow2 disk image</a></li> <li><u><em><strong><a href="/documentation/resize-qcow2-blockresize-running-vm">Resize qcow2 with blockresize on running VM</a></strong></em></u></li> </ul> </li> </ul> </li> </ul> </nav> <ul> <li><a href="/documentation/migrate-vm-minimal-downtime">Migrate a VM with Minimal Downtime</a></li> </ul> <p> </p> <p>I was pretty apprehensive about the potential downtime with resizing a disk image with virsh img-resize, and searched all over for, specifically, what I had in mind, which was to resize the backing image while 'quiescent' and the server's data being stored to the snapshot image.</p> </nav> <p>So I sent an email to <a href="mailto:libvirt-users@redhat.com">libvirt-users@redhat.com</a> (there are some amazing wizards there!) and got an almost immediate response from Peter:</p> <p>You can resize a QCOW2 (or any VM disk image) with virsh blockresize VM /path/to/image.qcow2 SIZE'.</p> <p><strong>This <em>requires</em> the VM to be running.</strong></p> <p><code>virsh blockresize ISPA /var/lib/libvirt/images/ispa.qcow2 300G</code></p> <p><strong>Result:</strong><br /><code>jeff@ispa-mx ~ $ sudo fdisk -l<br /> [sudo] password for jeff:  <br /> Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors</code><br />  </p> <p>Next, Install gdisk and cloud utils package for growpart, a Linux command line tool used to extend a partition in a partition table to fill available space.</p> <p><code>apt install cloud-utils gdisk</code></p> <p>Problem is that often/usually, in our case, the swap partition sits at the end of the disk, so it needs to be removed and added back after growing the primary data partition sda1.</p> <pre> <code>root@ispa-mx:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 300G 0 disk ├─sda1 8:1 0 212.2G 0 part / └─sda2 8:2 0 7.8G 0 part [SWAP]</code></pre><p> Turn swap OFF.</p> <p>swapoff -a</p> <p><strong>EDIT /etc/fstab and comment it OUT as a reboot may be required and it would hang the system because after recreating the partition the UUID will have changed!</strong></p> <p>Overview to end: Run fdisk, delete the swap, then recreate the swap partition at the end of the disk where it belongs. Write fdisk changes and run partprobe to get the kernel reinitialised with the change. </p> <p><strong>Then:</strong></p> <p><code>growpart /dev/sda 1 #Note the space</code></p> <p><code>resize2fs /dev/sda1</code></p> <p><strong>Then fix the swap partition:</strong></p> <pre> <code>mkswap /dev/sda2 Setting up swapspace version 1, size = 7.8 GiB (8389423104 bytes) no label, UUID=5a00a73e-a01c-4900-8a63-ae76c42fa61f </code></pre><p><strong>Turn swap back on:</strong></p> <p><code>swapon -a</code></p> <p>Note the new UUID. Edit /etc/fstab and update the swap UUID.</p> <p>Fin.</p> </div> <div class="field field--name-field-category field--type-entity-reference field--label-above"> <div class="field--label">Category</div> <div class="field--item"><a href="/documentation" hreflang="en">Documentation</a></div> </div> <div class="fftags field field--name-field-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tags/kvm" hreflang="en">KVM</a></div> <div class="field--item"><a href="/tags/qemu-kvm" hreflang="en">qemu-kvm</a></div> <div class="field--item"><a href="/tags/swap" hreflang="en">swap</a></div> <div class="field--item"><a href="/tags/fdisk" hreflang="en">fdisk</a></div> <div class="field--item"><a href="/tags/partprobe" hreflang="en">partprobe</a></div> <div class="field--item"><a href="/tags/growpart" hreflang="en">growpart</a></div> <div class="field--item"><a href="/tags/resize2fs" hreflang="en">resize2fs</a></div> </div> </div> </div> </div> Wed, 09 Mar 2022 03:46:15 +0000 Jeff 241 at https://forum.ff.co.za