<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.malinux.no/index.php?action=history&amp;feed=atom&amp;title=Libvirt_TRIM%2FUNMAP</id>
	<title>Libvirt TRIM/UNMAP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.malinux.no/index.php?action=history&amp;feed=atom&amp;title=Libvirt_TRIM%2FUNMAP"/>
	<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;action=history"/>
	<updated>2026-06-07T02:40:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=47&amp;oldid=prev</id>
		<title>Roy at 00:42, 6 December 2017</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=47&amp;oldid=prev"/>
		<updated>2017-12-06T00:42:57Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:42, 6 December 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First of all, your disk images need to be in QCOW2 format. If they are raw, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[&lt;/del&gt;[https://unixblogger.com/2016/06/13/convert-img-raw-to-qcow2/ convert&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]&lt;/del&gt;] them first. To allow for deallocation of unused space, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First of all, your disk images need to be in QCOW2 format. If they are raw, [https://unixblogger.com/2016/06/13/convert-img-raw-to-qcow2/ convert] them first. To allow for deallocation of unused space, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key malinwiki:diff::1.12:old-46:rev-47 --&gt;
&lt;/table&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=46&amp;oldid=prev</id>
		<title>Roy at 00:42, 6 December 2017</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=46&amp;oldid=prev"/>
		<updated>2017-12-06T00:42:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:42, 6 December 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First of all, your disk images need to be in QCOW2 format. If they are raw, [[https://unixblogger.com/2016/06/13/convert-img-raw-to-qcow2/ convert] them first. To allow for deallocation of unused space, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First of all, your disk images need to be in QCOW2 format. If they are raw, [[https://unixblogger.com/2016/06/13/convert-img-raw-to-qcow2/ convert&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]&lt;/ins&gt;] them first. To allow for deallocation of unused space, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key malinwiki:diff::1.12:old-45:rev-46 --&gt;
&lt;/table&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=45&amp;oldid=prev</id>
		<title>Roy at 00:42, 6 December 2017</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=45&amp;oldid=prev"/>
		<updated>2017-12-06T00:42:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:42, 6 December 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;do this&lt;/del&gt;, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;First of all, your disk images need to be in QCOW2 format. If they are raw, [[https://unixblogger.com/2016/06/13/convert-img-raw-to-qcow2/ convert] them first. &lt;/ins&gt;To &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;allow for deallocation of unused space&lt;/ins&gt;, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key malinwiki:diff::1.12:old-44:rev-45 --&gt;
&lt;/table&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=44&amp;oldid=prev</id>
		<title>Roy at 00:32, 6 December 2017</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=44&amp;oldid=prev"/>
		<updated>2017-12-06T00:32:57Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:32, 6 December 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To do this, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039; to &amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To do this, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;VirtIO&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;VirtIO&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039; to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;VirtIO SCSI&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Shut down the VM&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l26&quot;&gt;Line 26:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 26:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Start the vm with &amp;#039;&amp;#039;virsh start &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;mym&lt;/del&gt;&amp;#039;&amp;#039; or with virt-manager and wait for it to start. When done, try &amp;#039;&amp;#039;du -sh /var/lib/libvirt/images/myvm.qcow2&amp;#039;&amp;#039; and run &amp;#039;&amp;#039;fstrim /&amp;#039;&amp;#039; inside the VM and check &amp;#039;&amp;#039;du&amp;#039;&amp;#039; again. If there are a lot of wasted space, it should be freed by now.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Start the vm with &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;virsh start &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;myvm&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039; or with virt-manager and wait for it to start. When done, try &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;du -sh /var/lib/libvirt/images/myvm.qcow2&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039; and run &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;fstrim /&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039; inside the VM and check &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the &amp;#039;&lt;/ins&gt;&amp;#039;&amp;#039;du&amp;#039;&amp;#039;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;#039; output &lt;/ins&gt;again. If there are a lot of wasted space, it should be freed by now.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[mailto:roy@karlsbakk.net roy]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[mailto:roy@karlsbakk.net roy]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key malinwiki:diff::1.12:old-43:rev-44 --&gt;
&lt;/table&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=43&amp;oldid=prev</id>
		<title>Roy: Some info about UNMAP/TRIM on KVM/Libvirt</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Libvirt_TRIM/UNMAP&amp;diff=43&amp;oldid=prev"/>
		<updated>2017-12-06T00:31:48Z</updated>

		<summary type="html">&lt;p&gt;Some info about UNMAP/TRIM on KVM/Libvirt&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;KVM/Libvirt supports UNMAP, similar to TRIM. That way you can free space used by a VM on a qemu2 vdisk not currently in use. &lt;br /&gt;
&lt;br /&gt;
To do this, you&amp;#039;ll need to use UNMAP, similar to TRIM, except that the latter is the ATA counterpart to SCSI&amp;#039;s UNMAP. KVM/Libvirt doesn&amp;#039;t support the ATA version, so we&amp;#039;ll change the driver to SCSI. Usually drives are added as &amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039;. If they are, change this, using virt-manager. Obviously, you can do this on the commandline, but I&amp;#039;m lazy so I just use the GUI. On my box (Debian Jessie), I can&amp;#039;t change &amp;#039;&amp;#039;VirtIO&amp;#039;&amp;#039; to &amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;, so I&amp;#039;ll have to remove and re-add the drives. If your version of KVM/Libvirt support changing this, skip steps 2 and 3 and just change it. Otherwise, do as follows&lt;br /&gt;
&lt;br /&gt;
# Shut down the VM&lt;br /&gt;
# Start virt-manager and remove the disk(s) from the VM&lt;br /&gt;
# Add them in the same order, but as &amp;#039;&amp;#039;VirtIO SCSI&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Now, you need to add a flag to the driver to make it support UNMAP. Changing the XML config file itself may not work too well, so in my experience, I find it easier to just dump the config, change it, undefine (that is, delete, not touching the data) the old VM and recreating one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
virsh dumpxml myvm &amp;gt; myvm.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then change myvm.xml, adding the discard part&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;driver name=&amp;#039;qemu&amp;#039; type=&amp;#039;qcow2&amp;#039; discard=&amp;#039;unmap&amp;#039;/&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Undefine and redefine the VM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
virsh undefine myvm&lt;br /&gt;
virsh define myvm.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the vm with &amp;#039;&amp;#039;virsh start mym&amp;#039;&amp;#039; or with virt-manager and wait for it to start. When done, try &amp;#039;&amp;#039;du -sh /var/lib/libvirt/images/myvm.qcow2&amp;#039;&amp;#039; and run &amp;#039;&amp;#039;fstrim /&amp;#039;&amp;#039; inside the VM and check &amp;#039;&amp;#039;du&amp;#039;&amp;#039; again. If there are a lot of wasted space, it should be freed by now.&lt;br /&gt;
&lt;br /&gt;
[mailto:roy@karlsbakk.net roy]&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
</feed>