mount and umount
Swap Management covered how to prepare and enable virtual memory — like an ordinary filesystem, it first requires preparing the device (mkswap or mkfs), then "attaching" it to the system. For filesystems, this attachment step happens through the mount command: a newly created or existing filesystem's device stays inaccessible through an ordinary path until it's attached to a specific directory (a mount point). This article covers the mount and umount commands, their main options, and common problems. The next article, fstab, builds on this by making mounts persist across reboots.
What You Will Learn
By the end of this article you will be able to:
- use the basic syntax of
mountandumount; - explain what a bind mount is and when it's needed;
- change a mounted filesystem's parameters with
mount -o remountwithout unmounting it; - diagnose a "device is busy" error with
lsof/fuserand know whenumount -l(lazy umount) is appropriate; - have a general understanding of the mount namespace concept;
- distinguish the purpose of virtual filesystems like
proc,sysfs, andtmpfs.
mount: Basic Syntax
The simplest form:
Here, /dev/sdb1 is the device (or partition) being mounted, and /mnt/data is the mount point — the directory under which the filesystem's contents will appear. The mount point must already exist as an empty directory:
mount with no arguments lists every currently mounted filesystem:
Info
mount output shows not just physical disks but also virtual filesystems like proc, sysfs, and tmpfs (covered below). For a view limited to real storage devices, df -hT is more convenient — it also shows disk size and free space.
Explicitly specifying the filesystem type when needed (mount usually detects it automatically):
Useful general mount options (combined with -o, comma-separated):
| Option | Purpose |
|---|---|
ro |
mount read-only |
rw |
read/write (the default) |
noexec |
disallow executing files on this filesystem |
nosuid |
ignore setuid/setgid bits |
Bind Mount: Showing One Directory at a Second Location
A bind mount doesn't mount a separate device — it "moves" an existing directory within a filesystem to another location, really pointing the second location at the first. No new disk or partition is needed:
From then on, any change inside /var/www/html also shows up in /srv/www — they're really one place, viewed through two paths.
Bind mounts are commonly used for:
- exposing a single directory from the host system into a container or
chrootenvironment; - adapting a directory to a path another program expects, without physically moving it;
- opening a specific directory read-only through a read-only bind mount:
Info
--bind mounts a directory, but only at the top level — it doesn't reflect other mount points nested inside it (for example, if a separate filesystem is mounted under /srv/www). If those need to be reflected too, --rbind is used instead.
mount -o remount: Changing Options Without Unmounting
Some parameters of an already-mounted filesystem (for example, ro to rw) can be changed without unmounting and remounting:
This is useful, for example, when a system boots read-only (the root filesystem mounted with ro for maintenance) and needs to be opened for writing:
remount works even while the filesystem is busy, since it doesn't replace the mount point — it only updates the flags on the existing mount.
umount: Detaching a Filesystem
or by device path:
Both produce the same result — the important thing is that the filesystem isn't in use by anyone at that moment.
The "device is busy" Error and Diagnosing It
If the filesystem has an open file, is the current working directory (cd) for some shell, or has a running process on it, umount refuses:
There are two main tools for finding out which process is holding the filesystem busy.
lsof — shows open files under a mount point:
fuser — shows the processes using a mount point in a shorter format:
The result shows the matching process PID and name. Stopping that process properly (for example, closing the service with systemctl stop) is the safest fix. fuser can also forcibly terminate the processes:
Warning
fuser -k kills every process using the filesystem with no warning. This can cause unsaved data loss — first identify which processes they are with lsof/fuser -v, and try to stop them gracefully.
Lazy Umount (umount -l)
Sometimes a process can't be identified immediately, or stopping it is risky, but the filesystem still needs to be detached from its mount point quickly. umount -l (lazy) removes the mount point from the filesystem hierarchy immediately, but the actual detach happens only once the processes holding the device finish:
Warning
umount -l "hides" the problem rather than solving it: the filesystem may still be busy in the background, so trying to mount it again, or physically detaching the device (e.g. pulling out a USB disk), is risky. Use it only as a temporary measure, not as a permanent fix.
A Brief Word on Mount Namespaces
On a modern Linux kernel, mount information isn't global — each process can have its own mount namespace. This means a change made with mount/umount in one terminal usually applies to the whole system (or at least that user's session) unless a special namespace is in use, but containers (Docker, LXC) and tools like unshare/chroot can each have their own, isolated mount view.
Practical consequence: mount/df output inside a container can differ from the host system — this isn't a bug, it's the natural result of mount namespace isolation. Studying this in depth belongs to a containerization module (Docker, for example); it's mentioned here only to explain why mount results can sometimes differ from what you'd expect.
Virtual Filesystems: proc, sysfs, tmpfs
Many lines in mount output belong not to a physical disk, but to virtual filesystems created by the kernel. They don't occupy disk space — instead they present kernel data in file form:
proc(/proc) — presents information about running processes and kernel parameters as files. For example,/proc/cpuinfo,/proc/meminfo.sysfs(/sys) — structured information about devices, drivers, and kernel subsystems; device parameters can often be read from here, and (carefully) written to.tmpfs— a temporary filesystem living in RAM./tmpor/runare often mounted astmpfs— their contents disappear on reboot, but they're much faster than disk.
These filesystems normally don't need to be mounted/unmounted manually — they're prepared automatically at boot. Knowing about them matters because not every line that appears in mount/df output means "disk."
Practical Scenario: Safely Unmounting Before Replacing a Disk
Problem. An external USB disk mounted at /mnt/backup is no longer needed and needs to be physically unplugged, but umount fails with "target is busy."
Inspection.
This reveals an rsync process is still working on the filesystem — likely a backup task running in the background.
Action. Once the process is identified, rather than killing it forcibly, waiting for it to finish or stopping it properly makes more sense:
# watch the process's state
ps -p 2214 -o pid,etime,cmd
# if stopping the process is safe (e.g. it's a script that can be re-run)
sudo kill 2214
sleep 2
sudo umount /mnt/backup
If the process can't be stopped or there's no time, a lazy umount is used as an alternative, and the disk is detached physically later:
Result.
If the command returns nothing, the mount point has been removed from the hierarchy.
Conclusion. A "device is busy" error almost always means a process is using the filesystem. Proper diagnosis (lsof/fuser) solves the problem without hiding it; umount -l should only be used as a last resort when a process genuinely can't be stopped safely.
Common Mistakes
Using a Non-Empty Directory as a Mount Point
If the chosen mount point directory already contains files, they temporarily "disappear" once mounted (they're still there underneath the filesystem, but hidden because a new filesystem is now mounted on top). This isn't data loss, but it causes confusion — an empty directory should be used as a mount point.
Passing the Wrong Path to umount
umount /mnt/data/subdir only works if subdir is separately mounted. To detach the whole /mnt/data filesystem, its actual mount point or device name must be given.
Forgetting a Manually Mounted Filesystem Disappears After a Reboot
A change made with the mount command is temporary — it isn't preserved across a reboot. A permanent mount requires an entry in /etc/fstab.
Exercises
- In a disposable VM, create an empty partition or loop device (
dd+losetup, or an extra virtual disk), format it withmkfs.ext4, and mount it at/mnt/test. - Link two directories with
--bindand confirm that writing a file to one shows up in the other. cdinto a mounted filesystem from one terminal and tryumountfrom another — get the error, then find the cause withfuser -vm.- Switch a filesystem to read-only with
mount -o remount,ro, try writing to it and see the error, then revert withremount,rw.
Verification criterion: given a "device is busy" error, you should be able to state the exact command that identifies the responsible process before attempting to force anything.
Summary
mount attaches a device (or, via --bind, an existing directory) to a specific point in the filesystem hierarchy, and umount detaches it. -o remount safely changes parameters even on a busy filesystem, while lsof/fuser pinpoint the cause of a "device is busy" error. All of these commands are temporary — nothing survives a reboot. The next article, fstab, solves exactly this problem, introducing a permanent file that applies the mount configuration automatically at every boot.