Linux Unit 3.2
Linux Unit 3.2
Contents
How to List Mounted File Systems
Mounting a File System
o Mounting a File System using /etc/fstab
o Mounting USB Drive
o Mounting ISO Files
o Mounting NFS
Unmounting a File System
o Lazy unmount
On Linux and UNIX operating systems, you can use the mount command to attach (mount)
file systems and removable devices such as USB flash drives at a particular mount point in
the directory tree.
The umount command detaches (unmounts) the mounted file system from the directory tree.
In this tutorial, we will go over the basics of attaching and detaching various file systems
using the mount and umount commands.
mount
By default, the output will include all file systems including the virtual ones such as cgroup,
sysfs, and others. Each line contains information about the device name, the directory to
which the device is mounted to, the type of the filesystem and the mount options in the
following form:
For example, to print only the ext4 partitions you would use:
mount -t ext4
Once the file system is attached, the mount point becomes the root directory of the mounted
file system.
For example, to mount the /dev/sdb1 file system to the /mnt/media directory you would
use:
Usually when mounting a device with a common file system such as ext4 or xfs the mount
command will auto-detect the file system type. However, some file systems are not
recognized and need to be explicitly specified.
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.
When providing just one parameter (either directory or device) to the mount command, it will
read the content of the /etc/fstab configuration file to check whether the specified file
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.
/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:
On most modern Linux distribution like Ubuntu, USB drives will auto mount when you insert
it, but sometimes you may need to manually mount the drive.
Assuming that the USB drive uses the /dev/sdd1 device you can mount it to /media/usb
directory by typing:
To find the device and filesystem type, you can use any of the following commands:
To mount exFAT formatted USB drives, install the free FUSE exFAT module and tools .
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.
1. Start by creating the mount point, it can be any location you want:
Mount the ISO file to the mount point by typing the following command:
2. 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.
Use the steps below to mount a remote NFS directory on your system:
1. Create a directory to serve as the mount point for the remote filesystem:
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 :
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
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 system.
Conclusion
By now you should have a good understanding of how to use the mount command to attach
various file systems to your directory tree and detaching the mounts with the umount
command.