The Wayback Machine - https://web.archive.org/web/20240921205353/https://www.geeksforgeeks.org/unmount-file-system-in-linux-using-the-umount-command/
Open In App

Unmount File System in Linux Using the umount Command

Last Updated : 05 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Unmounting a file system is a vital procedure for securely deleting storage devices or rendering system resources accessible. A vital instrument in this procedure is the “umount” command, which enables users to softly unmount mounted devices or partitions. Before beginning the unmounting process, this step ensures data integrity and protects any potential issues relating to current file operations.

What is the umount Command in Linux?

To unmount mounted file systems from their mount points, use the umount command. Before physically removing a storage device or making configuration changes, it is essential to unmount the file system. It is a vital instrument for securely disconnecting network shares or USB drives, among other types of storage, from the Linux file system. For the purpose of preventing data loss or corruption, the command makes sure each of the current file operations has concluded. This command is typically utilized by users to free up resources and allow the removal or upkeep of devices.

Syntax of the ‘umount’ command in Linux

umount [OPTIONS] [TARGET]
  • OPTIONS: Optional flags or parameters that modify the behavior of the umount command.
  • TARGET: The directory or device path indicating the location to be unmounted.

Commonly Used Options in the `umount` Command in Linux

Options

Description

-a

Unmount all filesystems listed in /etc/fstab.

-c

Report the number of mounts and unmounts since the last check.

-f

Force unmount, even if the device is busy.

-h, –help

Display help information.

-l

Lazy unmount. Detach the filesystem now and clean up later.

-n

Dry run. Show what would be done without actually unmounting.

-r , –read-only

Mount the filesystem read-only.

-t

Specify the filesystem type to unmount.

-no-canonicalize

Do not canonicalize paths (don’t resolve symlinks).

–fake

Simulate unmount. Useful -v for verbose simulation.

-v, –verbose

Increase verbosity, showing more details during unmounting.

The Linux File System

On a Linux operating system, files and directories are organized and handled via a hierarchical structure termed the Linux file system. It is important for understanding the Linux file system for system development, leadership, and regular usage. Here is an overview of the primary components and features:

Key Components of the Linux File System

  1. Root Directory (/)
    • In the Linux file system, the root directory is the most important directory. The root folder is home to all other files and folders as well.
  2. Standard Directories
    • /bin: Contains freely accessible binary executables which are essential to system use.
    • /boot: Contains the Linux kernel or boot loader files.
    • /dev: Provides device files, that stand in with components of the device.
    • /etc: Hosts scripts and files needed system configuration.
    • /home: Contain user home directories; here is a subdirectory for each user here.
    • /lib: Contains kernel modules and shared library files.
    • /media: Provides mount puts for USB ports and other removable media.
    • /mnt: Employed to mount file systems temporarily.
    • /opt: Employed to install software items which are optional.
    • /proc: A virtual file system that provides system and process information.
    • /root: The root user’s home directory.
    • /run: Temporarily saves files required for system boot.
    • /sbin: Includes system binaries, that are usually used by the root user.
    • /srv: Collects data needed the services the system provides.
    • /sys: A virtual file system that provides system and device information.
    • /tmp: Temporary files programmers and the operating system use.
    • /usr: Contains files and applications utilized by customers. includes subdirectories like /usr/share, /usr/lib, and /usr/bin.
    • /var: Maintains track of email, databases, logs, and other flexible data files.

File Types in the Linux File System

  • Regular Files: Ordinary files for data.
  • Directories: individual files that contain details about other files.
  • Symbolic Links: Links to additional categories or files.
  • Device Files: Represent hardware parts.
  • Sockets: Employed for interaction among operations.
  • Named Pipes: Another means to communicate among programs.

How to Unmount File System in Linux using umount Command?

Step 1: Creating a Mount Point

