How to use mount command in Linux

mount command in Linux is used to mount partitions, usb storage, cd-drives. These devices are mounted on mount points in order to use of linux system.Once used the mounted device you need to unmount it, in order to prevent its further usage. Although mount automatically identifies file system type but in some cases  

Syntax

mount -t type device desitination_directory

OR

mount device desitination_directory

Destination directory should be available at time of execution of command

Display list of all mounted device

Simply running mount command with no other arguments displays all available mount points.

Syntax

mount

The information shows contains

device on directory type type [options]

This command shows list of all type of file system, but in case if you want to list only specific file system type

Syntax

mount -t file_system_type

Example

mount -t ext3

mount command with option

Addition mount option are available which can be used at time of execution of mount command

Below is list of typically used mount option

async: allows asynchronous I/O operations on the file system being used.
auto: marks the file system as enabled to be mounted automatically. This command can also be executed by using option mount -a
defaults: this option is an alias for async,auto,dev,exec,nouser,rw,suid.
exec: allows execution of binary files present in file system.
user: Allows an user (other than root user) to mount and unmount the file system.
loop: Mounts an image (an .iso file, for example) as a loop device.
noexec: prevents the execution of executable files on the particular filesystem.
nouser: prevents any users (other than root) to mount and unmount the filesystem.
remount: mounts the filesystem again in case it is already mounted.
ro: mounts the filesystem as read only.
rw: mounts the file system with read and write capabilities.
relatime: makes access time to files be updated only if atime is earlier than mtime.
user_xattr: allow users to set and remote extended filesystem attributes.

Mount CD ROM

Below command mount device CDROM available at /dev/cdrom at directory mnt/cdrom. Ensure directory cdrom exists at location mnt before executing command.

Syntax

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

OR

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

Mount file system using /etc/fstab file

fstab file control which file system are to be mounted at time of booting of system and location where these files are to be mounted. To mount a file system at time of boot you must make entry for specified file system in fstab file.

A typical entry in fstab has following fields

Device – mention for the device to which is to be mounted. Here you have to provide the device file or Label in this field.

Mount point – This contains information about location of directory where this file system is to be mounted.

Filesystem –  Here details for file system type (ext4, iso9660 etc) is given.

Mount options – Refer mount options above

Dump value – This can be either 0 or 1. Dump value refers to whether backup should be done for the file system or not. This method of backing up is not preferred method in modern systems, it can be left as 0.

Filesystem check order – This value determines the order in which filesystems are checked by “fsck” program during the boot process. If the value is “0”, fsck won’t check the filesystem. For older file systems ext2, NTFS or FAT16 system it should be 0.

A sample entry

/dev/sda5 /media/mydata ext4 defaults 0 0

This command will mount sda5 device at startup on location /media/mydata, with mount default option. There will be no Dump or backup taken f, also no File system check order is provided since no check is required.