From c3882c00c16bf8e044991e057acdf1bc00a3b374 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 11 Aug 2025 13:08:13 +0200 Subject: [PATCH] mount: add --beneath support Signed-off-by: Karel Zak --- bash-completion/mount | 1 + sys-utils/mount.8.adoc | 12 ++++++++++++ sys-utils/mount.c | 10 ++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bash-completion/mount b/bash-completion/mount index d3535f7c9..940e70af4 100644 --- a/bash-completion/mount +++ b/bash-completion/mount @@ -56,6 +56,7 @@ _mount_module() -*) OPTS=" --all --exclusive + --beneath --no-canonicalize --fake --fork diff --git a/sys-utils/mount.8.adoc b/sys-utils/mount.8.adoc index c873d1e4d..4deee23fe 100644 --- a/sys-utils/mount.8.adoc +++ b/sys-utils/mount.8.adoc @@ -317,6 +317,18 @@ Since version 2.35 it is possible to use the command line option *-o* to alter m + Note that it is a bad practice to use *mount -a* for _fstab_ checking. The recommended solution is *findmnt --verify*. +*--beneath*:: +Mount the filesystem beneath the top mount of the specified target (mountpoint), allowing the top mount to be unmounted. This option replaces the filesystem at the mountpoint in an atomic manner, ensuring there is no moment when the filesystem is absent. ++ +For example update from a Btrfs filesystem to an XFS filesystem without ever revealing the underlying mountpoint: +____ +.... +mount -t btrfs /dev/sdA /mnt +mount --beneath -t xfs /dev/sdB /mnt +umount /mnt +.... +____ + *-B*, *--bind*:: Remount a subtree somewhere else (so that its contents are available in both places). See above, under *Bind mount operation*. diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 858da6579..d6dd2805a 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -559,7 +559,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_OPTIONS, out); fputs(_(" -a, --all mount all filesystems mentioned in fstab\n"), out); fputs(_(" -c, --no-canonicalize don't canonicalize paths\n"), out); - fputs(_(" --exclusive allow only one filesystem instance"), out); + fputs(_(" --beneath attach the filesystem beneath the top mount\n"), out); + fputs(_(" --exclusive allow only one filesystem instance\n"), out); fputs(_(" -f, --fake dry run; skip the mount(2) syscall\n"), out); fputs(_(" -F, --fork fork off for each device (use with -a)\n"), out); fputs(_(" -T, --fstab alternative file to /etc/fstab\n"), out); @@ -710,11 +711,13 @@ int main(int argc, char **argv) MOUNT_OPT_OPTSRC, MOUNT_OPT_OPTSRC_FORCE, MOUNT_OPT_ONLYONCE, - MOUNT_OPT_EXCL + MOUNT_OPT_EXCL, + MOUNT_OPT_BENEATH, }; static const struct option longopts[] = { { "all", no_argument, NULL, 'a' }, + { "beneath", no_argument, NULL, MOUNT_OPT_BENEATH }, { "exclusive", no_argument, NULL, MOUNT_OPT_EXCL }, { "fake", no_argument, NULL, 'f' }, { "fstab", required_argument, NULL, 'T' }, @@ -982,6 +985,9 @@ int main(int argc, char **argv) case MOUNT_OPT_EXCL: mnt_context_enable_exclusive(cxt, 1); break; + case MOUNT_OPT_BENEATH: + mnt_context_enable_beneath(cxt, 1); + break; case 'h': mnt_free_context(cxt); -- 2.47.3