LinuxCommandLibrary

mount

Connect filesystems to the directory tree

TLDR

Show all mounted filesystems

$ mount
copy

Mount a device to a directory
$ mount [[-t|--types]] [filesystem_type] [path/to/device_file] [path/to/target_directory]
copy

Create a specific directory if it does not exist and mount a device to it
$ mount [[-m|--mkdir]] [path/to/device_file] [path/to/target_directory]
copy

Mount a device to a directory for a specific user
$ mount [[-o|--options]] uid=[user_id],gid=[group_id] [path/to/device_file] [path/to/target_directory]
copy

Mount a CD-ROM device (with the filetype ISO9660) to /cdrom (readonly)
$ mount [[-t|--types]] [iso9660] [[-o|--options]] ro [/dev/cdrom] [/cdrom]
copy

Mount all the filesystem defined in /etc/fstab
$ mount [[-a|--all]]
copy

Mount a specific filesystem described in /etc/fstab (e.g. /dev/sda1 /my_drive ext2 defaults 0 2)
$ mount [/my_drive]
copy

Mount a directory to another directory
$ mount [[-B|--bind]] [path/to/old_dir] [path/to/new_dir]
copy

SYNOPSIS

mount [options] device directory
mount [options] directory (from /etc/fstab)
mount [options] device (from /etc/fstab)
mount -a [options]
mount (list mounted filesystems)

PARAMETERS

device
    The device containing the filesystem to be mounted (e.g., /dev/sdb1, //server/share, /path/to/image.iso).

directory
    The empty directory (mount point) where the filesystem will be attached (e.g., /mnt/usb, /media/cdrom).

-a, --all
    Mount all filesystems mentioned in /etc/fstab (unless specified as noauto).

-t fstype, --types fstype
    Specify the filesystem type (e.g., ext4, xfs, nfs, cifs, iso9660, auto for detection).

-o options, --options options
    Specify various mount options as a comma-separated list. Common options include ro (read-only), rw (read-write), defaults (use default options from /etc/fstab), remount (change options on an already mounted filesystem), loop (mount a loop device), bind (bind mount), noexec (prevent execution of binaries), nosuid (ignore set-user-id/set-group-id bits).

-r, --read-only
    Mount the filesystem read-only. Equivalent to using -o ro.

-w, --read-write
    Mount the filesystem read-write. Equivalent to using -o rw (default).

-v, --verbose
    Increase verbosity of output, showing more details about the mounting process.

-f, --fake
    Perform a dry run; everything is done except for the actual system call to mount the filesystem.

-U uuid
    Mount the filesystem by its Universally Unique Identifier (UUID) instead of its device name. Often used in /etc/fstab.

-L label
    Mount the filesystem by its label instead of its device name. Often used in /etc/fstab.

DESCRIPTION

The mount command in Linux is used to attach a filesystem, located on a specified device (like a hard drive partition, USB stick, CD-ROM, or network share), to a designated directory in the system's directory tree. This directory is known as the mount point. Once mounted, the files and directories within that filesystem become accessible as if they were part of the local directory structure.

mount allows the operating system to access data on various storage devices or network locations by making them appear as a logical part of the root filesystem. It's crucial for accessing external storage, optical media, network file systems, or even virtual disk images. The opposite command, umount, detaches the filesystem from the mount point, making its contents inaccessible through that path until it is mounted again.

CAVEATS

Mounting typically requires root privileges. However, entries in /etc/fstab with the user or users option allow ordinary users to mount and unmount specific filesystems.
A mount point must be an empty directory before a filesystem is mounted on it. Any existing content in the directory will be hidden until the filesystem is unmounted.
Improper use or forcefully unmounting a busy filesystem can lead to data loss or corruption.

MOUNT POINT

A mount point is a directory on the existing filesystem tree (usually on the root filesystem) where an external or separate filesystem is attached. After mounting, the contents of the attached filesystem become accessible through this directory. For example, if you mount a USB drive at /mnt/usb, the files on the USB drive will appear inside /mnt/usb.

/ETC/FSTAB

The /etc/fstab file (filesystem table) is a configuration file that contains static information about filesystems. It's read by mount and other utilities to determine which filesystems to mount at boot time, their mount options, and mount points. This file is crucial for persistent filesystem configurations.

BIND MOUNTS

A bind mount allows you to re-mount a subtree of the filesystem hierarchy somewhere else. It effectively creates an alias or a duplicate view of a directory's contents at a different location. This is achieved using the -o bind option (e.g., mount --bind /olddir /newdir). It's often used in chroot environments or container technologies.

LOOP DEVICES

A loop device is a pseudo-device that makes a file accessible as a block device. This is commonly used to mount disk image files (like .iso, .img) as if they were physical disks. You can mount an ISO image directly using mount -o loop /path/to/image.iso /mnt/cdrom, without needing to burn it to a CD/DVD.

HISTORY

The concept of mounting filesystems is fundamental to Unix-like operating systems and has been part of their design since the early days. The mount command itself has evolved to support a wide array of filesystem types (e.g., ext2, ext3, ext4, XFS, ZFS, NTFS, FAT), network file systems (NFS, SMB/CIFS), and advanced features like loop devices and bind mounts. It is part of the util-linux project, which provides a suite of essential Linux utilities, and continues to be actively maintained and adapted to modern storage paradigms.

SEE ALSO

umount(8), df(1), lsblk(8), fstab(5), findmnt(8)

Copied to clipboard