Disk Cleanup in Appliance Upgrade Process

The implementation of this feature seeks to address the excessive memory usage of the appliance disk. There are two factors that contribute to this:

  • Old docker images that are no longer used, but remain in storage
  • Remaining unused blocks on a mounted filesystem

To prevent this unnecessary memory usage, the cleanup of old docker images is executed each Login Enterprise update right before the user is prompted to confirm proceeding with the Debian update.

TrimDisk.png

The second issue listed above, unused blocks on the mounted filesystem, can be solved by using the fstrim command. This will trim the disk and discard any blocks that are no longer in use by a mounted file system.

Note: The device underlying the file system must support the physical discard operations. To check if they do, the value in /sys/block/{device_name}/queue/discard_max_bytes file must not be zero. The script used for this implementation will perform this check before executing any trim.

It is worth noting that executing fstrim too frequently might negatively impact the lifetime of lower-quality SSD devices. For most desktop and server systems, a sufficient trimming frequency is once a week.

 

Changing the Schedule

The script checks for support of discard operations, then enabled a system timer for weekly trimming (by default this is scheduled for Mondays 12PM UTC) if it is not already enabled. If a custom schedule is desired, users can modify the schedule by editing the fstrim.timer file:

nano /lib/systemd/system/fstrim.timer

fstrim1.png

fstrim2.png

The timer is setup during initial-run startup, so it applies both after update and for new deployments.

If the timer has not been enabled yet, the script makes sure to execute the first trim by itself. This is done to elimate doncerns that the very first scheduled trim would impact testing results (since it might execute while testing is in progress). Therefore, it is best to run the first trim while no services are running yet, and this way have the following schedules trims finish more quickly.

fstrim3.png

This feature is not noisy, meaning the process it very fast, runs in the background, and doesn’t require any interaction from the user. The only indication that the cleanup has been carried out are terminal messages and entries in the log file. Response text from cleanup of old docker images is logged to loginvsi/update.log and filesystem trimming output can be found in loginvsi/startup.log file.

fstrim4.png