Read-only Bind Mount with systemd
In a previous post I commented on how to create a read-only bind mount out of a read-write mount. That approach only works if your distribution does a mount -a during boot. As Fedora uses systemd to initialize the filesystems, this trick stopped working quite a while ago.
I finally found another trick to get my read-only bind mount. It's a hack, but it works for me in Fedora 20. First create the bind mount as usual, with an entry in /etc/fstab like this:
/source/dir /destination/dir none bind 0 0
Then, create a systemd service to remount the bind read-only:
[Unit] Description=Remounts bind mount as read-only. After=destination-dir.mount [Service] Type=oneshot ExecStart=/usr/bin/mount -o remount,ro /destination/dir [Install] RequiredBy=destination-dir.mount
Activate the service:
# cp read-only-mount-bind.service /etc/systemd/system # systemctl daemon-reload # systemctl enable read-only-backup.service
The remount service should now be called every time the bind mount is mounted by systemd. You can test it by:
# systemctl stop destination-dir.mount # systemctl start destination-dir.mount