Documentation https://ff.co.za/ en WASPA / ISPA redactions https://ff.co.za/documentation/waspa-ispa-redactions <span property="schema:name">WASPA / ISPA redactions</span> <span rel="schema:author"><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span property="schema:dateCreated" content="2023-08-22T06:42:45+00:00">Tue, 22/08/2023 - 08:42</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=252&amp;2=bookmark" token="vEfukMcmMKlyCWW25KNqIpK2J6DWWbnXdH8oOnNbaVc"></drupal-render-placeholder><drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=252&amp;2=like" token="9g6VJwtBMqpkbnYpnEI_1t5iq6VBrQxkQ7MYVWZcVwI"></drupal-render-placeholder> </div> </div> Tue, 22 Aug 2023 06:42:45 +0000 Jeff 252 at https://ff.co.za Trim Mailman archive for data deletion policy https://ff.co.za/documentation/trim-mailman-archive-data-deletion-policy <span property="schema:name">Trim Mailman archive for data deletion policy</span> <span rel="schema:author"><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span property="schema:dateCreated" content="2023-07-06T06:40:33+00:00">Thu, 06/07/2023 - 08:40</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=251&amp;2=bookmark" token="3dFo-EgE9-AaqViFT1OwYJWSIp2xaekXqOCdzOpKXD0"></drupal-render-placeholder><drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=251&amp;2=like" token="mrush45JHR3Gqod4PwC5n9np2sGCE8ADHLhuYhzn_bM"></drupal-render-placeholder> </div> </div> Thu, 06 Jul 2023 06:40:33 +0000 Jeff 251 at https://ff.co.za Resize qcow2 with blockresize on running VM https://ff.co.za/documentation/resize-qcow2-blockresize-running-vm <span>Resize qcow2 with blockresize on running VM</span> <span><span lang="" about="/user/admin" typeof="schema:Person" property="schema:name" datatype="">Admin</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 Admin 241 at https://ff.co.za ECC and certbot automated renewal https://ff.co.za/documentation/ecc-and-certbot-automated-renewal <span>ECC and certbot automated renewal</span> <span><span lang="" about="/user/admin" typeof="schema:Person" property="schema:name" datatype="">Admin</span></span> <span>Sun, 21/06/2020 - 11:34</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="ffimage field field--name-field-image field--type-image field--label-hidden field--item"> <a href="https://ff.co.za/sites/default/files/2020-06/ecc_1.png" aria-controls="colorbox" aria-label="{&quot;alt&quot;:&quot;&quot;}" role="button" title="ECC and certbot automated renewal" data-colorbox-gallery="gallery-book-220-235a6H6dxR8" class="colorbox" data-cbox-img-attrs="{&quot;alt&quot;:&quot;&quot;}"><img src="/sites/default/files/styles/medium/public/2020-06/ecc_1.png?itok=nDHxybyf" width="220" height="187" alt="" loading="lazy" typeof="foaf:Image" class="img-responsive" /> </a> </div> <div class="body-padding field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>The problem is that the certbot program cannot renew a certificate for an ECC public key.</p> <p>Instead of running certbot renew, we should roll our own. </p> <p>Take care to rename the Exim and Dovecot certificates in the appropriate place.</p> <p> </p> <p> </p> <p> </p> <p> </p> <p>This works:</p> <pre> <code>root@abispa ~/certbot-renewal $ cat renew-certbot.sh #!/bin/sh LOGFILE=/root/certbot-renewal/certbot-renewal.log ARCHIVE=/etc/letsencrypt/ecc-archive/abispa.waspa.org.za ## "Renew" the RSA certificate -- this actually generates a fresh ## 4096-bit RSA key pair and creates a certificate from the public key. echo "RSA renewal ====================================" &gt; $LOGFILE certbot --force-renewal --rsa-key-size 4096 renew &gt;&gt; $LOGFILE 2&gt;&amp;1 ## Use the Certificate-Signing Request for the existing ECC ## public key, and request a new certificate. ## You can read a CSR with: ## $ openssl req -noout -text -in /path/to/csr.pem echo "ECC renewal ====================================" &gt;&gt; $LOGFILE certbot certonly --non-interactive --apache \ -d abispa.waspa.org.za \ --email ops@ff.co.za \ --csr /etc/letsencrypt/csr/ecc-csr.pem \ --agree-tos &gt;&gt; $LOGFILE 2&gt;&amp;1 ## The above creates three files in the local directory. ## Move them into place. echo "Installing files ===============================" &gt;&gt; $LOGFILE mv -fv 0000_cert.pem $ARCHIVE/cert.pem &gt;&gt; $LOGFILE mv -fv 0000_chain.pem $ARCHIVE/chain.pem &gt;&gt; $LOGFILE mv -fv 0001_chain.pem $ARCHIVE/fullchain.pem &gt;&gt; $LOGFILE ## Fix Debian-exim group permissions. ## Remember to update dovecot &amp; exim4 cert locations! chmod 755 -R /etc/letsencrypt/{ecc-archive,ecc-live}; chgrp -R Debian-exim /etc/letsencrypt/{ecc-archive,ecc-live} chmod 755 -R /etc/letsencrypt/{rsa-archive,rsa-live}; chgrp -R Debian-exim /etc/letsencrypt/{rsa-archive,rsa-live} ## Restart mail &amp; web server so they use the new certs. echo "Apache restart =================================" &gt;&gt; $LOGFILE service apache2 stop &gt;&gt; $LOGFILE 2&gt;&amp;1 service apache2 start &gt;&gt; $LOGFILE 2&gt;&amp;1 echo "Dovecot restart =================================" &gt;&gt; $LOGFILE service dovecot stop &gt;&gt; $LOGFILE 2&gt;&amp;1 service dovecot start &gt;&gt; $LOGFILE 2&gt;&amp;1 echo "Exim4 restart =================================" &gt;&gt; $LOGFILE service apache2 stop &gt;&gt; $LOGFILE 2&gt;&amp;1 service apache2 start &gt;&gt; $LOGFILE 2&gt;&amp;1 </code></pre><p> </p> <p><img alt="" class="image-large colorbox" data-entity-type="file" data-entity-uuid="insert-large-6fa223cd-558b-4cd3-b14a-557267a82c21" data-insert-class="image-large colorbox" data-insert-type="image" src="/sites/default/files/2020-06/ecc_0.gif" /></p> </div> <div class="field field--name-field-images field--type-image field--label-hidden field--items"> <div class="field--item"> <a href="https://ff.co.za/sites/default/files/2020-06/ecc_0.gif" aria-controls="colorbox" aria-label="{&quot;alt&quot;:&quot;&quot;}" role="button" title="ECC and certbot automated renewal" data-colorbox-gallery="gallery-book-220-235a6H6dxR8" class="colorbox" data-cbox-img-attrs="{&quot;alt&quot;:&quot;&quot;}"><img src="/sites/default/files/styles/thumbnail/public/2020-06/ecc_0.gif?itok=qJikefds" width="100" height="100" alt="" loading="lazy" typeof="foaf:Image" class="img-responsive" /> </a> </div> </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/ecc" hreflang="en">ECC</a></div> <div class="field--item"><a href="/tags/lets-encrypt" hreflang="en">Lets Encrypt</a></div> <div class="field--item"><a href="/tags/certbot" hreflang="en">certbot</a></div> </div> </div> </div> </div> Sun, 21 Jun 2020 09:34:17 +0000 Admin 220 at https://ff.co.za Elliptic Curve Crypto & LetsEncrypt https://ff.co.za/documentation/elliptic-curve-crypto-letsencrypt <span property="schema:name">Elliptic Curve Crypto &amp; LetsEncrypt</span> <span rel="schema:author"><span lang="" about="/user/admin" typeof="schema:Person" property="schema:name" datatype="">Admin</span></span> <span property="schema:dateCreated" content="2020-06-21T08:53:23+00:00">Sun, 21/06/2020 - 10:53</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=219&amp;2=bookmark" token="CUwtsbk6l7KTVbz_BCrK3PCnIrW8Jr3DAEKj8IOnIbs"></drupal-render-placeholder><drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=219&amp;2=like" token="cgqfuvX6JfyKCmnRFnY74ZisRg0dF-ymIXv63IKqqSk"></drupal-render-placeholder> </div> </div> Sun, 21 Jun 2020 08:53:23 +0000 Admin 219 at https://ff.co.za Migrate a VM with Minimal Downtime https://ff.co.za/documentation/migrate-vm-minimal-downtime <span>Migrate a VM with Minimal Downtime</span> <span><span lang="" about="/user/admin" typeof="schema:Person" property="schema:name" datatype="">Admin</span></span> <span>Tue, 26/11/2019 - 10:17</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"> <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><a href="/documentation/resize-qcow2-blockresize-running-vm">Resize qcow2 with blockresize on running VM</a></li> </ul> </li> </ul> </li> </ul> </nav> <ul> <li><em><u><strong><a href="/documentation/migrate-vm-minimal-downtime">Migrate a VM with Minimal Downtime</a></strong></u></em></li> </ul> <p> </p> <p>This script takes a snaphot of the running VM, which leaves the qcow2 backing images in a known state. All VM activity is then recorded in the snapshots, while the backing images are rsync'd to a reciprocal hypervisor on the 1G VLAN.</p> <p>After the backing images are transferred, the VM is shutdown and snapshots copied to the reciprocal hypervisor. The server is defined on the new host, started, and the snapshots are merged into the backing image/s.</p> <p> Total downtime depends on the size of the snapshots, but is usually less than a minute or two. The whole process takes about an hour an a half for a ~200GB QCOW2 image over a 1GB/sec VLAN.</p> <p><span id="cke_bm_139S" style="display: none;"> </span> Example 1:</p> <pre> <code class="language-bash">jeff@sheri:/var/lib/libvirt/images/scripts$ cat skillsregistry.migrate.sh #!/bin/bash ################################################################################ ###################### Migrate VM to a new hypervisor ######################## # Authors: Jeff Brown / Lucio de Re # Date: 2019/11/26 # # This script takes a snaphot of the running VM, which leaves the qcow2 backing # images in a known state. All VM activity is then recorded in the snapshots, # while the backing images are rsync'd to a reciprocal hypervisor on the VLAN. # After the backing images are transferred, the VM is shutdown and snapshots # copied to the reciprocal hypervisor. The server is defined on the new host, # started, and the snapshots are merged into the backing image/s. # Total downtime depends on the size of the snapshots, but is usually # less than a minute or two. The whole process takes about an hour and a half. # # NB. This script must be run by a user who is a member of libvirt-qemu group. # NB. The user must also be able to run sudo aa-teardown/chown/chmod without password. # E.g. jeff ALL=NOPASSWD:/bin/chown, /bin/chmod # # 192.100.0.4 (vespa.org.za) # 192.100.0.82 (abispa.org.za) # ################################################################################ cd /var/lib/libvirt/images/ virsh snapshot-create-as --domain skillsregistry skillsregistry.snapshot --diskspec sda,file=/var/lib/libvirt/images/snapshots/skillsregistry.snapshot.qcow2 --disk-only --atomic export RSYNC_PASSWORD="real password for rsyncd secret" rsync -ShavW --progress /var/lib/libvirt/images/skillsregistry.qcow2 rsync://tergum@192.168.100.82/bvar/lib/libvirt/images/skillsregistry.qcow2 virsh shutdown skillsregistry x=0 while sleep 5; do virsh list --all | grep skillsregistry | grep "shut off" &amp;&amp; break x=$(expr $x + 1) [ $x -gt 120 ] &amp;&amp; { echo &gt;&amp;2 timed out after $(expr $x \* 5) seconds; exit 3; } done virsh autostart skillsregistry --disable virsh -c qemu:///system dumpxml skillsregistry &gt; /var/lib/libvirt/images/xml/skillsregistry.xml scp /var/lib/libvirt/images/xml/skillsregistry.xml 192.168.100.82:/var/lib/libvirt/images/xml/ sudo find . -type f -exec chown libvirt-qemu:libvirt-qemu {} \; -exec chmod g+rw {} \; rsync -ShavW --progress /var/lib/libvirt/images/snapshots/skillsregistry.snapshot.qcow2 rsync://tergum@192.168.100.82/bvar/lib/libvirt/images/snapshots/ export RSYNC_PASSWORD="nopass" virsh -c qemu+ssh://192.168.100.82/system define /var/lib/libvirt/images/xml/skillsregistry.xml virsh -c qemu+ssh://192.168.100.82/system start skillsregistry x=0 while sleep 5; do virsh -c qemu+ssh://192.168.100.82/system list --all | grep skillsregistry | grep "running" &amp;&amp; break x=$(expr $x + 1) [ $x -gt 120 ] &amp;&amp; { echo &gt;&amp;2 timed out after $(expr $x \* 5) seconds; exit 3; } done # Required for Debian 10 + to disable apparmor! : ssh 192.168.100.82 sudo aa-teardown virsh -c qemu+ssh://192.168.100.82/system blockcommit skillsregistry sda --active --pivot --shallow --verbose virsh -c qemu+ssh://192.168.100.82/system autostart skillsregistry </code></pre><p><strong><em>(Don't forget to delete the snapshots left behind in case we need to revert!)</em></strong></p> <p> </p> <p><strong>Different examples to copy sparse images:</strong></p> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">rsync --rsync-path="ionice -n 7 nice -n19 rsync" -havW --progress /var/lib/libvirt/images/UAT.qcow2 192.168.100.1:/var/lib/libvirt/images/</div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"> </div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">cd /var/lib/libvirt/images/; tar czf - DNC.qcow2 | ssh 192.168.100.1 cd /var/lib/libvirt/images/ \&amp;\&amp; tar xzvf -</div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"> </div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">rsync -SWv --show-progress rsync://tergum@192.168.100.4/bvar/lib/libvirt/images/FFDev.qcow2 /tmp/</div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"> </div> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"> <div> </div> </div> </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/qemu-kvm" hreflang="en">qemu-kvm</a></div> </div> </div> </div> </div> Tue, 26 Nov 2019 08:17:45 +0000 Admin 210 at https://ff.co.za Install QEMU-KVM on Debian 9 https://ff.co.za/documentation/install-qemu-kvm-debian-9 <span property="schema:name">Install QEMU-KVM on Debian 9</span> <span rel="schema:author"><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span property="schema:dateCreated" content="2019-02-25T07:17:07+00:00">Mon, 25/02/2019 - 09:17</span> <div class="layout layout--onecol"> <div class="layout__region layout__region--content"> <drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=151&amp;2=bookmark" token="XPK8bLm8YkE4mPq5OZrq4ElhcB8rr0clcAAWrTEPcRU"></drupal-render-placeholder><drupal-render-placeholder callback="flag.link_builder:build" arguments="0=node&amp;1=151&amp;2=like" token="QbRN8_kXQEwTO4zTEE9eJoP0Fgyb_IWTGh09e-nWwo0"></drupal-render-placeholder> </div> </div> Mon, 25 Feb 2019 07:17:07 +0000 Jeff 151 at https://ff.co.za Allow users to run virsh and manage VMs https://ff.co.za/documentation/allow-users-run-virsh-and-manage-vms <span>Allow users to run virsh and manage VMs</span> <span><span lang="" about="/user/admin" typeof="schema:Person" property="schema:name" datatype="">Admin</span></span> <span>Tue, 13/11/2018 - 06:59</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><em><u><strong><a href="/documentation/allow-users-run-virsh-and-manage-vms">Allow users to run virsh and manage VMs</a></strong></u></em></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="/documentation/managing-kvm-and-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="/documentation/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><a href="/documentation/resize-qcow2-blockresize-running-vm">Resize qcow2 with blockresize on running VM</a></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> </nav> <nav aria-label="Book outline for Elliptic Curve Crypto &amp; LetsEncrypt" role="navigation"> <p>Sources:</p> </nav> <p><a href="https://libvirt.org/aclpolkit.html">https://libvirt.org/aclpolkit.html</a><br /> <a href="https://major.io/2015/04/11/run-virsh-and-access-libvirt-as-a-regular-user/">https://major.io/2015/04/11/run-virsh-and-access-libvirt-as-a-regular-u…</a><br /> <a href="https://www.poftut.com/use-virt-manager-libvirt-normal-user-without-root-privileges-without-asking-password/">https://www.poftut.com/use-virt-manager-libvirt-normal-user-without-roo…</a></p> <p>Defining custom rules requires creation of a file in the /etc/polkit-1/rules.d directory with a name chosen by the administrator (100-libvirt-acl.rules would be a reasonable choice). See the polkit(8) manual page for a description of how to write these files in general.</p> <p>We're going to allow members of the libvirt group to manage VM's:</p> <p><code>mkdir /etc/polkit-1/rules.d</code><br /> vi /etc/polkit-1/rules.d/100-libvirt-acl.rules</p> <p><code>polkit.addRule(function(action, subject) </code><code>{<br /> if (action.id == "org.libvirt.unix.manage" &amp;&amp; subject.local &amp;&amp; subject.active &amp;&amp; subject.isInGroup("libvirt")) {<br /> return polkit.Result.YES;<br /> }<br /> });</code></p> <p><strong>NB. Add to user's .bashrc:</strong></p> <p><code>export LIBVIRT_DEFAULT_URI=qemu:///system</code></p> <p> </p> <h2>Add bash completion library:</h2> <p>Download the bash completion library: <a href="https://github.com/LuyaoHuang/virsh-bash-completion/blob/master/virsh_bash_completion">virsh_bash_completion</a></p> <p>How to use it: Copy virsh_bash_completion file to /etc/bash_completion.d/ then restart bash.</p> <p>(<a href="https://github.com/LuyaoHuang/virsh-bash-completion">Source</a>)</p> <p> </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/libvirt" hreflang="en">libvirt</a></div> <div class="field--item"><a href="/tags/virsh" hreflang="en">virsh</a></div> <div class="field--item"><a href="/tags/qemu-kvm" hreflang="en">qemu-kvm</a></div> <div class="field--item"><a href="/tags/polkit" hreflang="en">polkit</a></div> </div> </div> </div> </div> Tue, 13 Nov 2018 04:59:46 +0000 Admin 127 at https://ff.co.za Backup Virtual Machine https://ff.co.za/documentation/backup-virtual-machine <span>Backup Virtual Machine</span> <span><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span>Sun, 11/11/2018 - 10:21</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="/documentation/managing-kvm-and-qcow2-images" hreflang="en">Managing qcow2 images</a></p> <ul> <li><em><u><strong><a href="/documentation/backup-virtual-machine">Backup virtual machine</a></strong></u></em></li> <li><a href="/documentation/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><a href="/documentation/resize-qcow2-blockresize-running-vm">Resize qcow2 with blockresize on running VM</a></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> </nav> <p><strong>Sources:</strong></p> <ul> <li><a href="https://www.virtkick.com/docs/how-to-perform-a-live-backup-on-your-kvm-virtual-machines.html">www.virtkick.com/docs/how-to-perform-a-live-backup-on-your-kvm-virtual-machines.html</a></li> <li><a href="https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit">wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit</a></li> </ul> <p> </p> <h2>1. As root, locate the virtual machine you want to back up using virsh:</h2> <p><code>virsh -c qemu:///system list # shows only running</code></p> <p>or</p> <p><code>virsh list --all # shows all</code></p> <p> </p> <h2>2. Dump the configuration for your virtual machine:</h2> <p><code>virsh -c qemu:///system dumpxml MACHINE_NAME &gt; /var/lib/libvirt/images/safe/MACHINE_NAME.datestamp.xml</code></p> <p> </p> <h2>3. You may need to locate the image directory:</h2> <p><code>virsh -c qemu:///system domblklist MACHINE_NAME</code></p> <p> </p> <h2>4. Now prepare the backup of this machine using a snapshot:</h2> <p><code>virsh snapshot-create-as --domain MACHINE_NAME IMAGE_NAME.snapshot --diskspec sda,file=/var/lib/libvirt/images/safe/IMAGE_NAME.snapshot.qcow2 --disk-only --atomic</code></p> <p>Note: If you get an error, then the disk is not converted to virtio-scsi, and should be <strong>vda</strong>, not sda.</p> <p><em>After creating the snapshot, all disk operations from the guest will be directed to it so that you can copy the original disk image to a safe place.</em></p> <p>You can establish this by running, as example:</p> <pre> <code class="language-bash">virsh -c qemu:///system domblklist ispa Target Source ------------------------------------------------ hda - sda /var/lib/libvirt/images/safe/ispa.snapshot.qcow2</code></pre><p> </p> <h2>5. Copy to external server and include both the qcow2 disk image and the machine configuration (the XML file):</h2> <p>su - yourusername   # you must be in libvirt-qemu group</p> <p><code>rsync -hav --progress /var/lib/libvirt/images/IMAGE_NAME.qcow2 192.168.100.2:backups/ # IP address of prionyx on 1GB VLAN</code></p> <p> </p> <h2>6. Merge snapshot:</h2> <p>After the file transfer is completed, you should merge changes written to snapshot, back to original disk image. This operation is called 'active block commit':</p> <p><code>virsh blockcommit MACHINE_NAME sda --active --pivot --shallow --verbose</code></p> <p>Check block devices again. If the block commit completed successfuly your virtual machine should use its original image again.</p> <p><code>virsh -c qemu:///system domblklist MACHINE_NAME</code></p> <p> </p> <h2>Example Backup script for running VMs:</h2> <pre> <code class="language-bash">jeff@sheri:~$ cat /var/lib/libvirt/images/scripts/ispa.backup.sh #!/bin/bash ################################################################################ # # This script takes a snaphot of the running VM, which leaves the main qcow2 # image in a known state. All VM activity is then recorded in the snapshot, # while the main qcow2 image can be rsync'd to a remote backup server. # After the image has been transferred, the snapshot is merged back to the # main image, and then deleted. # # NB. This script must be run by a user who is a member of libvirt-qemu group. # ################################################################################ virsh -c qemu:///system dumpxml ISPA &gt; /var/lib/libvirt/images/xml/ispa.xml scp /var/lib/libvirt/images/xml/ispa.xml 192.168.100.4:/var/lib/libvirt/images/xml/ virsh snapshot-create-as --domain ISPA ISPA.snapshot --diskspec sda,file=/var/lib/libvirt/images/snapshots/ispa.snapshot.qcow2 --disk-only --atomic rsync --rsync-path="ionice -c 3 nice rsync" -havW --progress /var/lib/libvirt/images/ispa.qcow2 192.168.100.4:/var/lib/libvirt/images/sheriff/ virsh blockcommit ISPA sda --active --pivot --shallow --verbose virsh snapshot-delete ISPA --metadata ISPA.snapshot rm -rf /var/lib/libvirt/images/snapshots/ispa.snapshot.qcow2 #rm /var/lib/libvirt/images/xml/ispa.xml </code></pre><p> </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/backups" hreflang="en">backups</a></div> <div class="field--item"><a href="/tags/kvm" hreflang="en">KVM</a></div> <div class="field--item"><a href="/tags/rysnc" hreflang="en">rysnc</a></div> <div class="field--item"><a href="/tags/qemu-kvm" hreflang="en">qemu-kvm</a></div> </div> </div> </div> </div> Sun, 11 Nov 2018 08:21:51 +0000 Jeff 126 at https://ff.co.za Reclaiming space on qcow2 disk image https://ff.co.za/documentation/reclaiming-space-qcow2-disk-image <span>Reclaiming space on qcow2 disk image</span> <span><span lang="" about="/user/jeff" typeof="schema:Person" property="schema:name" datatype="">Jeff</span></span> <span>Sat, 01/09/2018 - 10:20</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><em><u><strong><a href="/documentation/reclaiming-space-qcow2-disk-image" hreflang="en">Reclaiming space on qcow2 disk image</a></strong></u></em></li> <li><a href="/documentation/resize-qcow2-blockresize-running-vm">Resize qcow2 with blockresize on running VM</a></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> </nav> </p> <p><em>Update 2018-11-11:</em></p> </p> <p>Source: <a href="https://dustymabe.com/2013/06/11/recover-space-from-vm-disk-images-by-using-discardfstrim/">dustymabe.com/2013/06/11/recover-space-from-vm-disk-images-by-using-discardfstrim/</a></p> <p>Recommended method is to use fstrim. See: <a href="https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_File">pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files</a></p> <p><em>"The recommended version is to pass TRIM commands (known from SSDs) from the VM to the backing storage. This has the advantage that it works automatically, does not need to write the whole free parts of all disks to zero and must only be setup once."</em></p> <p>The alternative manual method outlined below, is slow and painful - but seemingly necessary for the occasional apparent failure of fstrim, as experienced first-hand.</p> <h2>Convert the storage 'driver' from virtio-blck to virtio-scsi</h2> <p>Use VMM (Virtual Machine Manager) in a vncserver session on the hypervisor, over the VPN.</p> <p><strong>NB: Shut the VM down, first!</strong></p> <p>Remove the current virtio-blk disk image:</p> <p><img alt="" class="image-large colorbox" data-entity-type="file" data-entity-uuid="insert-large-9d1d45b4-2a30-4bd1-90b1-f57272129769" data-insert-class="image-large colorbox" data-insert-type="image" height="357" src="/sites/default/files/styles/large/public/2018-11/Screenshot%202018-11-11%20at%2012.36.42.png" width="480" /></p> <p>And add it back as virtio-scsi:</p> <p><img alt="" class="image-large colorbox" data-entity-type="file" data-entity-uuid="insert-large-b6cc7325-beac-4b6f-993f-2514f1fe91d1" data-insert-class="image-large colorbox" data-insert-type="image" height="357" src="/sites/default/files/styles/large/public/2018-11/Screenshot%202018-11-11%20at%2012.41.15.png" width="480" /></p> <p> </p> <h2>Then, to enable TRIM in the guest, first edit the VM's XML configuration file on the hypervisor:</h2> <p><code>virsh edit MACHINE_NAME</code></p> <p>And add <strong>discard='unmap' </strong>to the driver.</p> <pre> <code class="language-bash"> &lt;devices&gt; &lt;emulator&gt;/usr/bin/kvm&lt;/emulator&gt; &lt;disk type='file' device='disk'&gt; &lt;driver name='qemu' type='qcow2' discard='unmap'/&gt; &lt;source file='/var/lib/libvirt/images/new-ff.qcow2'/&gt; &lt;target dev='sda' bus='scsi'/&gt; &lt;address type='drive' controller='0' bus='0' target='0' unit='0'/&gt; &lt;/disk&gt;</code></pre><p> </p> <h2>Start the VM and TRIM</h2> <p><code>virsh start new-ff</code></p> <p>Then, SSH to the VM, and as root, run the following command:</p> <p>fstrim -v /</p> <p>Add to root's crontab to perform a trim weekly.</p> <p><code>crontab -e</code></p> <pre> <code class="language-bash"># Trim filesystem daily to recover space 0 2 * * 1 /sbin/fstrim -v / &gt;&gt; /home/jeff/fstrim.log</code></pre><hr /> <h1><strong>Alternative method:</strong></h1> <p>Shutdown and backup the VM's qcow2 disk image.</p> <p>Mount the qcow2 image using <a href="/documentation/how-mount-qcow2-image-qemu-nbd">this guide</a>.</p> <ol> <li>Zero-fill the drive (<code>dd if=/dev/zero of=/some/file</code> until you run out of space)</li> <li>delete /some/file</li> <li> </li> </ol> <p><code>qemu-img convert -O qcow2 original_image.qcow2 deduplicated_image.qcow2</code></p> <p>Or...</p> <p>In a terminal on the VM, run the dd if=zero commands until you run out of disk space. Before running this, be sure to stop any applications running on the guest otherwise errors may result.</p> <p style="margin: 0px 0px 0.5em; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 15px; vertical-align: baseline; box-sizing: inherit; word-wrap: break-word;"> </p> </div> <div class="field field--name-field-images field--type-image field--label-hidden field--items"> <div class="field--item"> <a href="https://ff.co.za/sites/default/files/2018-11/Screenshot%202018-11-11%20at%2012.36.42.png" aria-controls="colorbox" aria-label="{&quot;alt&quot;:&quot;&quot;}" role="button" title="Reclaiming space on qcow2 disk image" data-colorbox-gallery="gallery-book-78-235a6H6dxR8" class="colorbox" data-cbox-img-attrs="{&quot;alt&quot;:&quot;&quot;}"><img src="/sites/default/files/styles/thumbnail/public/2018-11/Screenshot%202018-11-11%20at%2012.36.42.png?itok=chc6MmN0" width="100" height="74" alt="" loading="lazy" typeof="foaf:Image" class="img-responsive" /> </a> </div> <div class="field--item"> <a href="https://ff.co.za/sites/default/files/2018-11/Screenshot%202018-11-11%20at%2012.41.15.png" aria-controls="colorbox" aria-label="{&quot;alt&quot;:&quot;&quot;}" role="button" title="Reclaiming space on qcow2 disk image" data-colorbox-gallery="gallery-book-78-235a6H6dxR8" class="colorbox" data-cbox-img-attrs="{&quot;alt&quot;:&quot;&quot;}"><img src="/sites/default/files/styles/thumbnail/public/2018-11/Screenshot%202018-11-11%20at%2012.41.15.png?itok=5dbLTRX6" width="100" height="74" alt="" loading="lazy" typeof="foaf:Image" class="img-responsive" /> </a> </div> </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/qemu-nbd" hreflang="en">qemu-nbd</a></div> <div class="field--item"><a href="/tags/qcow2" hreflang="en">qcow2</a></div> <div class="field--item"><a href="/tags/dd" hreflang="en">dd</a></div> <div class="field--item"><a href="/tags/fstrim" hreflang="en">fstrim</a></div> </div> </div> </div> </div> Sat, 01 Sep 2018 08:20:52 +0000 Jeff 78 at https://ff.co.za