The effect is to have folders on a partition bind mounted at various locations, but the full partition not mounted anywhere.
E.g. if /dev/sdb1 contains /f1 and /f2 and fstab looks like this:
# Mount to /mnt because it already exists and won't leave an extra empty folder after unmounted. # But if you want it to remain, create a root folder, maybe hidden like ".bindmounts" and mount to that. UUID=[uuid for /dev/sdb1] /mnt ext4 defaults 0 0 # Create root /myf1 and /myf1 first /mnt/f1 /myf1 none bind,defaults 0 0 /mnt/f2 /myf2 none bind,defaults 0 0
So after that, if you reboot, ls /mnt would show f1 and f2. How to hide/remove that? Make a systemd service. E.g. I’ll call it unmount-mnt.service
[Unit] Description=Unmount mnt After=mnt.mount myf1.mount myf2.mnt [Service] Type=oneshot ExecStart=umount /mnt [Install] WantedBy=local-fs.target
Put it in /lib/systemd/system then run
systemctl enable unmount-mnt.service
Reboot, and /mnt should be empty, and any content you have on sdb1 in folders f1 and f2 should now be visible under /myf1 and /myf2.
This works because systemd converts /etc/fstab to *.mount units. And this service waits until everything is mounted and then unmounts /mnt.
It’s my first shot at a systemd service, so I’m not sure if I did everything “right.”
QUESTION FOR MORE EXPERIENCED PEOPLE:
Will this cause any problems that you know of? I tested it in a VM and it works, but I didn’t test exhaustively to see if something down the road could drop the bind mounts, or something like that.