Shrink guest on hosted platform: Difference between revisions

 
(One intermediate revision by the same user not shown)
Line 95: Line 95:


These days there's an alternative way for zero-ing out the parts of the disk that are not used using [https://www.man7.org/linux/man-pages/man8/fstrim.8.html fstrim].
These days there's an alternative way for zero-ing out the parts of the disk that are not used using [https://www.man7.org/linux/man-pages/man8/fstrim.8.html fstrim].
eg:
# fstrim -a -v
/var: 274.3 MiB (287592448 bytes) trimmed on /dev/sda3
/tmp: 63 MiB (66060288 bytes) trimmed on /dev/sda5
/home: 125 MiB (131072000 bytes) trimmed on /dev/sda6
/boot/efi: 505.2 MiB (529735680 bytes) trimmed on /dev/sda1
/: 5 MiB (5242880 bytes) trimmed on /dev/sda2


The great thing about this is that it only zero's out the parts of the disk that are not zero and as such the disk does not inflate to its full size.
The great thing about this is that it only zero's out the parts of the disk that are not zero and as such the disk does not inflate to its full size.
Line 101: Line 109:


* [https://github.com/vmware/open-vm-tools/issues/457 Avoid disk expansion while shrinking (github issue tracker)]
* [https://github.com/vmware/open-vm-tools/issues/457 Avoid disk expansion while shrinking (github issue tracker)]
On most modern systems fstrim is being run automatically using systemctl. You can check if it is enabled:
# systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
      Loaded: loaded (/lib/systemd/system/fstrim.timer; disabled; vendor preset: enabled)
      Active: inactive (dead)
    Trigger: n/a
    Triggers: ● fstrim.service
        Docs: man:fstrim
Oh-huh, our system does not have it enabled.. might there be a reason, such as that the UNMAP command is not supported?
If so, the following command would return 0.
# cat /sys/block/sda/queue/discard_max_bytes
1073741824
So UNMAP is supported, but fstrim still is not enabled, lets fix that.
# systemctl enable fstrim.timer
Created symlink /etc/systemd/system/timers.target.wants/fstrim.timer → /lib/systemd/system/fstrim.timer.
and reload systemctl plus check that it now works...
# systemctl start fstrim.timer
# systemctl daemon-reload
# systemctl status fstrim.timer
● fstrim.timer - Discard unused blocks once a week
      Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
      Active: active (waiting) since Sat 2024-01-06 13:00:46 CET; 6s ago
    Trigger: Mon 2024-01-08 01:17:59 CET; 1 day 12h left
    Triggers: ● fstrim.service
        Docs: man:fstrim
see also:
* https://www.suse.com/support/kb/doc/?id=000019447


== Zero out unused space on a Windows VM ==
== Zero out unused space on a Windows VM ==
1,274

edits