Read-only trees, ready before attach
Clone a bind mount and apply recursive attributes while it is still detached.
Mountfd.bind("/src", "/dst",
recursive: true, attrs: {rdonly: true})
A Ruby gem for the Linux mount API
Build a filesystem, set its attributes, and attach it in one atomic step. Mountfd brings Linux’s file-descriptor-based mount API to Ruby.
Ruby 3.2+ / Linux 5.2+ / MIT licensed
require "mountfd"
mount = Mountfd::FsContext.open("tmpfs") do |fs|
fs.set("size", "64M")
fs.create!
fs.mount(attrs: {nosuid: true})
end
# Ready. Now make it visible.
mount.attach("/mnt/tmp")
Invisible to the namespace until you attach it.
The legacy mount API exposes a mount before later attribute changes. Mountfd lets you prepare it while detached, then attach the finished tree with move_mount. Close the descriptor to discard an unattached mount.
Pass options directly to the kernel. Get structured diagnostics when a configuration fails.
fsopen · fsconfig
Create a new mount or clone an existing tree. Apply attributes before the mount becomes visible.
fsmount · open_tree · mount_setattr
Attach the prepared mount at its destination. No intermediate configuration is exposed.
move_mount
For Ruby tools that manage containers, sandboxes, and storage. A native C extension calls the kernel directly.
Explore runnable examplesClone a bind mount and apply recursive attributes while it is still detached.
Mountfd.bind("/src", "/dst",
recursive: true, attrs: {rdonly: true})
Use idmapped mounts to present different user and group IDs without recursively changing file ownership. Requires Linux 5.12+ and filesystem support.
View the idmapped volume exampleDiscover mounts with statmount and listmount, with a mountinfo fallback for older kernels.
Mountfd.mounts
Mountfd.mount_at("/home")
Add Mountfd to your Ruby project, then start with a small tmpfs mount in a Linux environment.
bundle add mountfd
Mount operations need CAP_SYS_ADMIN in the owning user namespace. Container and host policies may restrict access.
The gem also loads on macOS and Windows for feature detection; mount operations remain Linux-only. Check Mountfd.supported? before use.