]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Feat: TRIM support using image_discards option
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 8 Jan 2022 19:18:57 +0000 (16:18 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 8 Jan 2022 19:18:57 +0000 (16:18 -0300)
kvmx
kvmxfile
share/provision/debian/basic

diff --git a/kvmx b/kvmx
index a486271c866b57b7abfcd0dd5cfed32cbbbc62b8..42252dd6f63c636ffe13e1f4a6404985b5e7df13 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -547,6 +547,11 @@ function kvmx_up {
     image_opts="-cdrom $image"
   else
     image_opts="-drive file=$image,if=$drive_interface"
+
+    # TRIM support
+    if [ "$image_discards" != "n" ]; then
+      image_opts="$image_opts,discard=unmap"
+    fi
   fi
 
   if [ ! -z "$virtio_rng" ]; then
index 48bc9ccb4a03dadaa1bb69e532bf86e18cd36623..308a59d57c33d40f0d307d92e0cd5bab47614148 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -149,6 +149,11 @@ xrandr="0"
 # Image type: file or device (kvmx-create only)
 image_type="file"
 
+# Discards support
+# See https://jschumacher.info/2020/11/debian-qemu-libvirt-qcow2-and-fstrim/
+#     https://chrisirwin.ca/posts/discard-with-kvm-2020/
+image_discards="y"
+
 # Image size
 size="10G"
 
index f3a282c0f6657c09135e16a48891afcceaa80cd3..1ef8e1352de2d5a398cd2edafb5763744be1ea20 100755 (executable)
@@ -75,5 +75,8 @@ fi
 
 # Fstrim
 # See https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files
+# See also image_discards kvmxfile option
+sudo systemctl enable fstrim.timer
+sudo systemctl start  fstrim.timer
 sudo fstrim -av
 sudo sync