]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mount: add --beneath support
authorKarel Zak <kzak@redhat.com>
Mon, 11 Aug 2025 11:08:13 +0000 (13:08 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Aug 2025 08:30:49 +0000 (10:30 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/mount
sys-utils/mount.8.adoc
sys-utils/mount.c

index d3535f7c91e6ddc13c91b66d798c7c6ac800e108..940e70af42f591f9ac26b5fa9ea33bfb9ac45820 100644 (file)
@@ -56,6 +56,7 @@ _mount_module()
                -*)
                        OPTS="  --all
                                --exclusive
+                               --beneath
                                --no-canonicalize
                                --fake
                                --fork
index c873d1e4d6a28984092c420b04bc905261f97ae6..4deee23fe840e4b76fe998bc3c244b7b0f005fa7 100644 (file)
@@ -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*.
 
index 858da6579cfdd11a8753d4562108b21ee69e0c3e..d6dd2805af576dc9d73602adfce8f3ef72060fcd 100644 (file)
@@ -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 <path>      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);