Table of Contents
Introduction
Mounting and unmounting are how Linux connects or disconnects filesystems to and from the single unified directory tree. At this stage you already know what devices and partitions are and have a basic idea of filesystems. This chapter focuses only on the practical and conceptual aspects of attaching those filesystems so that users and applications can access them, and then detaching them safely.
The idea of mounting
Linux presents storage as part of one large tree that starts at /. A filesystem on a partition, disk, network share, or virtual device does not appear automatically inside this tree. Instead, it must be attached to a directory, called a mount point, by mounting it.
After a filesystem is mounted, the contents of that filesystem become visible at the chosen directory. Before the mount, the directory is just an empty directory or contains whatever was there previously. After the mount, any previous contents are hidden while the filesystem is mounted.
Unmounting reverses this. When a filesystem is unmounted from a mount point, its content is no longer visible at that directory, and the directory reverts to its previous state.
Important rule: Do not remove power, unplug a disk, or detach network storage before unmounting the filesystem. This reduces the risk of data loss and corruption.
Basic manual mounting with `mount`
The main tool to attach filesystems is the mount command. It has many options, but there are two key arguments you always provide: the device and the mount point.
A minimal example looks like this:
sudo mount /dev/sdb1 /mnt
In this example /dev/sdb1 is the device that holds the filesystem, and /mnt is an existing directory that will serve as the mount point. After this command, the top-level directories and files stored in the filesystem on /dev/sdb1 appear inside /mnt.
mount must usually run with administrative privileges, which is why sudo is used. Without it, normal users are generally not allowed to mount arbitrary filesystems.
When calling mount without arguments, it shows a list of currently mounted filesystems. This is a quick way to verify that your mount operation succeeded and to see where different devices are attached.
Choosing and preparing mount points
A mount point is any directory that already exists. If the directory does not exist, you must create it in advance. For example:
sudo mkdir /data
sudo mount /dev/sdb1 /data
Some directories are conventionally used as temporary or generic mount points, such as /mnt or /media. System packages or desktop environments might also create subdirectories inside them.
Mount points can be created almost anywhere, but there are practical considerations. Placing them under locations like /data, /srv, or /media helps keep the filesystem layout understandable. Applications that expect data in particular directories may rely on consistent mount points.
Remember that when you mount a filesystem on a nonempty directory, the original contents of that directory become hidden while the mount is active. Those contents are not deleted, but they are not visible or accessible until the filesystem is unmounted again.
Unmounting with `umount`
To detach a filesystem you use umount with either the device or the mount point. For example:
sudo umount /mntor:
sudo umount /dev/sdb1
Both forms unmount the filesystem as long as nothing is actively using it. After this operation, the directory /mnt is no longer backed by that filesystem.
Unmounting is especially important before removing a USB stick, detaching an external disk, or shutting down network storage. Filesystem writes are often buffered in memory and may not yet be fully written to the device. Unmounting forces the system to complete those operations and ensures consistency.
Important rule: If umount reports that a target is busy, do not ignore it. Find and stop the processes using that filesystem, then try unmounting again.
Handling “device is busy” situations
When a filesystem is in use, umount may fail with an error message similar to “target is busy” or “device is busy.” Common reasons include having a terminal with its current working directory inside the mounted filesystem, open files from editors or other applications, or running services whose data directory is located there.
A typical workflow is:
- Close terminals and applications that are using the mount point.
- Make sure your current directory is not inside the mount point. Change to a safe directory such as your home directory.
- Stop any services that may be using that filesystem.
If the problem persists, tools that list open files or mounted usage can help identify which processes are still holding references. Once those processes are closed or moved, unmounting usually succeeds.
Filesystem types and the `-t` option
Many filesystems can be detected automatically by the mount command. In some situations you need to specify the filesystem type explicitly with the -t option. For example:
sudo mount -t ext4 /dev/sdb1 /data
The parameter after -t tells mount how to interpret the data on the device. For local filesystems such as ext4 or xfs, detection is often automatic. For network filesystems, or less common formats, the -t argument is usually required.
Mounting an incorrect type does not succeed, so if you see errors about unknown or wrong filesystem types, check that you are using the correct one and that the correct support is installed on your system.
Mount options with `-o`
Mount operations often need additional options that control behavior, performance, or access permissions. These are provided through the -o flag, followed by a comma separated list of options. For example:
sudo mount -o ro /dev/sdb1 /mnt
In this case, ro means read only. Once mounted this way, the filesystem cannot be modified until it is remounted with write access. Other common options include user access control, permission behavior, or cache settings.
Many options are filesystem specific or scenario specific, such as network latency settings for remote mounts. Always check documentation for a particular filesystem or service before using more advanced options.
Important rule: Use read only mounts when inspecting untrusted or potentially damaged filesystems. This minimizes the risk of further damage.
Temporary vs persistent mounts
When you run mount manually from the command line, the resulting mount is typically temporary. It lasts until you unmount it manually or until the system reboots. After a restart, the system does not automatically remember these temporary mounts.
To have filesystems mounted automatically at boot, Linux uses a configuration file that lists persistent mount rules. This chapter does not cover editing that file in detail, but it is important to understand the difference. Temporary mounts are useful for testing, one time access, and removable media. Persistent mounts are used for permanent disks and important data partitions.
When planning a system, it is common to experiment with a device using manual mounts first. Once you are satisfied with the configuration and options, you can convert that setup into a persistent configuration so that the filesystem is ready each time the machine starts.
Mounting removable media
Desktop Linux environments usually offer graphical tools that automatically mount removable devices such as USB drives when they are plugged in. These user friendly layers run mount commands on your behalf, choose mount points under directories such as /media, and show the device in file managers.
From the command line, the procedure is still the same. Identify the device, choose a mount point, and call mount. Once you finish using the device, you either use a graphical “eject” function offered by the desktop environment or you call umount manually before unplugging the device.
With removable media, unmounting is particularly important. Just because data appears in a file manager does not guarantee that it is fully written to the hardware. Unmounting reduces the risk that you remove the device while writes are still pending in memory.
Network filesystems
Storage does not always come from local disks. Network filesystems make remote directories available as if they were local, by mounting them on a mount point on your machine. The syntax for mounting these often includes a hostname and path instead of a local device.
Conceptually the process is the same: a remote filesystem is attached to a directory, and you can work with it using regular tools. The main differences involve additional mount options for authentication, performance, and network behavior, and the need for corresponding client support on your system.
Just like local filesystems, network filesystems should be unmounted cleanly, especially when you expect the network connection to become unavailable, such as before shutting down a VPN or disconnecting from a remote site.
Inspecting current mounts
To understand which filesystems are currently in use and where they are attached, you can inspect the list of mounts. The simplest way is to run mount with no arguments, which prints every mounted filesystem and its mount point.
This output can be verbose, because the system mounts many internal and virtual filesystems. It is primarily useful for troubleshooting and for confirming that a specific filesystem is mounted as expected. It also helps you match devices with their mount points when planning changes or performing maintenance.
Some systems also provide more specialized views, for example through files in /proc that contain mount information. These views are often used internally by tools that manage mounts for you.
Summary
Mounting and unmounting are the mechanisms through which Linux connects and disconnects filesystems to the directory tree. You select a device and a mount point, use mount to attach the filesystem, then use umount to detach it safely. Understanding mount points, common options, and the importance of clean unmounts is essential for everyday administration of local disks, removable media, and network storage.