On UNIX and UNIX operating system operating systems, you’ll use the mount command to connect (mount) file systems and removable devices like USB flash drives at a selected mount purpose within the directory tree.
The umount command detaches (unmounts) the mounted classification system from the directory tree.
In this tutorial, we are going to reassess the fundamentals of attaching and detaching numerous file systems victimisation the mount and umount commands.
How to List Mounted File Systems
When used with none argument, the mount command canshow all presently hooked up file systems:
mount
By default, the output can embody all file systems as well as the virtual ones like cgroup, sysfs, and others. every line contains info concerning the device name, the directory to that the device is mounted to, the kind of the filesystem and also the mount choices within the following form:
device_name on directory type filesystem_type (options)
To display only certain file systems use the -t
option.
For example, to show only the ext4 partitions you can type:
mount -t ext4
Mounting a File System
To mount a classification system in an exceedingly given location (mount point), use the mount command within the following form:
Once the filing system is connected, the mount purpose becomes the foundation directory of the mounted filing system.
For example, to mount the /dev/sdb1
file system to the /mnt/media
directory you would use:
sudo mount /dev/sdb1 /mnt/media
Usually when mounting a device with a common file system such as ext4
or xfs
the mount
command can auto-detect the filing system kind. However, some file systems aren’t recognized and want to be expressly such that.
Use the -t
option to specify the file system type:
mount -t TYPE DEVICE_NAME DIRECTORY
To specify additional mount options , use the -o
option:
mount -o OPTIONS DEVICE_NAME DIRECTORY
Multiple options can be provided as a comma-separated list (do not insert a space after a comma).
You can get a list of all mount options by typing man mount
in your terminal.
Mounting a File System using /etc/fstab
When providing only one parameter (either directory or device) to the mount command, it’ll browse the content of the /etc/fstab configuration file to examine whether or not the desired filing system is listed or not.
If the /etc/fstab
contains information about the given file system, the mount
command uses the value for the other parameter and the mount options specified in the fstab
file.
The /etc/fstab
file contains a list of entries in the following form:/etc/fstab
[File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]
Use the mount
command in one of the following forms to attach a file system specified in the /etc/fstab
file:
mount [OPTION...] DIRECTORY
mount [OPTION...] DEVICE_NAME
Mounting USB Drive
On latest UNIX operating system distribution like Ubuntu, USB drives can auto mount after you insert it, however typically you will ought to manually mount the drive.
To manually mount a USB device, perform the subsequent steps:
- Create the mount point:
sudo mkdir -p /media/usb
- Assuming that the USB drive uses the
/dev/sdd1
device you can mount it to/media/usb
directory by typing:sudo mount /dev/sdd1 /media/usb
- To find the device and filesystem type, you can use any of the following commands:
fdisk -lls -l /dev/disk/by-id/usb*dmesglsblk
To mount exFAT formatted USB drives, install the free FUSE exFAT module and tools .
Mounting ISO Files
You can mount an ISO file using the loop device which is a special pseudo-device that makes a file accessible as a block device.
- Start by creating the mount point, it can be any location you want:
sudo mkdir /media/iso
- Mount the ISO file to the mount point by typing the following command:
sudo mount /path/to/image.iso /media/iso -o loop
- Don’t forget to replace
/path/to/image.iso
with the path to your ISO file.
Mounting NFS
To mount an NFS share you’ll need to have the NFS client package installed on your system.
- Install NFS client on Ubuntu and Debian:
sudo apt install nfs-common
- Install NFS client on CentOS and Fedora:
sudo yum install nfs-utils
Use the steps below to mount a remote NFS directory on your system:
- Create a directory to serve as the mount point for the remote filesystem:
sudo mkdir /media/nfs
- Generally, you will want to mount the remote NFS share automatically at boot. To do so open the
/etc/fstab
file with your text editor :sudo nano /etc/fstab
- Add the following line to the file, replacing
remote.server:/dir
with the NFS server IP address or hostname and the exported directory:/etc/fstab# <file system> <dir> <type> <options> <dump> <pass> remote.server:/dir /media/nfs nfs defaults 0 0
- Mount the NFS share by running the following command:
sudo mount /media/nfs
Unmounting a File System
To detach a mounted file system, use the umount
command followed by either the directory where it has been mounted (mount point) or the device name:
umount DIRECTORYumount DEVICE_NAME
If the file system is in use the umount
command will fail to detach the file system. In those situations, you can use the fuser
command to find out which processes are accessing the file system:
fuser -m DIRECTORY
Once you determine the processes you can stop them and unmount the file system.
Lazy unmount
Use the -l
(--lazy
) option to unmount a busy file system as soon as it is not busy anymore.
umount -l DIRECTORY
Force unmount
Use the -f
(--force
) option to force an unmount. This option is usually used to unmount an unreachable NFS system.
umount -f DIRECTORY
Generally not a good idea to force unmount as it may corrupt the data on the file sys
Conclusion
By currentlyyou must have an honest understanding of the way to use the mount command to connect numerous file systems to your directory tree and detaching the mounts with the umount command.
To learn a lot of concerning the mount and umount command choices see their individual man pages.