Linux Mount Command Tutorial With Examples
As we know Linux operating system mainly uses files and folders as operational units. Files an folders are stored in files systems and disks. There are different tools to manage file systems and disks. But
mount is de facto command used to mount and list disks and files systems. In this tutorial we will look different type of usages of mount.
Normally most of the Linux operating systems are started by mounting some file system for system partition and user partition. The mounted partitions can be changed according to configuration. These partitions and file systems can be listed just issuing
mount command like below. In this example we can see that are are some psedeu partitions those used by operations system related functionalities.
Mount file systems and partitions are not so hard or complex in the command line. To mount just provide the partitions that will be mounted and the destination where mounted partition will be accessed.
$ mount /dev/vdb1 /mnt
In previous example we have mounted a partition without specifying a file system. Because mount is decided the partitions file system automatically and set required parameters internally without needing any additional information. But some time this can not worked. We can specify file system type with
-t parameter like below. In this example we will mount ext4 file system.
$ mount -t ext4 /dev/vdb1 /mnt
As we know NTFS is windows native file system. Mounting NTFS file system is very similar. NTFS provides reach feature set like BTRFS file system which is used by some of the distributions. We can see from mount output NTFS is named as fuseblk .
$ mount -t ntfs /dev/vdb1 /mnt
FAT is predecessor of the NTFS file system and used wide in different systems like camera, TV etc. FAT file systems can be specifically mounted like below.
$ mount | grep vdb1
CD-ROM is old technology nowadays. But the CD-ROM de facto file system ISO is used regularly for distribution of Linux distributions, Setup tools etc. These ISO file system can be mounted with the following command.
$ mount -t iso9660 virtio-win.iso /mnt
Mount All File Systems Of Fstab
Up to now we have mounted file systems by giving details. There is a configuration file used by mount which resides
/etc/fstab . This file is used to mount file systems during boot time. But this configuration file can be use after boot.
$ mount -a
Unmount All File Systems Of Fstab
In previous example we have used
fstab file as mount configuration but this can be also used as unmount configuration to unmount all file systems specified in fstab.
$ unmount -a
Mount Specific File Systems Of Fstab
Fstab can be used to get mount configuration of specific mount point. Below is an example fstab file that provides mount configuration for
/mnt . We will mount this line by specifying mount path.
UUID=01f0e46f-9e44-4e25-8712-886427a3798b / ext4 errors=remount-ro 1
UUID=764C4C593741045B /mnt ntfs errors=remount-ro 1
And we mount
$ mount /mnt
List Mounted File Systems
Mounted file systems can be listed with
$ mount -l
List Mounted Ext3 File Systems
While listing specific file systems can be specified to be listed. This can be used
$ mount -l -t ext3
List Mounted Ext4 File Systems
Ext4 file systems can be listed with the
-t ext4 parameter like below.
$ mount -l -t ext4
List Mounted Btrfs File Systems
Btrfs file systems can be list with the
-t btrfs like below.
$ mount -l -t btrfs
Bind Mount To New Directory
After mounting to a directory the mount point can be changed. We will provide current mounted point and new mount point in row with
-B parameter. This is actually do not removes old mount only adds new directory as mount.
$ mount -B /mnt /mnt2
Mount File System Read Only
While mounting file systems there are a lot of options which effects the mount operation. One of the most used option is read/write option. By default file systems are mounted read/write able. But there are some situations we need to mount read only. Mount can mount read only with
$ mount -r /mnt
Remount Mounted File System
All ready mounted file systems can be remounted easily with
-o mount parameter. This is needed some times some configurations about the file system is changed and make new configuration effective.
$ mount -o remount /mnt
Unmount Multiple Mounts
Previously we have mounted multiple mount points. Now we may want to unmount the multiple mount points with the following commands.
$ umount /mnt /mnt2
Unmounting have some restrictions. While there is operations on the mounted partitions these partitions can not be unmounted. This can be an unwanted situation. There is a work around which will unmount the system after the operation on the mount point.
$ umount -l /mnt
In previous example we have looked lazy unmount which will wait the operation to end in order to unmount the mount point. There is a hard way which will forcibly unmount the mount point. But keep in mind that this can create problems with file systems.
$ umount -f /mnt