LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   “mount -o remount,ro” makes source readonly also (http://www.linuxquestions.org/questions/linux-general-1/%93mount-o-remount-ro%94-makes-source-readonly-also-4175466492/)

emanation.grz 06-18-2013 10:36 AM

“mount -o remount,ro” makes source readonly also
 
Hello.
I tried to make next solution for making readonly folder by another path:

Code:

mount --bind /source/ /dest/
mount -o remount,ro /dest/

This is work in meaning that /dest/ becomes readonly. But my problem that source also stays readonly. What I do in details:

I have this

Code:

/dev/sdb1 on /mnt/raid3 type ext3 (rw,noatime)
I made folder and mount as bind

Code:

mkdir /mnt/raid3-readonly/
mount --bind /mnt/raid3 /mnt/raid3-readonly/

Now I can

Code:

cp /mnt/raid3-readonly/test.file /mnt/raid3-readonly/test.file2
next

Code:

mount -o remount,ro  /mnt/raid3-readonly/
cp /mnt/raid3-readonly/test.file /mnt/raid3-readonly/test.file3
cp: cannot create regular file `/mnt/raid3-readonly/test.file3': Read-only file system

Looks OK but:

Code:

cp /mnt/raid3/test.file /mnt/raid3/test.file4
cp: cannot create regular file `/mnt/raid3/test.file4': Read-only file system

And this is my problem. After

Code:

mount -o remount,rw  /mnt/raid3-readonly/
I can copy again at source

Code:

cp /mnt/raid3/test.file /mnt/raid3/test.file5
I'm really lost. Please, help. Maybe be it's a bug in kernel.

Code:

uname -a
Linux myserver 2.6.18-194.32.1.el5 #1 SMP Mon Dec 20 10:52:42 EST 2010 x86_64 x86_64 x86_64 GNU/Linux


Rumata 06-19-2013 02:56 AM

Not assuming that you haven't read the man page. still:

Note that behavior of the remount operation depends on the
/etc/mtab file. The first command stores the 'bind' flag to the
/etc/mtab file and the second command reads the flag from the
file. If you have a system without the /etc/mtab file or if you
explicitly define source and target for the remount command
(then mount(8) does not read /etc/mtab), then you have to use
bind flag (or option) for the remount command too. For example:

mount --bind olddir newdir
mount -o remount,ro,bind olddir newdir

Note that remount,ro,bind will create a read-only mountpoint
(VFS entry), but the original filesystem suberblock will be
still writable, it means that the olddir will be writable, but
the newdir will be read-only.

emanation.grz 06-19-2013 06:55 AM

Thank you for reply.
I tried
I think my problem related with /proc/mounts
BTW system does have /etc/mtab and content of it after mount -o remount,ro,bind /mnt/raid3 /mnt/raid3-readonly

Code:

/dev/sdb1 /mnt/raid3 ext3 rw,noatime 0 0
/mnt/raid3 /mnt/raid3-readonly none ro,bind 0 0

but content of /proc/mounts is

Code:

/dev/sdb1 /mnt/raid3 ext3 ro,noatime,data=ordered 0 0
/dev/sdb1 /mnt/raid3-readonly ext3 ro,data=ordered 0 0

and it explains why olddir also read-only.

I assumed that /mnt/raid3 path is overlapping with another mount point and affects on it too. That is why I changed source and mount point to another filesystem

Code:

mkdir /mnt/raid3/testfolder
mkdir /root/readonlyfolder
mount --bind /mnt/raid3/testfolder /root/readonlyfolder
mount -o remount,ro,bind /mnt/raid3/testfolder /root/readonlyfolder

Now /etc/mtab has

Code:

/dev/sdb1 /mnt/raid3 ext3 rw,noatime 0 0
/mnt/raid3/testfolder /root/readonlyfolder none ro,bind 0 0

but /proc/mounts still has both readonly

Code:

/dev/sdb1 /mnt/raid3 ext3 ro,noatime,data=ordered 0 0
/dev/sdb1 /root/readonlyfolder ext3 ro,data=ordered 0 0

So, I can rephrase my question. Why does "mount -o remount,ro" affect on /mnt/raid3 in /proc/mounts file?
Thanks.


All times are GMT -5. The time now is 09:37 AM.