bind mount over a directory, how to access underlying files?
-
[email protected]replied to [email protected] last edited by
You can only mount into an empty directory. You cannot mix two directories with mount.
-
[email protected]replied to [email protected] last edited by
Well that's bullshit, I can mount to directories with contents
-
[email protected]replied to [email protected] last edited by
Alright, I didn't know you can mount "over" a directory. But my point was, you cannot mix them, you do not mount into the directly. It just replaces it. Which also would make this directory no longer accessible, but he wants both accessible at the same time.
-
[email protected]replied to [email protected] last edited by
The results are the same no matter which order I do the mounts in.
-
[email protected]replied to [email protected] last edited by
Ideally I'd like to avoid a script because my experience is they aren't very durable. I make mistakes and they are difficult to troubleshoot. So I am trying to just use the tools that are already available in the system.
But maybe there is something in the idea of using a second mount, like if
/home/user/folderApple
is always empty/home/user/folderApple-original
mounts ontop of/home/user/folderApple
at boot- then
/mnt/drive/folderBanana
also mounts ontop of/home/user/folderApple
when/if it becomes available (later in the order)
-
[email protected]replied to [email protected] last edited by
So... are you saying the contents of
/home/user/folderApple-original
really changes after you bindmount something over/home/user/folderApple
?
This seems odd.
Do you have submounts under the original directory? Try with--rbind
? -
[email protected]replied to [email protected] last edited by
The easy solution would be to have a third common mount point for the two that is switched if the external drive is connected or not.
-
[email protected]replied to [email protected] last edited by
In another subthread I came up with the below, is this what you mean? I haven't tried it yet.
/home/user/folderApple
is always empty/home/user/folderApple-original
mounts ontop of/home/user/folderApple
at boot- then
/mnt/drive/folderBanana
also mounts ontop of/home/user/folderApple
when/if it becomes available (later in the order)
-
[email protected]replied to [email protected] last edited by
Basically, yeah. Mount the "local" path on boot and then have systemd triggers for when USB mounts and unmounts to swap them automatically.
(Personally I wouldn't do it like this though because it will become trouble with any open files or shell or whatever in a path that is replaced by a different mount.)
-
[email protected]replied to [email protected] last edited by
Check out section 4.1 here https://www.baeldung.com/linux/bind-mounts