2

Please read the following steps to understand my problem,

Execute following commands

mkdir ~/src
mkdir ~/destination

sudo mount ~/src ~/destination --bind -o ro

src folder has been bind mounted to destination folder. When I view the destination folder with nautilus it is read only. But the ll command gives same file permission for both src and destination folders.

What is the reason for this? How can I view the actual permission of the 'destination` folder? How does the nautilus display it as read only?

3

There are two things at play here:

  1. Directory permissions.
  2. Mount options.

The directory permissions are independent of the fact that the mount was read-only. Hence, ls will still list the permissions assigned to the folder, without regards for how it was mounted.

In the same way, if I mount a folder with noexec, ls will show that the executable files in there are still executable. Mounting the folder with noexec (or ro in your case) does not change the permissions on files and directories.

The file manager appears to be smarter though, and knows that the directory is mounted read-only. It obviously queries more than just the permission bits to find this out.


From comments: "In my use case I want to read the mount permission with a shell command".

The command mount, without any options, will output all the currently mounted partitions and their mount options:

$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=32841600k,nr_inodes=8210400,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=6572324k,mode=755)
(etc.)

The mount options are listed in parenthesis.

You may also investigate /etc/mtab for the currently mounted filesystems. This file has the same format as /etc/fstab, so you could do

awk '{ print $2, $4 }' /etc/mtab

to only get the mount points and the mount options, for example.

  • Thank you very much for the clear answer. In my use case I want to read the mount permission with a shell command. Then how can I achieve that? – Dulaj Atapattu Jun 9 '17 at 11:02
  • @DulajAtapattu Updated my answer. – Kusalananda Jun 9 '17 at 11:10
  • Thank you very much. Got a clear understanding and solved my problem by your answer. – Dulaj Atapattu Jun 9 '17 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.