I have seen an industrial computer running Debian, to protect the flash disk from writes and have the system in a defined state after every boot, the whole disk was mounted read-only, there are no other disks attached and no network storage. There are some services running, most notably Samba.

I tried to recreate that system for educational purposes, how can I stop any writes to disk, especially /var?

Just mounting as read-only breaks the system, as does mounting as tmpfs.

  • mount -o remount,ro /var – Ipor Sircer Jan 3 '17 at 23:10
  • 2
    A read-only /var will break your system. It's called /var because it holds variable data. Think of /var/cache, /var/spool, /var/log and so on. A very long time ago those were in /etc or /usr; then came the idea that /usr should be made read-only to enable diskless workstations and so was born /var... – AlexP Jan 3 '17 at 23:58
  • why don't you want anything in /var to be written to disk? – jayhendren Jan 4 '17 at 0:23
  • 1
    I rephrased the question to be more clear what I'm trying to accomplish – Christian Jan 4 '17 at 8:02

I'm guessing that the two approaches fail for very different reasons.

The /var filesystem hierarchy can not be mounted read-only since the system will be needing to write to it. There is no way around this.

Mounting it as a tmpfs filesystem seems like a good approach, but such a filesystem will be empty when mounted, and that will make the system fail in other ways.

This can still be a viable option, but you will have to make the system populate the empty /var hierarchy with the appropriate files and directories straight after mounting it, for example by untaring a pre-packed /var.tar file (or something), or recursively copying from an existing directory somewhere.

I'm not sure how to do that on Debian. OpenBSD has a memory file system called MFS. When mounting an MFS filesystem, one has the option to pre-populate it with the contents of a directory or an FFS file system on a block device (this may even be done from the /etc/fstab file).

Obviously, the changes to the contents of /var while the machine is running won't be persistent between reboots without syncing it to an actual disk upon shutdown, which may or may not be a problem in your case.

  • 1
    Searching for memory file system led to OverlayFS and AuFS, which seem to do excatly what I need, thank you. – Christian Jan 5 '17 at 15:35

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.