[How to] Create Periodic TRIM Job for LibreELEC (Intel)

  • I'm a former openELEC user who has been using LibreELEC for the past year and I'm very impressed at LibreELEC's features, stability and pace of new version releases. I would like to know if anyone out there knows how to set up a Periodic TRIM Cron Job for an Intel-based build of LibreELEC.

    Thanking you all in advance.

    MINIX NGC-1 (Intel-based)

  • I don't have an X86 machine running LE but this *should* work.

    Create in /storage/.config/system.d

    fstrim.service

    Code
    [Unit]
    Description=Run fstrim on all applicable drives
    
    [Service]
    User=root
    Type=oneshot
    ExecStart=/usr/sbin/fstrim -av

    fstrim.timer

    Code
    [Unit]
    Description=Run fstrim on boot and weekly afterwards
    
    [Timer]
    OnBootSec=15min
    OnUnitActiveSec=1w 
    
    [Install]
    WantedBy=timers.target

    Check that is works:

    systemctl start fstrim.service

    If happy: Enable it

    systemctl enable fstrim.timer

  • When I went to check that it works, I received the following error: "LibreELEC:~/.config/system.d # systemctl start fstrim.service
    Failed to start fstrim.service: Unit fstrim.service has a bad unit file setting.
    See system logs and 'systemctl status fstrim.service' for details."

  • OK - I was able to edit and commit the files and test it, however, when I went to enable fstrim.timer, I received the following error:

    "LibreELEC:~/.config/system.d # systemctl enable fstrim.timer
    Failed to enable unit: File fstrim.timer: Bad message"

  • I had to delete both the previously created fstrim.service and fstrim.timer files and recreate using nano - only then was I able to enable fstrim.timer. One of the two were corrupted.

    [SOLVED]