Part 6 of 7 · 3 min read
Mount options
Mount options
Think of rules written on the door of a room: "no food", "quiet", "closing at 6". The room stays the same, and the rules change how it can be used. The analogy stops in one place: a rule on a door is advice, and a mount option is enforced by the kernel.
In plain words: A mount can carry options that change how the file system behaves. ro makes it read-only. noexec forbids running programs from it. nosuid ignores the set-user-id bits (Level 10). noatime and relatime reduce writes caused by reading, since a read normally updates the access time of the file. discard sends TRIM to a flash disk (Level 8, page 3). Each option is a way to make the system safer or faster without changing the data.
A worked example. A line of /proc/mounts on the test machine reads:
/dev/vda / ext4 rw,relatime,discard,no_prefetch_block_bitmaps,resv_strict,resuid=65534,resgid=65534 0 0
The source is the disk /dev/vda, the mount point is /, the type is ext4, and the options start with rw (read-write), then relatime (update the access time only if it is older than the modification time, or once a day) and discard (send TRIM). Other lines of the same file show ro,nosuid,nodev for tool directories that must not be changed.
The key lines. For a data disk that holds untrusted uploads, a good set is nosuid,nodev,noexec. For a flash disk with a heavy write load, noatime saves the writes that each read would cause.
Mount option
A mount option is a setting given when a file system is mounted that changes how the kernel treats it, such as read-only access, a ban on running programs, or the way access times are updated. It is listed in the mount table and in /etc/fstab.
Example: noexec on /tmp stops programs from running out of that directory.
Interview angle
A common question is "What happens when you mount a file system on a non-empty directory?" A good answer says that the old content is hidden, not deleted, and returns after the unmount, and adds that the VFS routes each path to the right file system by the mount table.
Check yourself:
1. What does noatime stop?
2. Which option would you use for a directory of uploaded files that must never be run?
3. Where do you see the options of the mounted file systems?
Words you will meet
| Word | Meaning |
|---|---|
| Mount point | Directory where another file system is attached. |
| VFS | Kernel layer that gives all file systems one interface. |
| Dentry | One cached name of a file with its inode. |
| tmpfs | A file system in memory. |
| Bind mount | The same directory visible at a second place. |
Quick notes
- Mounting attaches a file system to a directory. The old contents are hidden, not lost.
- A file is identified by its device number and inode number.
- The VFS defines superblock, inode, dentry and file objects with tables of functions.
proc,sysfsandtmpfsare not on a disk.statfsshows 0 blocks forprocandsysfs.- A bind mount shows the same inodes at a second path.
- Mount options such as
ro,noexec,nosuidandnoatimechange behaviour./proc/mountsshows them.