5

I know that mounting a drive with "rw" would mount the file system as read/write, but what does that even mean? What's the difference between setting read and write via chmod?

3
  • 5
    a read-write mount is the default. A read-only mount will prevent all writes to all files, for all users, regardless of permissions or being root etc. Plus the error message is different.
    – ilkkachu
    Commented Jan 31 at 18:26
  • 2
    Try mounting a partition read-only then try editing a file or changing its permissions. Perhaps using a physical CD/DVD would be a good test.
    – doneal24
    Commented Jan 31 at 18:48
  • 4
    You may not be old enough to remember floppy disks, but all formats of floppy had a physical method of write-protecting the entire media. (Either by means of a switch built into the outer casing, or a notch punched at a certain location on its edge.) Mounting a filesystem read-only is like inserting a write-protected floppy. IFF the filesystem isn't write-protected (is mounted rw), then the filesystem's ownership and permission semantics can be used to administratively permit/deny certain users' processes write access to individual files/directories.
    – FeRD
    Commented Feb 1 at 8:58

3 Answers 3

11

chmod sets the permission for individual files, based on its owner and group. mount options apply to the entire filesystem, including its metadata.

For instance, a file's access time is updated every time it is read, even if no one has permissions to write to it. If the filesystem is mounted ro, then the access time won't be updated.

2
  • Thank you that made it much clearer. So just let me add another question. Is ls -l actually showing any information if a drive is mounted for example read only? Or does it just represent the permissions set via umask/chmod?
    – Noobman
    Commented Feb 1 at 10:06
  • 1
    ls -l shows you the permissions for each node (file or directory), its ownership (user and group) and (usually) the node's last modification time. The permissions shown are those of the node, regardless of how the filesystem was mounted (i.e. you might see nodes with write permissions on ro filesystems). Use mount with no arguments to see how the filesystem was mounted.
    – Zé Loff
    Commented Feb 1 at 10:32
7

mount options apply to the entire file system, but also are specific to the state of it being mounted. You can unmount and remount a file system with different options. A read-write file system can be unmounted and the physical drive moved out into a separate machine, which then mounts it read-only. When mounted read-only, all write operations will fail regardless of file permissions.

chmod modifies the metadata within the filesystem to alter the permissions of a specific file, such that a particular file can be made read-only or read-write for owner, group, or others.

The effective permissions at runtime would be the combination of the most restrictive permissions. For example, a file that is readable and writable by its owner cannot be modified if the file system is mounted read-only. Likewise, a file with read-only permissions cannot be modified, even when its file system is mounted read-write.

1
  • That was a really helpful example ty
    – Noobman
    Commented Feb 1 at 9:54
5

Mount options apply just for the time the filesystem is mounted, and for that particular mount. You could mount it somewhere else with different options at the same time (e.g. rw in one folder, and ro somewhere else).

chmod modifies the files' permission bits persistently, i.e. on-disk. It will affect every mount of the filesystem. For that reason you can only do that on a filesystem mounted rw.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .