欧拉允许disk分区多次mount,这种行为能否通过开关禁止
Try this: mount --onlyonce /dev/sdb1 /mnt/data, which prevents the same partition from being mounted multiple times to the same directory.
However, it cannot prevent an already mounted partition from being mounted again to a different directory, nor can it prevent a different partition from being mounted to the same directory.
The phrase “multiple mounts” here could refer to several different scenarios, each requiring a different handling approach.
If you’re mounting the same partition to two different directories, for example:
mount /dev/sdb1 /data
mount /dev/sdb1 /mnt/data
This typically just adds two access points to the same filesystem, without creating two independent data copies: changes made via /data will be visible through /mnt/data. Linux supports this usage, which is different from two separate machines mounting and writing to the same shared disk. Therefore, the data consistency risks associated with the latter scenario cannot be directly applied here.
If your goal is to prevent a script from being executed multiple times, or avoid repeatedly mounting the same filesystem to the same mount point, then the --onlyonce option mentioned above can be used to check whether “the same source has already been mounted to this mount point,” provided your mount version supports it. However, this is only a check for the current command and not a system-wide switch—it won’t prevent the same partition from being mounted to another directory.
Additionally, the same mount point might be covered by another filesystem being mounted on top of it. In such cases, the original content is usually just hidden by the upper mount and not deleted; it reappears after unmounting the upper layer. If you want to prevent such accidental operations, you need to check whether the target directory is already a mount point—not just whether the partition has been mounted before.
Could you please share your system version, the actual mount commands you’ve run, and clarify which scenario you’d like to prevent? Are you trying to avoid repeated mounts when running a script multiple times, or do you want to restrict a specific user or service to only mount a partition to a designated directory? The latter requires considerations around permissions and mount management strategies—command-line parameters alone cannot enforce such restrictions.