Skip to content

fstools: allow multiple mount points for a single device (e.g., Btrfs subvolumes)#16

Open
shenwii wants to merge 1 commit into
openwrt:masterfrom
shenwii:block-mount-multi
Open

fstools: allow multiple mount points for a single device (e.g., Btrfs subvolumes)#16
shenwii wants to merge 1 commit into
openwrt:masterfrom
shenwii:block-mount-multi

Conversation

@shenwii
Copy link
Copy Markdown

@shenwii shenwii commented Mar 10, 2026

Summary

This MR enables support for mounting the same physical device (identified by UUID, Label, or device path) to multiple target mount points.

Background

Although the Linux kernel allows a single device to be mounted to different locations, the current implementation of fstools incorrectly treats the device identifier as a unique key, preventing multiple mount entries. This is particularly restrictive for Btrfs users who need to mount different subvolumes (subvol) to various system paths.

Key Changes

  1. mount_add function
    Changed the internal storage key from a simple identifier (UUID/Label/Device) to a composite key: concat(identifier, ",", target). This allows the system to store and track multiple configuration records for the same device.

  2. find_block & find_mount_point functions
    Updated these functions to return multiple device+target combinations. I have implemented a limit of 10 mount points per device, which should be sufficient for most use cases. All calling functions have been updated with loops to process these multiple results.

  3. umount_device function
    Added a skip_extroot flag to handle logic conflicts between mount_action and main_umount.

Testing

Configuration Example

To demonstrate the use case, this change allows a single Btrfs partition to be mounted to multiple paths using subvolumes in /etc/config/fstab:


config mount
        option uuid 'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option target '/overlay'
        option enabled '1'
        option options 'subvol=rootfs'

config mount
        option uuid 'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option target '/media/main'
        option enabled '1'
        option options 'subvol=main'

config mount
        option uuid 'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option target '/media/test'
        option enabled '1'
        option options 'subvol=main'

Previously, if multiple mount sections shared the same UUID, the later entry would overwrite the previous one in the vlist (due to the device identifier being used as the unique key). This patch ensures each unique (device, target) pair is treated as a distinct entry.

Testing Result

The following commands have been tested and are working as expected:

  • block mount
  • block umount
  • block detect
  • block info
root@OpenWrt:~# mount | grep /dev/m
/dev/mmcblk0 on /overlay type btrfs (rw,relatime,ssd,discard=async,space_cache=v2,subvolid=351,subvol=/rootfs)
/dev/mmcblk0 on /media/main type btrfs (rw,relatime,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/main)
/dev/mmcblk0 on /media/test type btrfs (rw,relatime,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/main)
root@OpenWrt:~# block info
/dev/ubi0_6: UUID="4e39f331-3004-45b2-8bce-93c4f5b0268b" VERSION="w5r0" TYPE="ubifs"
/dev/mmcblk0: UUID="a60604a0-11e2-447d-a6c2-58b85cc0533c" MOUNT="/overlay" TYPE="btrfs"
/dev/mmcblk0: UUID="a60604a0-11e2-447d-a6c2-58b85cc0533c" MOUNT="/media/main" TYPE="btrfs"
/dev/mmcblk0: UUID="a60604a0-11e2-447d-a6c2-58b85cc0533c" MOUNT="/media/test" TYPE="btrfs"
/dev/fit0: UUID="4231ad45-78f64759-81a62cfb-4f81a93a" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"
config 'global'
        option  anon_swap       '0'
        option  anon_mount      '0'
        option  auto_swap       '1'
        option  auto_mount      '1'
        option  delay_root      '5'
        option  check_fs        '0'

config 'mount'
        option  target  '/overlay'
        option  uuid    'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option  enabled '0'

config 'mount'
        option  target  '/media/main'
        option  uuid    'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option  enabled '0'

config 'mount'
        option  target  '/media/test'
        option  uuid    'a60604a0-11e2-447d-a6c2-58b85cc0533c'
        option  enabled '0'

config 'mount'
        option  target  '/rom'
        option  uuid    '4231ad45-78f64759-81a62cfb-4f81a93a'
        option  enabled '0'

Note: Currently, the block info command does not display mount options (such as Btrfs subvol). Consequently, while multiple mount points for the same device are now functional, the block info output may not yet reflect these specific options. I plan to submit a follow-up patch to include options details in the block info output to improve visibility.

Note: Changes in main_autofs and other areas were implemented for consistency but have not been fully tested in a live environment. Feedback or testing from others is welcome.

@shenwii
Copy link
Copy Markdown
Author

shenwii commented Mar 10, 2026

#12308

@shenwii shenwii force-pushed the block-mount-multi branch 4 times, most recently from 9027aab to c7ba4b7 Compare March 12, 2026 02:38
Previously, if multiple 'mount' sections in /etc/config/fstab referred
to the same physical device (via UUID, Label, or device path), the
latter configuration would override the previous ones, resulting in
only one active mount point.

This patch modifies the device matching logic to allow a single
source device to be mounted to multiple target paths. This is
particularly useful for users who need to expose the same partition
in different directory structures.

Signed-off-by: Shen Wei <shinkosame@gmail.com>
@shenwii shenwii force-pushed the block-mount-multi branch from c7ba4b7 to c86a72d Compare March 23, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant