| 1 |
.\" Copyright 1993, Rickard E. Faith <[email protected]> |
| 2 |
.\" Copyright 1994, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright 2002-2005, Michael Kerrisk <[email protected]> |
| 4 |
.\" Copyright, the authors of the Linux man-pages project |
| 5 |
.\" |
| 6 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 7 |
.\" |
| 8 |
.TH umount 2 2026-02-08 "Linux man-pages 6.18" |
| 9 |
.SH NAME |
| 10 |
umount, umount2 \- unmount filesystem |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B "#include <sys/mount.h>" |
| 17 |
.P |
| 18 |
.BI "int umount(const char *" target ); |
| 19 |
.BI "int umount2(const char *" target ", int " flags ); |
| 20 |
.fi |
| 21 |
.SH DESCRIPTION |
| 22 |
.BR umount () |
| 23 |
and |
| 24 |
.BR umount2 () |
| 25 |
remove the attachment of the (topmost) filesystem mounted on |
| 26 |
.IR target . |
| 27 |
.\" Note: the kernel naming differs from the glibc naming |
| 28 |
.\" umount2 is the glibc name for what the kernel now calls umount |
| 29 |
.\" and umount is the glibc name for oldumount |
| 30 |
.P |
| 31 |
Appropriate privilege (Linux: the |
| 32 |
.B CAP_SYS_ADMIN |
| 33 |
capability) is required to unmount filesystems. |
| 34 |
.P |
| 35 |
Linux 2.1.116 added the |
| 36 |
.BR umount2 () |
| 37 |
system call, which, like |
| 38 |
.BR umount (), |
| 39 |
unmounts a target, but allows additional |
| 40 |
.I flags |
| 41 |
controlling the behavior of the operation: |
| 42 |
.TP |
| 43 |
.BR MNT_FORCE " (since Linux 2.1.116)" |
| 44 |
Ask the filesystem to abort pending requests before attempting the |
| 45 |
unmount. |
| 46 |
This may allow the unmount to complete without waiting |
| 47 |
for an inaccessible server, but could cause data loss. |
| 48 |
If, after aborting requests, |
| 49 |
some processes still have active references to the filesystem, |
| 50 |
the unmount will still fail. |
| 51 |
As at Linux 4.12, |
| 52 |
.B MNT_FORCE |
| 53 |
is supported only on the following filesystems: |
| 54 |
9p (since Linux 2.6.16), |
| 55 |
ceph (since Linux 2.6.34), |
| 56 |
cifs (since Linux 2.6.12), |
| 57 |
fuse (since Linux 2.6.16), |
| 58 |
lustre (since Linux 3.11), |
| 59 |
and NFS (since Linux 2.1.116). |
| 60 |
.TP |
| 61 |
.BR MNT_DETACH " (since Linux 2.4.11)" |
| 62 |
Perform a lazy unmount: make the mount unavailable for new |
| 63 |
accesses, immediately disconnect the filesystem and all filesystems |
| 64 |
mounted below it from each other and from the mount table, and |
| 65 |
actually perform the unmount when the mount ceases to be busy. |
| 66 |
.TP |
| 67 |
.BR MNT_EXPIRE " (since Linux 2.6.8)" |
| 68 |
Mark the mount as expired. |
| 69 |
If a mount is not currently in use, then an initial call to |
| 70 |
.BR umount2 () |
| 71 |
with this flag fails with the error |
| 72 |
.BR EAGAIN , |
| 73 |
but marks the mount as expired. |
| 74 |
The mount remains expired as long as it isn't accessed |
| 75 |
by any process. |
| 76 |
A second |
| 77 |
.BR umount2 () |
| 78 |
call specifying |
| 79 |
.B MNT_EXPIRE |
| 80 |
unmounts an expired mount. |
| 81 |
This flag cannot be specified with either |
| 82 |
.B MNT_FORCE |
| 83 |
or |
| 84 |
.BR MNT_DETACH . |
| 85 |
.TP |
| 86 |
.BR UMOUNT_NOFOLLOW " (since Linux 2.6.34)" |
| 87 |
.\" Later added to Linux 2.6.33-stable |
| 88 |
Don't dereference |
| 89 |
.I target |
| 90 |
if it is a symbolic link. |
| 91 |
This flag allows security problems to be avoided in |
| 92 |
.RI set-user-ID- root |
| 93 |
programs that allow unprivileged users to unmount filesystems. |
| 94 |
.SH RETURN VALUE |
| 95 |
On success, zero is returned. |
| 96 |
On error, \-1 is returned, and |
| 97 |
.I errno |
| 98 |
is set to indicate the error. |
| 99 |
.SH ERRORS |
| 100 |
The error values given below result from filesystem type independent |
| 101 |
errors. |
| 102 |
Each filesystem type may have its own special errors and its |
| 103 |
own special behavior. |
| 104 |
See the Linux kernel source code for details. |
| 105 |
.TP |
| 106 |
.B EAGAIN |
| 107 |
A call to |
| 108 |
.BR umount2 () |
| 109 |
specifying |
| 110 |
.B MNT_EXPIRE |
| 111 |
successfully marked an unbusy filesystem as expired. |
| 112 |
.TP |
| 113 |
.B EBUSY |
| 114 |
.I target |
| 115 |
could not be unmounted because it is busy. |
| 116 |
.TP |
| 117 |
.B EFAULT |
| 118 |
.I target |
| 119 |
points outside the user address space. |
| 120 |
.TP |
| 121 |
.B EINVAL |
| 122 |
.I target |
| 123 |
is not a mount point. |
| 124 |
.TP |
| 125 |
.B EINVAL |
| 126 |
.I target |
| 127 |
is locked; |
| 128 |
see |
| 129 |
.BR mount_namespaces (7). |
| 130 |
.TP |
| 131 |
.B EINVAL |
| 132 |
.BR umount2 () |
| 133 |
was called with |
| 134 |
.B MNT_EXPIRE |
| 135 |
and either |
| 136 |
.B MNT_DETACH |
| 137 |
or |
| 138 |
.BR MNT_FORCE . |
| 139 |
.TP |
| 140 |
.BR EINVAL " (since Linux 2.6.34)" |
| 141 |
.BR umount2 () |
| 142 |
was called with an invalid flag value in |
| 143 |
.IR flags . |
| 144 |
.TP |
| 145 |
.B ENAMETOOLONG |
| 146 |
A pathname was longer than |
| 147 |
.BR MAXPATHLEN . |
| 148 |
.TP |
| 149 |
.B ENOENT |
| 150 |
A pathname was empty or had a nonexistent component. |
| 151 |
.TP |
| 152 |
.B ENOMEM |
| 153 |
The kernel could not allocate a free page to copy filenames or data into. |
| 154 |
.TP |
| 155 |
.B EPERM |
| 156 |
The caller does not have the required privileges. |
| 157 |
.SH STANDARDS |
| 158 |
Linux. |
| 159 |
.SH HISTORY |
| 160 |
.B MNT_DETACH |
| 161 |
and |
| 162 |
.B MNT_EXPIRE |
| 163 |
.\" http://sourceware.org/bugzilla/show_bug.cgi?id=10092 |
| 164 |
are available since glibc 2.11. |
| 165 |
.P |
| 166 |
The original |
| 167 |
.BR umount () |
| 168 |
function was called as |
| 169 |
.I umount(device) |
| 170 |
and would return |
| 171 |
.B ENOTBLK |
| 172 |
when called with something other than a block device. |
| 173 |
In Linux 0.98p4, a call |
| 174 |
.I umount(dir) |
| 175 |
was added, in order to |
| 176 |
support anonymous devices. |
| 177 |
In Linux 2.3.99-pre7, the call |
| 178 |
.I umount(device) |
| 179 |
was removed, |
| 180 |
leaving only |
| 181 |
.I umount(dir) |
| 182 |
(since now devices can be mounted |
| 183 |
in more than one place, so specifying the device does not suffice). |
| 184 |
.SH NOTES |
| 185 |
.SS umount() and shared mounts |
| 186 |
Shared mounts cause any mount activity on a mount, including |
| 187 |
.BR umount () |
| 188 |
operations, to be forwarded to every shared mount in the |
| 189 |
peer group and every slave mount of that peer group. |
| 190 |
This means that |
| 191 |
.BR umount () |
| 192 |
of any peer in a set of shared mounts will cause all of its |
| 193 |
peers to be unmounted and all of their slaves to be unmounted as well. |
| 194 |
.P |
| 195 |
This propagation of unmount activity can be particularly surprising |
| 196 |
on systems where every mount is shared by default. |
| 197 |
On such systems, |
| 198 |
recursively bind mounting the root directory of the filesystem |
| 199 |
onto a subdirectory and then later unmounting that subdirectory with |
| 200 |
.B MNT_DETACH |
| 201 |
will cause every mount in the mount namespace to be lazily unmounted. |
| 202 |
.P |
| 203 |
To ensure |
| 204 |
.BR umount () |
| 205 |
does not propagate in this fashion, |
| 206 |
the mount may be remounted using a |
| 207 |
.BR mount (2) |
| 208 |
call with a |
| 209 |
.I mount_flags |
| 210 |
argument that includes both |
| 211 |
.B MS_REC |
| 212 |
and |
| 213 |
.B MS_PRIVATE |
| 214 |
prior to |
| 215 |
.BR umount () |
| 216 |
being called. |
| 217 |
.SH SEE ALSO |
| 218 |
.BR mount (2), |
| 219 |
.BR mount_namespaces (7), |
| 220 |
.BR path_resolution (7), |
| 221 |
.BR mount (8), |
| 222 |
.BR umount (8) |