this post was submitted on 26 Jun 2026
6 points (100.0% liked)

linux4noobs

4242 readers
2 users here now

linux4noobs


Noob Friendly, Expert Enabling

Whether you're a seasoned pro or the noobiest of noobs, you've found the right place for Linux support and information. With a dedication to supporting free and open source software, this community aims to ensure Linux fits your needs and works for you. From troubleshooting to tutorials, practical tips, news and more, all aspects of Linux are warmly welcomed. Join a community of like-minded enthusiasts and professionals driving Linux's ongoing evolution.


Seeking Support?

Community Rules

founded 2 years ago
MODERATORS
 

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
[–] linuxPIPEpower@discuss.tchncs.de 1 points 1 day ago (1 children)

Thanks, I am OK with issuing a command before physically unplugging the device. I was just finding too many uses of the word "mount" because it's a verb, a command and a noun in this situation lol. I added my fstab to the top so you can see that I am actually using a bind mount.

I investigated symlinks as an alternative and for some reason decided against them. One thing I like about bind mounts is that there is always a backup directory in the location, so if the USB isn't plugged in, accidentally saved files don't just fall into the void. But I don't remember if that was the reason.

I could write some kind of script but I thought it would make more sense to see if something had already been developed because usually in Linux, it has been.

[–] tal@lemmy.today 1 points 1 day ago

One thing I like about bind mounts is that there is always a backup directory in the location, so if the USB isn’t plugged in, accidentally saved files don’t just fall into the void. But I don’t remember if that was the reason.

So, if you have a symlink, what will happen is that trying to save to a path that passes through the symlink will fail, because the program trying to save will fail to access the original path (assuming your above directory structure; /mount/external will exist, but /mount/external/realfolder will not, as realfolder is on your USB drive and won't exist when the media isn't mounted). With most programs, they'll warn you that they couldn't write the file (and in fact, that the directory isn't there). From their standpoint, the path is invalid. You won't typically just save a file and have it vanish.

I guess you could theoretically have something like a script that writes a file data and fails silently if the path doesn't exist. I do think that it might get confusing, to have some files written to the bind mount point in the user directory


I mean, the OS isn't going to merge them when you do the bind mount or anything. You're going to have one directory structure on your removable media that contains some files, and when it's inserted and the bind mount is in place, that's what you'll see, and a second directory structure inside the bind mount that will have different data. Like, if whatever is writing this is something that you control, I think I might set it up to explicitly write somewhere else. Or just create a /mount/external/realfolder directory on the /mount filesystem and give the user write permission to /mount/external/realfolder which will have the same effect, with some data going to a the removable media and some to the directory structure where the mountpoint lives if the media isn't present (just that the files will be written to wherever /mount lives, which may not be the same filesystem as /home/user/; I don't know if that matters for your use case).

But if you do feel that you want to set up a bind mount, then yeah, I'd look at the other comment I have in response to your comment here, the one talking about systemd-udev.