burmilla / os

Tiny Linux distro that runs the entire OS as Docker containers
https://burmillaos.org
Apache License 2.0
210 stars 13 forks source link

Cron - trim volumes on a schedule #165

Closed priceaj closed 6 months ago

priceaj commented 11 months ago

BurmillaOS Version: (ros os version) v1.9.6

Where are you running BurmillaOS? (docker-machine, AWS, GCE, baremetal, etc.) Hyper-V

Which processor architecture you are using? x64

Do you use some extra hardware? (GPU, etc)? No

Which console you use (default, ubuntu, centos, etc..) default

Do you use some service(s) which are not enabled by default? hyperv-vm-tools volume-nfs docker-compose

Have you installed some extra tools to console? No

Do you use some other customizations? No

Please share copy of your cloud-init (remember remove all sensitive data first)

mounts:
- - /dev/sdb1
  - /ContainerConfig
  - ext4
  - discard
- - nas.local:/NAS
  - /NAS
  - nfs4
  - ""
- - /dev/sdc1
  - /localStorage
  - ext4
  - discard
rancher:
  console: default
  environment:
    EXTRA_CMDLINE: /init
  services_include:
    docker-compose: true
    hyperv-vm-tools: true
    rancher-server: false
    volume-nfs: true
  state:
    dev: LABEL=RANCHER_STATE
    wait: true
  upgrade:
    url: https://raw.githubusercontent.com/burmilla/releases/v1.9.x/releases.yml
ssh_authorized_keys:
- xxx

Due to the way Hyper-V works with ext4 formatted virtual disks, Hyper-V will only compact the VHD for ext4 disks if the sectors are trimmed (i.e. zeroed out). Therefore I need to run trim sudo fstrim -av from the command line regularly to free up space used by the VHD file.

For volumes attached via cloud-init, I can add the discard flag to enable trim, however the main BurmillaOS drive /dev/sda1 does not have discard enabled by default and requires the fstrim command to be run in order to free up the space.

Is it possible to schedule a regular execution of sudo fstrim -av in BurmillaOS? crontab does not seem to be available by default, and I don't know if there is another system scheduler available by default.

It looks you might be able to create a custom service (https://burmillaos.org/docs/system-services/custom-system-services/), and schedule this via container crontab. But I don't understand how you would go about creating these services from the docs.

Any help would be appreciated.

olljanat commented 11 months ago

You can use any container image as system service so you basically need create container which have fstrim command included and setup entrypoint in way that it will run when container starts and contained stops after that.

Then just include needed volumes to it and set cron schedule.