首页 > 解决方案 > Linux Mount 使用 Remount 以允许读写

问题描述

我想使用 root 帐户重新安装只读文件系统,使其变为可读写。

检查 Linux 手册页,我注意到没有像 MS_RDWRITE 这样的标志,所以我的问题是,有没有人知道一个在线示例,它演示了使用 mount 和 remount 标志设置只读路径以允许读取和写入?

对于运行嵌入式 Linux 的设备,这将在 C++ 中完成。

/* Here's the declared function for Mount a filesystem.  */
extern int mount (__const char *__special_file, __const char *__dir,
      __const char *__fstype, unsigned long int __rwflag,
      __const void *__data) __THROW;

标签: c++linux

解决方案


我无法让原生 API 正常工作。根据制造商,他们建议在终端窗口中使用 remount 命令。这对我来说是正确的。

当使用 root 权限调用时,这会将整个根文件夹重新挂载为可读写。

        // Remount the root folder.         
        char* cmd = "mount -nwo remount,rw /";
        if (-1 == system(cmd))
        {
            // handle the error.
        }   

推荐阅读