Why 'defaults' mount options are not seen in /proc/mounts or mount command ?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL)

Issue

  • How to determine full mount options for a mounted file system ?
  • If defaults provides an alias for async,auto,dev,exec,nouser,rw,suid, then why these options not reported in /etc/mtab, /proc/mounts or in mount command ?
  • If the filesystem is mounted with one of the option in defaults, do other options are applicable ?
  • For example, /etc/fstab lists tmpfs filesystem as below :
tmpfs                   /dev/shm                tmpfs    defaults        0 0  
  • However, mount command and /proc/mounts reports only rw from defaults :
# mount -v -t tmpfs 
tmpfs on /dev/shm type tmpfs (rw)
# cat /proc/mounts | grep tmpfs
tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0

Resolution

  • For tmpfs, the only filesystem options that are displayed are :

    • size=SIZE (if the size is not default)
    • nr_inodes=INODES (if the number is not the default)
    • mode=MODE (if the mode is not the default)
    • uid=UID (if the uid is not 0/root)
    • gid=GID (if the gid is not 0/root)
    • memory policy (if not default)
  • ro/rw is displayed for all filesystem types.

  • Some mount options are only displayed if they are not the default.
  • The most complete location to view the mount options is in /proc/self/mounts in RHEL 5 and /proc/self/mountinfo in RHEL 6

Root Cause

  • For most filesystems, the mount options are only displayed in /proc/mounts if :
    • they are applicable to the particular filesystem type
    • they are not strictly for internal use
    • the mount options are not the default setting
    • the user has the appropriate capabilities to show the options (CAP_SYS_ADMIN) in the current mount namespace

Diagnostic Steps

[1] On a test system, edit fstab to mount tmpfs with rw only and performed a reboot :

# cat /etc/fstab | grep tmpfs
tmpfs                   /dev/shm                tmpfs   rw              0 0

# cd /dev/shm/

# cat > script.sh
#!/bin/bash
echo "Script ran"

# chmod u+x script.sh 
# ./script.sh 
Script ran
  • Result : Script ran, though exec not set.

[2] Now, edit fstab to mount tmpfs with rw,noexec and performed a reboot :

# cat /etc/fstab | grep tmpfs
tmpfs                   /dev/shm                tmpfs   rw,noexec              0 0

# cd /dev/shm/

# cat > script.sh
#!/bin/bash
echo "Script ran"

# ls -l
total 4
-rw-r--r--. 1 root root 30 Apr  6 00:47 scripts.sh

# chmod u+x script.sh
chmod: cannot access `script.sh': No such file or directory
  • Result : Unable to set execute permission, as noexec is set explicitly.

  • For example, mounting a filesystem with rw,exec options, will also mount the filesystem with suid,dev,auto, nouser,async,relatime.

  • But, if any of these option is unset explicitly, it will not be applicable.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.