1

I'm trying to create a ramfs mount point in /tmp/ram using:

  1. Created an entry in /etc/fstab with the following line:

    ramfs /tmp/ram ramfs rw,nodev,noexec,nosuid,async,user,noauto 0 0

    (I've also tried replacing user with users. Also tried using x-mount.mkdir=0770)

  2. Created a directory with permissions 0775 at /tmp/ram using normal user (not root).

  3. Mounted the ramfs filesystem using the command mount /tmp/ram using normal user.

But after the mounting - the directory is always with the ownership user=root, group=me (me is the username/groupname of my normal user) and permissions 0755, which doesn't allow me to create a file in the directory.

Any idea how to proceed? I'd like to mount that filesystem using normal user - not root... I don't want to use root privileges at all for this mounting, that's why there's a line at /etc/fstab.

  • Maybe you should use tmpfs instead of ramfs where you can specify the uid, gid and mode of the mounted ramdrive. – Thomas Feb 18 '17 at 10:43
  • @Thomas I'd rather to avoid the swapping behavior of tmpfs. The ramfs filesystem seems to be exactly what I need - a pure RAM storage. – Dor Feb 18 '17 at 10:47
  • @Dor Memory pages used by tmpfs, just any other, are going to the swap only if they weren't used long ago. Furthermore, the physical memory pages which are free, because their original content is in swap, can be used by the kernel as disk cache. Ramfs is needed only if you want to make its content very fast even in the case if they weren't used long ago. And, if it deserves the cost for you, that you will have smaller disk cache. – peterh Feb 18 '17 at 10:55
  • @peterh I don't find that info which you write about "Memory pages used by tmpfs ... are going to the swap only if they weren't used long ago". How much time is it? Where is it being set/configured? – Dor Feb 18 '17 at 11:45
  • @Dor You can see files of the tmpfs as if their memory area would be allocated by a process. I.e. if you have a process, which allocates 1024 memory pages by a malloc() call, it is (from the view of the virtual mrmory handling code of the kernel) as if you would have an 1024 page long (=4MB) file on a tmpfs. They are handled by the same kernel routines. The only difference is that in the first case, these pages are directly accessible by a process, with byte operations. While in the second case, these memory blocks are accessible through filesystem operations (open, close, read, write). – peterh Feb 18 '17 at 12:06
1

It happens because the root directory of a mount point is provided already by the mounted filesystem driver. Thus, the inode parameters (incl. permission settings) are coming from it, and they overlap the original settings of the /tmp/ram.

Some filesystems provide a feature to fix or change their permissions from a mount a parameter, although it serves a different reason: if an fs doesn't have adequate permission information (vfat), or it is too alien from the unix security (cifs), it is a way to hot-provide one by the sysadm. Ramfs doesn't have this feature.

The "user" parameter only enables the mounting or unmounting of the fs by users, but doesn't change its security parameters. It is probably not your intention (I think you want to produce a very fast tmp reachable by all of the users concurrently).

Note, simple optimization: Instead ramfs, you could use also tmpfs. Tmpfs content is also mainly in ram, but it can be swapped out if it is unused. Ramfs content is always in the physical memory. Tmpfs can be parametrized as you wish, for example a mode=1777 would make it behave like /tmp (everybody can create/delete files, but only theirs).

You have to run the chmod/chown commands after the mount happened. The linux mount tools don't provide a facility for that easily.

I suggest to make an initscript for that in /etc/init.d (other init scripts provide the syntax, how can it be done easily) and do the mount/chmod on reboots.

  • I'd rather to avoid tmpfs as I wrote to Thomas above. I prefer the simplicity of fstab but I guess there is no choice other than having an init script to do the job. Init scripts confuse me, there are many methods to perform them and you always forget which is the correct and how to use it :| – Dor Feb 18 '17 at 10:51
  • @Dor Extending my comments above: if your processes are using only few ram, compared to what you have, then also the tmpfs files will be in ram. If your system uses more ram as you have, then an intelligent swapping will happen, to make all your system as fast as possible. With the ramfs, you essentially disable this intelligence of the kernel virtual memory handling. It results that the files in /tmp/ram will be reachable always very fast, but the other parts of your system (including the processes handling these files) will be slower, and this loss is in most cases more as the gain. – peterh Feb 18 '17 at 12:45

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.