Creating a mount point in Linux is a straightforward process. A mount point is simply a directory where a file system can be attached (mounted) to access its contents. Here’s a step-by-step guide to creating a mount point and mounting a file system in Linux:

sudo mkdir /mnt/my_mount_point

Replace my_mount_point with a name of your choice. In below steps i have mentioned /data is the my mount point of the in linux system.

Step 2: Basic Usage of the umount Command

To unmount a file system, you need to provide the mount point or device as an argument to the umount command. For example, to unmount a device mounted at /mnt/data, the command would be:

mount | grep /mnt/data

To unmount the device, execute the below command.

sudo umount /mnt/data
Unmounting Device
Unmounting Device

Step 3: Unmounting Network File Systems

If you have a network file system (NFS) or other remote file systems mounted, the umount command works similarly. For instance, to unmount an NFS share mounted at /mnt/nfs, you can use:

mount | grep /mnt/nfs

To unmount the Network File System, execute the below command.

sudo umount /mnt/nfs
Unmounting Network File System
Unmounting Network File System

Step 4: Forcing Unmount with the -l Option

In some cases, a file system may be in use, and the umount command might result in an error. To force unmount, you can use the -l (lazy) option, which detaches the file system immediately, regardless of its usage. However, this should be done cautiously, as it may lead to data corruption if files are actively being accessed.

sudo umount -l /mnt/data
Forcing Unmount using -l Option
Forcing Unmount using -l Option

Step 5: Unmounting All File Systems

To unmount all currently mounted file systems, you can use the -a option with the umount command. This is particularly useful when preparing to shut down or reboot the system.

mount | grep /mnt/

To unmount all the file systems in one go, then execute the below umount command.

sudo umount -a
Unmounting All File Systems
Unmounting All File Systems

Interrogate your File System With df

Indeed, mounted file systems and their mount points can be seen with the df command, similar to in Ubuntu Linux. You can use the -x option to exclude particular file system types in order to prevent information overload, such as seeing pseudo-file systems constructed for various reasons.

You can use the -x option with df to exclude specific file systems, like tmpfs, or other specific types:

df -h -x tmpfs -x devtmpfs

Remounting a File System

Remounting a file system in Linux is useful when you need to change the mount options of an already mounted file system without unmounting and remounting it entirely. The mount command with the -o remount option allows you to do this. Here’s how you can remount a file system in Linux:

First, identify the file system you want to remount and check its current mount options. You can use the mount or df command for this.

mount | grep /mnt/my_mount_point

Use the mount command with the -o remount option to change the mount options. For example, to remount a file system as read-only, you can do:

sudo mount -o remount,ro /mnt/my_mount_point

Similarly, to remount it with read-write permissions:

sudo mount -o remount,rw /mnt/my_mount_point

Conclusion

For unmounting mounted filesystems or devices, the umount command in Linux is crucial. It ensures the endpoint of ongoing file operations and protects from data corruption by softly unmounting directories or devices. With parameters like -f for force unmounting and -l for lazy unmounting, the command’s flexibility allows users tailor the unmounting process to fit an array of scenarios. When using removable drives or network shares in a Linux environment, the umount command has to be used to guarantee system stability and data integrity.

Unmount File System in Linux Using umount Command – FAQs

How to list all currently mounted file systems in Linux?

You can use the `mount` command without any arguments to display a list of currently mounted file systems.

What command can be used to check if a specific file system is mounted in Linux?

The `findmnt /mnt/data` command can be used to search for a mounted file system based on its mount point.

How to forcefully unmount a busy file system using the umount command?

The -l (lazy) option can be used with umount to forcefully unmount a file system, even if it is busy. Example: sudo umount -l /mnt/data

How to unmount all file systems at once using the umount command?

The -a option with umount can be used to unmount all currently mounted file systems. Example: sudo umount -a

What command helps identify processes using a specific file system before unmounting?

The lsof command can be used to list processes that have files open on a specific file system. Example: lsof /mnt/data



