toolbox: prevent mounted snapshots from being gc'ed #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The toolbox uses ctr under the hood if available. The 'ctr image mount' command by default adds a 1 day lease on the created snapshot that is mounted as the upperdir. Therfore the snapshot will be gc'ed and the toolbox not function correctly anymore as the upperdir does not longer exist.
mounted upperdir snapshot is gc'ed after lease times out
The toolbox script uses the ctr client (which it seems should only be used for testing and administrative purposes?). This client will create a lease when using the
ctr image mount
command which lasts for one day and references the rw snapshot created.When said lease expires it will remove the upperdir of the mount and make the toolbox somewhat none functional.
In detail, if we run toolbox it will mount the fedore image and a rw snapshot which can be seen here:
$ cat /proc/mounts | grep toolbox overlay /var/lib/toolbox/core-docker.io_library_fedora-38 overlay rw,seclabel,relatime,lowerdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/1/fs,upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/27/fs,workdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/27/work,uuid=on 0 0
When inspecting the leases with ctr we can see that it creates a lease valid for a day:
After the lease expires it will remove the snapshot and therefore the mounted upperdir.
This lease can't be changed as it seems hardcoded in the client https://github.com/containerd/containerd/blob/main/cmd/ctr/commands/images/mount.go#L76-L80.
I worked around this by manually setting the label containerd.io/gc.root=true on the snapshot. This will prevent the
GC from removing the snapshot
There is also a --label flag which does not seem to work.
I'm not sure if setting
containerd.io/gc.root
is the best solution or if there is something else since i don't 100% understand what containerd is doing.For testing purposes i built an own version of ctr which sets the lease time to 1 minute. This helped for testing the problem.
How to use
Run the toolbox command on flatcar as usual and inspect manually with
ctr leases ls
,ctr snapshots ls
andctr snapshots info
.Testing done
Copied the toolbox script and updated it according to this PR. Called directly instead of the provided toolbox script.
changelog/
directory (user-facing change, bug fix, security fix, update)/boot
and/usr
size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.