ramfs was chosen specifically because there is zero chance of files being written to disk (swap space is used with tmpfs). tmpfs is out of scope for this question.

Here is my fstab entry for the mount point:

ramfs /path/to/mount ramfs  defaults,nofail   0 0

After mounting, I can set the permissions just fine:

chown -R myuser:myuser /path/to/mount

The problem comes after a reboot. The owner becomes root after reboot and it manually has to change back to my user. All I need to do is have the user id set at mount time (or persist through reboots).


ramfs has absolutely no mount options, so it isn't possible to set a mount uid/gid as it is with tmpfs.

From the man page:

Ramfs is a memory based filesystem. Mount it and you have it. Unmount it and it is gone. Present since Linux 2.3.99pre4. There are no mount options.

Obviously you are aware of the danger of your system running out of memory and crashing because your user accidentally overflowed the ramfs, and you have accepted that risk. So we won't mention that tmpfs solves this problem, and is why ramfs hasn't gotten much developer attention and is rarely used. To quote the kernel developers:

One downside of ramfs is you can keep writing data into it until you fill up all memory, and the VM can't free it because the VM thinks that files should get written to backing store (rather than swap space), but ramfs hasn't got any backing store. Because of this, only root (or a trusted user) should be allowed write access to a ramfs mount.

A ramfs derivative called tmpfs was created to add size limits, and the ability to write the data to swap space. Normal users can be allowed write access to tmpfs mounts. See Documentation/filesystems/tmpfs.txt for more information.

The only way you can do this, therefore, is to continue to set the ownership after the filesystem is mounted, e.g. in rc.local.

| improve this answer | |
  • Thank you, I think that confirms my suspicions on how it behaves. Any idea why tmpfs allows uid set in fstab but ramfs doesn't? – emmdee Jan 30 '18 at 18:34
  • Likely because it was never an intention to make it easy to hand a ramfs mount over to a normal user, and for good reasons. – Spooler Jan 30 '18 at 19:09
  • @emmdee ramfs is a very thin wrapper over Linux's existing disk caching mechanisms. Since it's so easy to break a system accidentally or intentionally with it, it's deliberately made not easy for ordinary users to do so. – Michael Hampton Jan 30 '18 at 19:21

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.