Similar Reads

How to Mount and Unmount Drives on Linux
In the Linux operating system, everything is treated as a file. Every Linux administrator must know how to organize and access files better. In this article, we will learn about the Mount and Unmount commands. What are mounting and unmounting in Linux?Mounting and Unmounting are essential tasks in any Linux Operating System. It allows users to acce
4 min read
How to Mount File System in Linux | mount Command
All files in a Linux filesystem are arranged in form of a big tree rooted at '/'.These files can be spread out on various devices based on your partition table, initially your parent directory is mounted(i.e attached) to this tree at '/', others can be mounted manually using GUI interface(if available) or using mount command. mount command is used
6 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
Extract Emails From a Text File Using Grep Command in Linux
Let's consider we have a text file that contains lots of text and in that text file there are some email IDs present, and we have to find the all email IDs present in that text file. So what we can do? How can we find all email IDs present in that text file?. One way to find all email IDs manually, but this is a very time-consuming and boring proce
3 min read
How to Create a Text File Using the Command Line in Linux
The Linux command line is a powerful tool that allows you to manage your system with precision and speed. One of the most common tasks is creating a text file, which can be achieved using several commands and methods. Here we will learn some quick ways to create a text file from the Linux Command Line or Terminal. Table of Content Using the 'touch'
6 min read
Check If File Exist Inside Tar File Using Tar And Grep Command
Linux users are familiar with the popular command-line tool Tar (tape archive), which is used to archive directories and files into a single file called a "tarball." Occasionally, you might need to verify whether a certain file is present in a tar archive without extracting the full archive. This detailed article will show you how to effectively se
4 min read
Finding System Boot-up Performance Statistics in Linux Using systemd-analyze Command
If your Linux system is taking so much time to boot, and you want to know which process is taking so much time to boot then you are on the right page. We are going to see how to get a complete overview of system boot-up time and which service is taking more time to initialize. We are going to use the systemd-analyze command and subcommands of syste
2 min read
How to Save Output of Command in a File in Linux?
When we run a command on a terminal on Linux it generates some output of that command. Sometimes we need the output result of the commands. Today we are going to see how to save the output of the command. Using Redirections in Linux: We can use the redirections operators to save the output of commands into files. Redirection operators redirect the
3 min read
How to compress file in Linux | Compress Command
Linux, renowned for its powerful command-line utilities, provides users with various tools to streamline file management tasks. One such tool, the compress `command`, is specifically designed to compress individual files, reducing their size for efficient storage and transfer. In this comprehensive guide, we'll explore the ins and outs of the compr
5 min read
Use the Lines of a File as Arguments of a Linux Command
Handling multiple arguments for a command can be difficult, especially when there are a lot of parameters. One way to make this easier is to put the arguments in a text file and use each line of the file as an argument for the command. This can simplify the process and save time. For example, let's say you have a text file with a list of 100 client
6 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different places, `mv` is the go-to friend for the job. It's
7 min read
How to Display Path of an Executable File in Linux | Which Command
In Linux finding the exact path of an excutable file can be crucial for the system adminstration, scripting and as well for troubleshooting. The `which` command helps with providing a simple and effective way to locate the executable files within the directories that are listed in your system. In this article, we are going to discuss on what is whi
6 min read
How to Find a File in Linux | Find Command
Linux, renowned for its robust command-line interface, provides a suite of powerful tools for efficient file and directory management. Among these, the "find" command stands out as an indispensable asset, offering unparalleled versatility in searching for files based on diverse criteria. This article explores the prowess of the find command, sheddi
9 min read
How to Change File Ownership in Linux | chown Command
In the Linux operating system, file ownership is a crucial aspect of system security and user management. The `chown` command, short for "change owner," is a powerful tool that allows users to change the owner of files and directories. This command is particularly useful in scenarios where administrators need to grant or revoke access to specific r
9 min read
How to Create an Empty File in Linux | Touch Command
The touch command is a standard command used in the UNIX/Linux operating system which is used to create, change and modify the timestamps of a file. Basically, there are two different commands to create a file in the Linux system which are as follows: touch command: It is used to create a file without any content. The file created using the touch c
8 min read
How to Rename File in Linux | rename Command
Changing the names of files in Linux is something we often do, and the "rename" command is like a helpful friend for this job. This guide is like a journey to becoming really good at renaming files on Linux, showing you how handy and useful the "rename" command can be. Whether you're just starting out or you're already good at working with files, t
8 min read
file command in Linux with examples
The 'file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a human-readable format (e.g., ASCII text) or as a MIME type (e.g.,
3 min read
How to View the Content of File in Linux | cat Command
The cat command in Linux is more than just a simple tool; it's a versatile companion for various file-related operations, allowing users to view, concatenate, create, copy, merge, and manipulate file contents. Let's delve into the details of some frequently used cat commands, understanding each example along the way. Table of Content Basic Syntax o
7 min read
How to Manage System Services in Linux | systemctl Command
Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool for managing services. In this article, we will ex
8 min read
Reboot Linux System Command with Examples
Rebooting a Linux system is a fundamental administrative task necessary for applying updates, troubleshooting, or system maintenance. Various commands are available to reboot a Linux system, each with specific options and use cases. This guide explores essential reboot commands such as `reboot`, `shutdown`, and `init`, illustrating their usage with
11 min read
How to Monitor System Activity in Linux | top Command
top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it will open an interactive command mode where the t
10 min read
SAR command in Linux to monitor system performance
sar (System Activity Report) It can be used to monitor Linux system's resources like CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, file system and more. Linux system Monitoring and analyzing aids in understandi
6 min read
How to Fix - Cp: Cannot Create Regular File 'File': File Exists
In Linux, while performing copying operations using the cp command, the error "Cp: Cannot Create Regular File 'File': File Exists" may occur when attempting to copy a file to a destination where a file with the same name already exists. This error is a safeguard to prevent accidental overwriting of files and potential data loss. To resolve this iss
3 min read
Exodus - Copy Linux Binaries From One Linux System
Exodus is an easy-to-implement program, that is used for bundling dependencies, and also helps to effectively copy Linux ELF binaries from one to another machine securely, and this is very handy when you don't have root access, also if there are issues in the availability of the packages in the Linux distribution, Commonly Server oriented distribut
3 min read
proc file system in Linux
Proc file system (procfs) is a virtual file system created on the fly when the system boots and is dissolved at the time of system shutdown. It contains useful information about the processes that are currently running, it is regarded as a control and information center for the kernel. The proc file system also provides a communication medium betwe
4 min read
Linux File System
Operating systems, the software that powers your computer, rely on a crucial element known as the file system. Think of it as a virtual organizational tool that manages, stores, and retrieves your data efficiently. In the Linux world, a diverse range of file systems has emerged, each crafted to address specific needs and preferences. This article a
11 min read
Display File System Type in Linux
Understanding the file system type on a Linux system is crucial for efficient management and troubleshooting. Different file systems serve various purposes, and identifying them provides insights into storage devices and their capabilities. This article explores various methods to display the file system type in Linux, providing detailed explanatio
4 min read
File System Navigation Commands in Linux
Linux offers an alternative to the usual windows and icons. The terminal might seem different at first, relying on text commands instead of a mouse. But this simplicity holds immense power. In this article, you’ll be going through a demonstration of Navigation Commands in Linux which will help in quickly navigating in the Linux file system. Let’s g
7 min read
Scientific Calculator Using awk Command in Linux
The awk command in Linux allows the user to use the numeric functions, variables, logical operators and string functions. Basically, it is a utility that allows the user to write small and effective programs in the form the statements. It is mostly used in pattern scanning and processing. Here, we are using the awk command to perform the following
2 min read