Kent Overstreet <[email protected]> writes:

> On Sun, Aug 20, 2023 at 07:11:06PM +0000, Linus Heckemann wrote:
>> Hi all!
>> 
>> I'd like to use bcachefs as my root filesystem -- but I don't want / to
>> be the root of the filesystem.
>> 
>> This is achievable with btrfs using subvolume mounts (passing -o
>> subvol=... or -o subvolid=... to the mount program), but having looked
>> at the way it's handled on the kernel side (duplication of code from
>> fs/super.c in fs/btrfs/super.c) I'm pretty sure that's not something
>> that should be repeated in bcachefs.
>> 
>> It can also be done by having an initramfs that mounts the root of the
>> filesystem, then bind-mounts a subpath of that and
>> switch_root/pivot_root-ing into the bind mount. However, this approach isn't
>> representable in a classic fstab -- the root of the filesystem needs to
>> be mounted somewhere, but given that I want the subtree to be /, we have
>> nowhere to mount it.
>> 
>> One idea I have -- and I haven't read enough code yet to tell whether
>> the APIs already support this -- is that the new mount API
>> (fsopen/move_mount flow) could be used as-is or extended to support
>> mounting a subtree of a filesystem without needing an intermediate mount
>> of its root. This would allow _all_ filesystems to benefit from this
>> ability, not just bcachefs -- and to represent this as a "fake mount
>> option", much like X-mount.mkdir, in util-linux, making it possible to
>> put this type of mount in an fstab.
>> 
>> I'd appreciate any opinions on whether my thoughts make sense, and how
>> else my goal might be achievable.
>
> David Howells might have some thoughts?

I had a chat with Christian Brauner at All Systems Go, and he pointed me
to https://uapi-group.org/kernel-features/ -- so this is indeed not
currently possible, but there is some agreement that it would make sense.

The relevant point on that page at the time of writing:
> Ability to mount sub-directories of regular file systems instead of
> the top-level directory. i.e. for a file system /dev/sda1 which
> contains a sub-directory /foobar mount /foobar without having to mount
> its parent directory first. Consider something like this:
>
> mount -t ext4 /dev/sda1 somedir/ -o subdir=/foobar
>
> Use-Case: systemd-homed currently mounts a sub-directory of the
> per-user LUKS volume as the user’s home directory (and not the root
> directory of the per-user LUKS volume’s file system!), and in order to
> implement this invisibly from the host side requires a complex mount
> namespace exercise.

Reply via email to