最近修改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 ).