On Linux, UNIX, and similar operating systems, file systems on different partitions and removable devices like CDs, DVDs, or USB flash drives can be attached to a mount point in the directory tree, and detached again. To attach or detach a file system, you can use the mount or umount command respectively.

Here are just few mostly used examples:

List currently mounted file systems

# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /sys/kernel/config type configfs (rw)

The findmnt utility allows users to list mounted file systems in a tree like form.

# findmnt
TARGET                        SOURCE     FSTYPE     OPTIONS
/                             /dev/sda2  xfs        rw,relatime,attr2,inode64,noquota
|-/sys                        sysfs      sysfs      rw,nosuid,nodev,noexec,relatime
| |-/sys/kernel/security      securityfs securityfs rw,nosuid,nodev,noexec,relatime
| |-/sys/fs/cgroup            tmpfs      tmpfs      ro,nosuid,nodev,noexec,mode=755
| | |-/sys/fs/cgroup/hugetlb  cgroup     cgroup     rw,nosuid,nodev,noexec,relatime,hugetlb
| | |-/sys/fs/cgroup/memory   cgroup     cgroup     rw,nosuid,nodev,noexec,relatime,memory
| | |-/sys/fs/cgroup/blkio    cgroup     cgroup     rw,nosuid,nodev,noexec,relatime,blkio
| | |-/sys/fs/cgroup/net_cls  cgroup     cgroup     rw,nosuid,nodev,noexec,relatime,net_cls

List only specified type of mounted file systems.

List sysfs type file system only

# mount -t sysfs
sysfs on /sys type sysfs (rw)

List mounted ext4 file systems only

# mount -t ext4 
/dev/sda2 on / type ext4 (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-home on /home type ext4 (rw)
/dev/mapper/vg0-opt on /opt type ext4 (rw)
/dev/mapper/vg0-tmp on /tmp type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)

Or, run

# findmnt -t ext4

Mounting a File System

The general mount command syntax to mount a device:

mount [option…] device directory

The mount command reads the content of the /etc/fstab configuration file to see if the given file system is listed. This file contains a list of device names and the directory in which the selected file systems should be mounted, as well as the file system type and mount options.

Because of this, when you are mounting a file system that is specified in this file, you can use one of the following variants of the command:

mount [option…] directory
mount [option…] device

Mount a specified file system type

Like mentioned in previous section, in most cases, mount detects the file system automatically. However, some file systems need to be specified manually especially if they are not in /etc.fstab. To specify the file system type, use the mount command in the following form:

mount -t type device directory

Here are just few examples:

Mount a CD ROM

mount -t iso9660 -o ro /dev/cdrom /mnt

or mount an iso image as a loop device

mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom

Mount a usb drive

mount -t vfat /dev/sdc1 /media/flashdisk

Mount options

To specify additional mount options, use the command in the following form:

mount -o options

When supplying multiple options, do not insert a space after a comma, or mount will incorrectly interpret the values following spaces as additional parameters

Option Description
async Allows the asynchronous input/output operations on the file system.
auto Allows the file system to be mounted automatically using the mount -a command.
defaults Provides an alias for async,auto,dev,exec,nouser,rw,suid.
exec Allows the execution of binary files on the particular file system.
loop Mounts an image as a loop device.
noauto Disallows the automatic mount of the file system using the mount -a command.
noexec Disallows the execution of binary files on the particular file system.
nouser Disallows an ordinary user (that is, other than root) to mount and unmount the file system.
remount Remounts the file system in case it is already mounted.
ro Mounts the file system for reading only.
rw Mounts the file system for both reading and writing.
user Allows an ordinary user (that is, other than root) to mount and unmount the file system.

Mount all file systems in /etc/fstab

mount -a 

Bind mount points to a new directory

The mountpoint can be binded to a new directory. So that you would be able to access the contents of a filesystem via more than one mountpoints at the same time.

Use -B option with olddir and newdir to be binded as follows, here is the example

# mount -B /a2_lun11 /lun11   # or mount --bind /a2_lun11 /lun11
# mount | grep lun11
/dev/mapper/A2_LUN11 on /a2_lun11 type xfs (rw)
/a2_lun11 on /lun11 type none (rw,bind)

Now you got one file system, with two mount points.

To be noted is that a user can access both mout points, but the new mount point can't be bind to a sub directory under the origional mount point.

To make it more flexible, try

mount -R old_directory new_directory
mount --rbind old_directory new_directory

It gives more flexible.

Shared mounting points

It's slightly different with the mount point binding. The useful case is that for some scenario, you want a media or a filesystem mounted and showing two or more different mount points once mounted.

Here is an example for CD-ROM media.

First, make /media directory shared

# mount --bind /media /media
# mount --make-shared /media

Then create its duplicate in /mnt by using the following command:

# mount --bind /media /mnt

Now, try mount a CD-ROM to

# mount /dev/cdrom /media/cdrom

The good part of this is now you see the contents of the CD-ROM under two mount points, and you only need do this once. Sometime later, if you want to mount a usb drive to /media/usb directory, the content of the use drive will show up in two directories once it's mounted.

Itsn't it a nice feature?

Move a mount point

You can always change mount point by remounting a file system, however, in case you want to do it on the fly, try this

mount --move /mnt/userdirs /home
mount -M /mnt/userdirs /home

Now you will see the filesystem userdirs appears under /home/

Want to know how to umount a file system, see The umount command examples

Comments powered by CComment