The mount command is used to make local & remote filesystems available for read/write operations and can be as simple as:

mount /mnt/volume3

The example above lacks the device name and it would only work if there was an entry in /etc/fstab for the mountpoint /mnt/volume3 specifying the device name as in …

# grep /mnt/volume3 /etc/fstab
UUID=38209381­aa26­432d­b9fe­42f13f8213af         /mnt/volume3       xfs      defaults     1   2

Lacking an entry in /etc/fstab, we will always have to state the device on which the filesystem sits:

# mount /dev/sde3 /mnt/volume3

The command above does not state the file system type or any options. The file system type can be skipped with the most common types (ext4, xfs, nfs, vfat, etc) as they should be recognised automatically. As for the options… some are common to most file systems and many others that are specific to a few or even one file system. Let’s see some of the most common generic options that apply to most file system types.

# mount -­a                                    → mounts all file systems found in /etc/fstab not already mounted
# mount -­a -­t ext4,xfs                        → same but only for ext4 and XFS file systems
# mount /dev/sdb /opt/oracle -­o ro ­-n         → mount as read­only and don’t write entry to /etc/fstab
.                                               (needed when /etc is read­only!)
# mount /dev/sdc /opt/web -­o rw,async,noatime  → mounts read­write & asynch mode and with access
.                                                time updates disabled
# mount /dev/sdd /opt/src -­o auto,sync,atime   → mounts in synch mode, with access time updates enabled
.                                                and can be mounted with the “-­a” option
# mount /dev/sde /opt/apache ­-o suid,dev,exec,nouser  → mounts with suid enabled (allows setUID & setGID bits
.                                                   in the file system), dev (allows interpretation of
.                                                   block/character devices), exec (allows execution of binaries)
.                                                   and nouser (FS only mountable by root)
# mount /dev/sdf /opt/test                     → mounts with default options:
.                                                rw,suid,dev,exec,auto,nouser,async,diratime
# mount /dev/sdg /opt/fw -­o nodiratime,dirsync → directory access time updates disabled + synch writes
.                                                enabled on directory inodes

The mount command also allows us to remount a file system that is already mounted. That comes in handy when we need to change the mount options:

mount /opt/oracle -o remount,rw

It also allows us to move the mount point of mounted filesystems:

mount --move /opt/oracle /app/oracle

It allows the remount of part of the file hierarchy somewhere else:

mount --bind /app/oracle /opt/oracle     →  the contents can be accessed from both mount points

The “--bind” option does not propagate to submounts within the rebound directory. If we want to propagate the binding to any mount points within /app/oracle we can do so with the “--­­rbind” option.

Finally, we can mount a file (e.g. ISO, IMG, etc) as a file system:

mount -­o loop,ro /software/tails/tails­i386­1.2.3.iso /cdrom

As an option we can state the device with its UUID or LABEL rather than with its physical path. For example, if device /dev/sda3 has a UUID of “6fa9dae9­9ac9­4064­9dcb­4c3b52fc2ef7”, we can mount it with either of these 2 commands:

marc:/oracle> cat /etc/fstab
# /etc/fstab
# Created by anaconda on Wed Apr 29 22:52:21 2015
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
UUID=2787­84C0                            /boot/efi   vfat     umask=0077,shortname=winnt   0 0
UUID=d458b947­eaa6­430d­b327­1eb41b91edad    swap        swap     defaults   0 0
/dev/mapper/vg­root                       /           xfs      defaults   0 0
/dev/mapper/vg­home                       /home       xfs      defaults   0 0
UUID=84c5bb32­f956­41a7­ba4d­983f75c155d5     /tmp       ext4     defaults   1 2
/dev/mapper/vg­var                        /var        xfs      defaults   0 0

Even though mount‘s main objective is to mount filesystems, it can also be used to list mounted filesystems:

marc:~> mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=8089464k,nr_inodes=2022366,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
marc:~> mount ­-l -­t ext4
/dev/sdb1 on /tmp type ext4 (rw,relatime,seclabel,data=ordered) [TMP]
/dev/mapper/vgdata­sl7ora112 on /sl7ora112 type ext4
(rw,relatime,seclabel,stripe=512,data=ordered) [OSTMP]

Unmounting a filesystem can be done in various ways with umount:

umount /mnt/marc     → normal unmount
umount ­-f /mnt/marc  → unmount even if in use
umount ­-l /mnt/marc  → unmount when not in use anymore
umount ­-r /mnt/marc  → unmount and if it fails, try remounting read­only
umount ­-a            → unmount all filesystems in /etc/fstab

<< storage commands                   query commands >>