7

How to remount as read-write a specific mount of device? (one folder) The file is "Read-only file system", rw-r-r, so it not allow to change permissions. I need to replace that file, then change permissions back to read-only. I know command

mount -o rw,remount [destination folder]

I know this method is unstable, and may cause complications (every mount will get changed). So I must be sure that this will remount as read-write only a specific destination folder, not every mount of the device. I need do this on running system, not test environment. Embedded linux system. Is that possible?

Path to folder: /etc/foo/bar I need remount /bar folder.

EDIT:

mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro)
proc on /proc type proc (rw)
ramfs on /var type ramfs (rw)
sysfs on /sys type sysfs (rw)
tmpfs on /dev type tmpfs (rw)
devpts on /dev/pts type devpts (rw)
/dev/mtdblock4 on /nvram type jffs2 (rw)

output of cat /proc/mounts

cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro 0 0
proc /proc proc rw 0 0
ramfs /var ramfs rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /dev tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
/dev/mtdblock4 /nvram jffs2 rw 0 0

remount command

<root@elocal:/etc/foo/bar> ls -la
total 6
drwxr-xr-x    2 root     0               98 Jan 18  2011 .
drwxrwxr-x    7 root     0              105 Feb 10  2011 ..
-rw-r--r--    1 root     0             1052 Jan 18  2011 file1
-rw-r--r--    1 root     0              270 Jan 18  2011 file2
-rw-r--r--    1 root     0             1088 Jan 18  2011 file3
-rw-r--r--    1 root     0              270 Jan 18  2011 file4

mount -o rw,remount /etc/foo/bar
mount: can't find /etc/foo/bar in /proc/mounts
Lexx Luxx
  • 1,383
  • You might be able to do so by editing the /etc/fstab config file. I will see if there is a specific way of doing so. – ryekayo Aug 09 '14 at 13:46
  • You can't mount only a folder from a filesystem, unless you're talking about a bind mount. Also what's exactly wrong with mount -o rw,remount? – Cristian Ciupitu Aug 09 '14 at 13:54
  • 2
    Do you actually mean a specific mount (with multiple bind mounts, which you don't have right now on your setup), or a specific directory tree? What kernel version do you have? The support for differing options on different bind mounts has changed over time (see http://unix.stackexchange.com/questions/128336/why-doesnt-mount-respect-the-read-only-option-for-bind-mounts, especially the comments). – Gilles 'SO- stop being evil' Aug 09 '14 at 22:22

3 Answers3

1

No; you can not apply mount flags to directories, only the whole filesystem, so you have to make the whole thing rw.

psusi
  • 17,303
0

I found a way of editing the /etc/fstab config file so that you can create a bind mount:

/my/real/dir /to/mount/dir <filesystem> rw,bind 0 0

  • none - No options associated with mount point (like quotas)
  • rw - The mount point is read and writeable.
  • bind - The mount point is a bound
  • directory filesystem - ext2,ext3,vfat,etc.
ryekayo
  • 4,763
0
mount -o rw,remount /foo

will remount /foo mount point rw. If there is a /foo/bar mount point (whether ro or rw), the mount command will likely fail.

If there are /foo/what and /foo/ever directories, those will be rw as well. If your read-only mount point is

/foo
/bar
/baz

then

mount -o rw,remount /foo 

will keep other mount points read only.

Faheem Mitha
  • 35,108
Archemar
  • 31,554