Mount utilities

This module implements helper classes to access the new Linux kernel mount API implemented since Linux kernel version 5.2. The new API is file descriptor based meaning it is suited to be used with namespaces.

Currently only the bind mounts are implemented with ClonedTree but support for mounting any unprivileged file systems is planned in the future versions.

class lxns.mount.ClonedTree(path: str | Path)
__init__(path: str | Path)

Clone mount tree at the given path.

Requires being owner of the current MountNamespace and having CAP_SYS_ADMIN in the current UserNamespace.

The cloned tree can be mounted at any point with mount().

close() None

Close tree file descriptor.

Can be called multiple times in which case only first call will close the namespace and subsequent calls will be ignored.

mount(path: str | Path) None

Create bind mount at the given path.