linux下文件read only file system

本文探讨了在遇到只读文件系统错误时如何通过mount命令重新挂载来解决问题,并介绍了不同挂载选项的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近修改init进程,在创建文件的时候,提示read only file system.

就使用了mount命令重新挂载了一下,mount("/","/",NULL,MS_REMOUNT,0);

这样我就能够进行文件操作了,创建、读写、删除文件。

为了不影响别的功能,我想在执行mount("/","/",NULL,MS_RDONLY,0);给改回去。

但是这个情况下,会不会把已经修改了权限全给改掉呢?疑问中。

在代码里面remount之后,在串口执行mount -o remount ro / 之后,目录居然还能够写,这样貌似不大对吧。

命令没有用对,mount -o remount,ro /  这样文件就无法读写了。

mount 命令关于remount介绍

remount

Attempt to remount an already-mounted filesystem.  This is commonly used to change the mount flags for a  filesys‐
              tem, especially to make a readonly filesystem writeable. It does not change device or mount point.

              尝试重新挂载一个已经挂载的文件系统。

              这个命令通常用于改变已经挂载的文件系统的挂载标志,特别是让一个只读的文件系统可写。

              它不会改变设备或者挂载点。

              The  remount  functionality follows the standard way how the mount command works with options from fstab. It means
              the mount command doesn't read fstab (or mtab) only when a device and dir are fully specified.


     
              mount -o remount,rw /dev/foo /dir


              After this call all old mount options are replaced and arbitrary stuff from fstab is  ignored,  except  the  loop=
              option which is internally generated and maintained by the mount command.


              mount -o remount,rw  /dir


              After this call mount reads fstab (or mtab) and merges these options with options from command line ( -o ).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值