I have an init script that allows me to mount a folder to tmpfs, while bind-mounting the folder on drive to another location, so I can sync the contents (on startup, shutdown, and when needed) between the tmpfs and the original folder on system drive.

It's used mostly to move to ram the folders and stuff that is written often to avoid excessive writes in the system drive (which is a USB flash or SD card).

I have a different init script for each mountpoint I need (each is actually generated by a setup script which is not relevant here).

Each of these init scripts does (as soon as possible during boot):

  • bind mount of folder X to another folder called X-bindmount located somewhere else in main drive. (the folder X-bindmount is also created if needed)
  • mount folder X as tmpfs
  • move content from X-bindmount to X (which is now a tmpfs and empty)
  • on shutdown or when asked to it syncs from X to X-bindmount.


How can I do this more or less natively with systemd? I can cobble together a systemd service that calls a script, what I'm asking is if there is a better, native way.


Asked this question in the systemd-devel mailing list, and got a definitive answer from Lennart. http://lists.freedesktop.org/archives/systemd-devel/2015-November/035043.html

Pasting here the answer, for posterity.

No, there is not. And I don't really see this a strong enough usecase to make it something native.



-- Lennart Poettering, Red Hat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.