大网数据广告活动
服务器运维问答

ramfs mounted through fstab is automatically owned by root

· 52CE 我爱测

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…

问题原文

原帖链接 · emmdee · CC BY-SA 3.0

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).

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。