Table of Contents
In this article, I will take you through 18 Popular umount and mount command examples in Linux. If you want to use any device on Linux then first you need to create a partition on that device using fdisk and then you create a filesystem over that device partition using mkfs or other similar tools and then mount it to a directory using mount command to use that device.
Then if you want to remove that device from your Linux System, you need to use umount command to unmount that partition first and then physically remove the device. We will go through the examples of mount and umount command in below sections to understand its usages with various devices and its partitions.
umount/mount command examples in Linux(How to mount and unmount Partition )
Also Read: 10 Useful nfsstat and nfsiostat examples to troubleshoot NFS Performance in Linux
Example 1: How to Mount a Partition or Filesystem in Linux
If you want to mount a device partition in Linux then you need to use mount command as shown below. Here we are trying to mount /dev/sdc1
device partition on /u01
using mount /dev/sdc1 /u01
command. If you run df -h
command then you will see device partition of size 7.8G
is now mounted on /u01
. It is worth noting here that this partition mount is a temporary mounting. If you want to permanently mount the partition then you need to provide an entry in /etc/fstab
file.
[root@localhost ~]# mount /dev/sdc1 /u01 [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.4G 0 1.4G 0% /dev/shm tmpfs 1.4G 8.6M 1.4G 1% /run tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 11G 27G 28% / /dev/sda1 1014M 282M 733M 28% /boot tmpfs 280M 0 280M 0% /run/user/0 /dev/sdc1 7.8G 36M 7.3G 1% /u01
NOTE:
root
user to run all the below commands.You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.Example 2: How to unmount a Partition or Filesystem in Linux
If you want to unmount a partition then you need to use umount command as shown below. Here we are unmounting /dev/sdc1
device partition which was mounted on /u01
using umount /u01
command. You can also use umount /dev/sdc1
command to unmount the partition. You can use it either way.
[root@localhost ~]# umount /u01/ [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.4G 0 1.4G 0% /dev/shm tmpfs 1.4G 8.6M 1.4G 1% /run tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 11G 27G 28% / /dev/sda1 1014M 282M 733M 28% /boot tmpfs 280M 0 280M 0% /run/user/0
Example 3: How to View All the mount information in Linux
If you want to view all the mounted partition in Linux then you need to use mount
command as shown below. This command will provide important information like mount point, type of mounted filesystem, assigned permission etc.
[root@localhost ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=1420756k,nr_inodes=355189,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
Example 4: How to Check mount command version
If you want to view the mount command version then you need to use mount -V
command as shown below. As you can see from below output, current mount command version is 2.23.2
.
[root@localhost ~]# mount -V mount from util-linux 2.23.2 (libmount 2.23.0: selinux, debug, assert)
-V : Output version. Check mount command Man Page for more info.
Example 5: How to Check umount command version
If you want to view the umount command version then you need to use umount -V
command as shown below. As you can see from below output, current umount command version is 2.23.2
.
[root@localhost ~]# umount -V umount from util-linux 2.23.2 (libmount 2.23.0: selinux, debug, assert)
-V : Print version and exit. Check umount command Man Page for more info.
Example 6: How to mount all the filesystem of /etc/fstab
If you want to mount all the filesystem of /etc/fstab
then you need to use mount -a
command as shown below. Usually when you perform any change in /etc/fstab
file and you do not want to reboot your system to reflect those changes then you can use mount -a
command to refresh those changes.
[root@localhost ~]# mount -a [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Apr 23 12:36:31 2020 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=1e70f026-ce6f-4938-a74c-ec9c5f6ce74a /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 #/dev/sdb1 swap swap defaults 0 0 #/root/testswap swap swap defaults 0 0 /dev/vol_grp/log_vol swap swap defaults 0 0
-a : Mount all filesystems (of the given types) mentioned in fstab. Check mount command Man Page for more info.
Example 7: How to Remount a mounted Filesystem in Linux
If you want to remount a device partition then you need to use -o
option with mount command as shown below. when you want to remount the filesystem with read/write access which was previously mounted with read access then you have to use the remount option. Here we are remounting /dev/sdc1
partition with read
,write
access using mount -o remount,rw /dev/sdc1
command.
[root@localhost ~]# mount -o remount,rw /dev/sdc1
-o : Options are specified with a -o flag followed by a comma separated string of options. Check mount command Man Page for more info.
Example 8: How to Mount an ISO Image in Linux
If you want to mount an ISO image in Linux then you need to use -o loop
option with mount command as shown below. Here we are mounting a CentOS ISO image to /mnt/iso
using mount -o loop CentOS.ISO /mnt/iso
command.
[root@localhost ~]# mount -o loop CentOS.ISO /mnt/iso mount: /dev/loop0 is write-protected, mounting read-only
Example 9: How to Bind mount Point to a New Directory in Linux
If you run df -h
command then you can see /dev/sdc1
is currently mounted on /u01
directory.
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.4G 0 1.4G 0% /dev/shm tmpfs 1.4G 8.6M 1.4G 1% /run tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 11G 27G 28% / /dev/sda1 1014M 282M 733M 28% /boot tmpfs 280M 0 280M 0% /run/user/0 /dev/sdc1 7.8G 36M 7.3G 1% /u01
Now to bind the mount point /u01
to another directory /mnt/iso
you need to use mount -B /mnt/iso /u01
command as shown below.
[root@localhost ~]# mount -B /mnt/iso /u01
-B : Remount a subtree somewhere else (so that its contents are available in both places). Check mount command Man Page for more info.
If you again check the binding by using lsblk
command then you can see /dev/sdc1
is now binded to /mnt/iso
directory as shown below.
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─centos-root 253:0 0 37G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk └─sdb1 8:17 0 8G 0 part └─vol_grp-log_vol 253:2 0 200M 0 lvm [SWAP] sdc 8:32 0 8G 0 disk └─sdc1 8:33 0 8G 0 part /mnt/iso sr0 11:0 1 1024M 0 rom
Example 10: How to Perform Lazy Unmount in Linux
As you can see from below lsblk
output /dev/sdc1
is currently mounted to /mnt/iso
directory.
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─centos-root 253:0 0 37G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk └─sdb1 8:17 0 8G 0 part └─vol_grp-log_vol 253:2 0 200M 0 lvm [SWAP] sdc 8:32 0 8G 0 disk └─sdc1 8:33 0 8G 0 part /mnt/iso sr0 11:0 1 1024M 0 rom
If you want to unmount a partition when disk operations are completed on that then you need to use -l
option with umount command. Here to perform the Lazy unmount of partition /dev/sdc1
you need to use umount -l /dev/sdc1
command as shown below.
[root@localhost ~]# umount -l /dev/sdc1
-l : Lazy unmount. Check umount command Man Page for more info.
If you again check the lsblk
command output then you see it is now mounted to /u01
. So previously the partition which was mounted to both /mnt/iso
and /u01
is now only mounted to /u01
as we have already done the lazy unmount of /dev/sdc1
partition from /mnt/iso
.
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─centos-root 253:0 0 37G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk └─sdb1 8:17 0 8G 0 part └─vol_grp-log_vol 253:2 0 200M 0 lvm [SWAP] sdc 8:32 0 8G 0 disk └─sdc1 8:33 0 8G 0 part /u01 sr0 11:0 1 1024M 0 rom
Example 11: How to Unmount all the Filesystem from /etc/fstab in Linux
If you want to unmount all the filesystem from /etc/mtab
then you need to use umount -a
command as shown below.
[root@localhost ~]# umount -a umount: /: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) umount: /sys/fs/cgroup/systemd: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) umount: /sys/fs/cgroup: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) umount: /run: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) umount: /dev: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
-a : All of the file systems described in /etc/mtab are unmounted. Check umount command Man Page for more info.
Example 12: How to Check all the mounting information of a Specific Filesystem
If you want to check all the mounting information of a Specific Filesystem then you need to use -t
option with mount command as shown below. In this example, we are trying to check all the mounted temporary filesystem information using mount -t tmpfs
command.
[root@localhost ~]# mount -t tmpfs tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=286516k,mode=700)
-t : The argument following the -t is used to indicate the filesystem type. Check mount command Man Page for more info.
Example 13: How to Forcefully unmount a Partition Using umount command
If some device is busy or if you are unable to unmount the partition due to some other reasons like partition is current not reachable then you can try to forcefully unmount the partition using umount -f /dev/sdc1
command as shown below. This command will remove all the references of partition from the System.
[root@localhost ~]# umount -f /dev/sdc1
-f : Force unmount (in case of an unreachable NFS system). Check umount command Man Page for more info.
Example 14: How to mount an NFS Partition in Linux
If you want to mount NFS Partition then you need to specify the partition type as nfs with -t
option as shown below. Here we are mounting NFS partition /mnt/nfs
which is getting exported from NFS Server to our local client system on /nfsclient
using mount -t nfs 192.168.0.108:/mnt/nfs /nfsclient
command.
[root@localhost ~]# mount -t nfs 192.168.0.108:/mnt/nfs /nfsclient [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.4G 0 1.4G 0% /dev/shm tmpfs 1.4G 8.6M 1.4G 1% /run tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 11G 27G 28% / /dev/sda1 1014M 282M 733M 28% /boot tmpfs 280M 0 280M 0% /run/user/0 192.168.0.108:/mnt/nfs 20G 11G 7.8G 58% /nfsclient
Example 15: How to check all the other options of mount command
If you want to check all the other options available for mount command then you need to use mount -h
command as shown below.
[root@localhost ~]# mount -h Usage: mount [-lhV] mount -a [options] mount [options] [--source] <source> | [--target] <directory> mount [options] <source> <directory> mount <operation> <mountpoint> [<target>] Options: -a, --all mount all filesystems mentioned in fstab -c, --no-canonicalize don't canonicalize paths -f, --fake dry run; skip the mount(2) syscall -F, --fork fork off for each device (use with -a) -T, --fstab <path> alternative file to /etc/fstab -h, --help display this help text and exit -i, --internal-only don't call the mount.<type> helpers -l, --show-labels lists all mounts with LABELs -n, --no-mtab don't write to /etc/mtab -o, --options <list> comma-separated list of mount options -O, --test-opts <list> limit the set of filesystems (use with -a) -r, --read-only mount the filesystem read-only (same as -o ro) -t, --types <list> limit the set of filesystem types --source <src> explicitly specifies source (path, label, uuid) --target <target> explicitly specifies mountpoint -v, --verbose say what is being done -V, --version display version information and exit -w, --rw, --read-write mount the filesystem read-write (default)
Example 16: How to check all the other options of umount command
If you want to check all the other options available for umount command then you need to use umount -h
command as shown below.
[root@localhost ~]# umount -h Usage: umount [-hV] umount -a [options] umount [options] <source> | <directory> Options: -a, --all unmount all filesystems -A, --all-targets unmount all mountpoins for the given device in the current namespace -c, --no-canonicalize don't canonicalize paths -d, --detach-loop if mounted loop device, also free this loop device --fake dry run; skip the umount(2) syscall -f, --force force unmount (in case of an unreachable NFS system
Example 17: How to check Man page of mount command
If you want to check Man page of mount command then you need to use man mount
command as shown below.
[root@localhost ~]# man mount MOUNT(8) System Administration MOUNT(8) NAME mount - mount a filesystem SYNOPSIS mount [-lhV] mount -a [-fFnrsvw] [-t vfstype] [-O optlist] mount [-fnrsvw] [-o option[,option]...] device|dir mount [-fnrsvw] [-t vfstype] [-o options] device dir DESCRIPTION All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again. The standard form of the mount command, is mount -t type device dir This tells the kernel to attach the filesystem found on device (which is of type type) at the directory dir. The previous contents (if any) and owner and mode of dir become invisible, and as long as this filesystem remains mounted, the pathname dir refers to the root of the filesystem on device. If only directory or device is given, for example: mount /dir then mount looks for a mountpoint and if not found then for a device in the /etc/fstab file. It's possible to use --target or --source options to avoid ambivalent interpretation of the given argument. For example
Example 18: How to check Man page of umount command
If you want to check Man Page of umount command then you need to use man umount
command as shown below.
[root@localhost ~]# man umount UMOUNT(8) System Administration UMOUNT(8) NAME umount - unmount file systems SYNOPSIS umount [-hV] umount -a [-dflnrv] [-t vfstype] [-O options] umount [-dflnrv] {dir|device}... DESCRIPTION The umount command detaches the file system(s) mentioned from the file hierarchy. A file system is specified by giving the directory where it has been mounted. Giving the special device on which the file system lives may also work, but is obsolete, mainly because it will fail in case this device was mounted on more than one directory. Note that a file system cannot be unmounted when it is 'busy' - for example, when there are open files on it, or when some process has its working directory there, or when a swap file on it is in use. The offending process could even be umount itself - it opens libc, and libc in its turn may open for example locale files. A lazy unmount avoids this problem, but it may introduce another issues. See --lazy description bellow. OPTIONS -a, --all All of the file systems described in /etc/mtab are unmounted. (With umount version 2.7 and later: the proc filesystem is not unmounted.) -A, --all-targets Unmount all mountpoints in the current namespace for the specified filesystem. The filesystem could be specified by one of the mountpoints or device name (or UUID, etc.). This option could be used together with --recursive then all nested mounts within the filesystem are recursively unmounted. -c, --no-canonicalize Do not canonicalize paths. For more details about this option see the mount(8) man page.
Popular Recommendations:-
10 Popular nfsstat command examples in Linux for Professionals (cheatsheet)
Understanding Kafka Console Producer and Consumer in 10 Easy Steps
Popular Apache Kafka Architecture Explained Using 4 Basic Components
17 Useful Apache Kafka Examples on Linux (RedHat/CentOS 7/8)
How to Install Apache Kafka on Ubuntu 18.04
How to Install Apache Zookeeper on Ubuntu 18.04
Tutorial: How to do Elasticsearch Backup and Restore (v7.5)
Top 20 Elasticsearch API Query for Developers Part – 1
How to Mount and Unmount Partition in Linux
52 Useful cut command in Linux/Unix with Examples for Beginners