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 destination_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
-a: Same as auto marks file system for automatic mounting.
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.
-l: lists all file system mounted.
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.
-t: This option is usually followed by file system to be used by mount command.
-r: Similar to ro mounts file system as read-only.
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 USB
To mount USB drive first identify mount destination for USB drive.
Syntax
mount /dev/sdxx /mount_destination
Example
Assuming that USB is device location /dev/sdc1, use below command for mounting
mount /dev/sdc1 /mnt/usb
Mount ISO image file
Similar to mounting of USB firstly identify mount destination for ISO image file. For mounting an disk image file you need to use loop device.
Syntax
mount /path/to/image.iso /destination/of_mount -o loop
Example
mount /test/home/image.iso /mnt/iso -o loop
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.
Below guide shows fstab file utilization for mounting windows partition in Linux
How to auto mount Windows NTFS partition in Fedora Linux at start up