automatic bind mount/unmount (discuss.tchncs.de)
submitted 3 months ago* (last edited 3 months ago) by to c/linux4noobs@programming.dev
 

I have bind mounts configured in my /etc/fstab. The source (i.e. where the files physically exist) is on a removable USB drive.

Right now it works but I have to mount/unmount everything individually when I plug/unplug the drive. I would like to be able to have the bind mounts follow the state of of the USB drive automatically.

Is there a way?

Edit here is relevant section of fstab:

/dev/mapper/external-crypt	/mount/external		auto	nosuid,nodev,nofail,x-systemd.device-timeout=5	0 0
/mount/external/realfolder	/home/user/folder	none	bind,nofail	0 0

So when I run sudo mount "/mount/external" I want sudo mount /home/user/folder to be implied; likewise for umount.

you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 3 months ago (7 children)

Usually your desktop environment does it. KDE allows it. Tell us more about your setup.

  • source
  • hideshow 7 child comments
  • [–] 2 points 3 months ago* (last edited 3 months ago) (3 children)

    Assuming that OP is using the term correctly, a bind mount is where you have a second "copy" of a mount somewhere else on the filesystem (like, you use mount --bind). So he might specifically want two mountpoints for the mount. I don't use KDE, but I don't know if they do that with whatever system they have going on.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 3 months ago* (2 children)

    Oh yeah, you're correct. I misinterpreted that. If @linuxPIPEpower@discuss.tchncs.de really does mean a bind mount, then I'm guessing it will require systemd. That can act upon the appearance of a file/folder and trigger another unit. In this case that would be a mount. Upon disappearance the reverse could happen.

    I don't know of a user-friendly way to do it, but if OP is talking about real bind mounts, they aren't a normal user anymore and this is a very specific usecase.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 3 months ago* (last edited 3 months ago)

    Yeah, and you may very well be giving him the right answer; he very well may be just be accidentally using the term, and actually thinking of a regular mount. I gave a response specific to bind mounts as a top level comment.

    EDIT: Yeah, he put a portion of his fstab up there


    he's after honest-to-God bind mounts (or at least, that's what he's presently using).

  • source
  • parent
  • [–] [S] 2 points 3 months ago (2 children)

    I use xfce4 on endeavor. How would you configure it in KDE?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 3 months ago (1 child)
  • [–] [S] 2 points 3 months ago*

    Thunar file manager has volman. You can use it to manually unmount, including binds, but I'm not sure how to trigger it to know about them automatically. It's an extra step because it has to read the rest of the fstab file to find any dependencies and I don't know why it would do that.

    I updated the OP to show my fstab

  • source
  • parent