app.mount
app.mount provides thin command-construction wrappers around util-linux
mount and umount.
This module constructs
ward.process.cmd(...)invocations; it does not parse output. consumers can usewardlib.tools.out(or their own parsing) on the:output()result.
This module models a small set of commonly used options. Everything unmodeled
can be passed through via opts.extra.
Import
local Mount = require("wardlib.app.mount").Mount
Privilege escalation
Mounting and unmounting typically require elevated privileges. Prefer
wardlib.tools.with so escalation is explicit and scoped.
local with = require("wardlib.tools.with")
with.with(with.middleware.sudo(), function()
Mount.mount("/dev/sdb1", "/mnt/data", { fstype = "ext4" }):run()
end)
Options
MountOpts
fstype: string?— adds-t <fstype>options: string|string[]?— adds-o <opts>(string or list joined by commas)readonly: boolean?— addsroto-obind: boolean?— adds--bindrbind: boolean?— adds--rbindmove: boolean?— adds--moveverbose: boolean?— adds-vfake: boolean?— adds-fextra: string[]?— appended before positional args
UmountOpts
lazy: boolean?— adds-lforce: boolean?— adds-frecursive: boolean?— adds-Rverbose: boolean?— adds-vextra: string[]?— appended before positional args
API
Mount.mount(source, target, opts)
Builds: mount [opts] [source] [target]
Mount.mount(source: string|nil, target: string|nil, opts: MountOpts|nil) -> ward.Cmd
Notes:
- If both
sourceandtargetarenil, this corresponds to plainmount(printing the current mount table).
Mount.umount(target, opts)
Builds: umount [opts] <target>
Mount.umount(target: string, opts: UmountOpts|nil) -> ward.Cmd
Examples
Show current mounts
local out = require("wardlib.tools.out")
local mounts = out.cmd(Mount.mount(nil, nil))
:label("mount")
:lines()
Mount a device read-only
-- mount -t ext4 -o ro /dev/sdb1 /mnt/data
Mount.mount("/dev/sdb1", "/mnt/data", { fstype = "ext4", readonly = true }):run()
Bind mount
-- mount --bind /src /dst
Mount.mount("/src", "/dst", { bind = true }):run()
Unmount recursively
-- umount -R /mnt/data
Mount.umount("/mnt/data", { recursive = true }):run()