Mounted disk (ext4) - possible to run fstrim from host?

Given a block device with an ext4 filesystem and a mountpoint in a container I am unable to run fstrim to reclaim discarded blocks from ‘inside’ the container

fstrim: /var/lib/docker: FITRIM ioctl failed: Operation not permitted

This is understandable, however I am unable to find a way to perform the operation on the host

My searching found the following directory that allows rootfs access from the host


However, the mountpoint for the block device is empty.

What I’m looking to achieve is either from the host or the container to run fstrim without having to shut down the container, mount the block device to the host, run fstrim, unmount, then restart the container.

What storage pool driver are you using?

The container’s root/storage pool is on zfs, the disk device attached has ext4 on top of a zvol.

If this is an externally attached volume then I believe you can temporarily mount the volume on the host to run fstim.

I was able to to test it out and mount it (while it was still mounted in the container) to the host and run the command. Seemingly all is ok and the space is reclaimed as expected.

However, is there any risk for corruption from having it (even temporarily) mounted in both places and executing a trim?

I think mounting at the same time is fine as it’s one kernel and one filesystem, as for fstrim if it’s ok to do it while filesystem is in use then should be fine if mounted twice. Any thoughts @stgraber?

Yep, all fine. Only risk is when mounting a block device on two different systems, on the same system, the kernel will treat the second mount as a bind-mount and things will work just fine.

1 Like