Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / umount.2
blobe9059c405c5d8a12eb5716100c2aee4eee3133c4
1 .\" Copyright (C) 1993 Rickard E. Faith <faith@cs.unc.edu>
2 .\" and Copyright (C) 1994 Andries E. Brouwer <aeb@cwi.nl>
3 .\" and Copyright (C) 2002, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" 2008-10-06, mtk: Created this as a new page by splitting
28 .\"     umount/umount2 material out of mount.2
29 .\"
30 .TH UMOUNT 2 2021-08-27 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 umount, umount2 \- unmount filesystem
33 .SH SYNOPSIS
34 .nf
35 .B "#include <sys/mount.h>"
36 .PP
37 .BI "int umount(const char *" target );
38 .BI "int umount2(const char *" target ", int " flags );
39 .fi
40 .SH DESCRIPTION
41 .BR umount ()
42 and
43 .BR umount2 ()
44 remove the attachment of the (topmost) filesystem mounted on
45 .IR target .
46 .\" Note: the kernel naming differs from the glibc naming
47 .\" umount2 is the glibc name for what the kernel now calls umount
48 .\" and umount is the glibc name for oldumount
49 .PP
50 Appropriate privilege (Linux: the
51 .B CAP_SYS_ADMIN
52 capability) is required to unmount filesystems.
53 .PP
54 Linux 2.1.116 added the
55 .BR umount2 ()
56 system call, which, like
57 .BR umount (),
58 unmounts a target, but allows additional
59 .I flags
60 controlling the behavior of the operation:
61 .TP
62 .BR MNT_FORCE " (since Linux 2.1.116)"
63 Ask the filesystem to abort pending requests before attempting the
64 unmount.
65 This may allow the unmount to complete without waiting
66 for an inaccessible server, but could cause data loss.
67 If, after aborting requests,
68 some processes still have active references to the filesystem,
69 the unmount will still fail.
70 As at Linux 4.12,
71 .BR MNT_FORCE
72 is supported only on the following filesystems:
73 9p (since Linux 2.6.16),
74 ceph (since Linux 2.6.34),
75 cifs (since Linux 2.6.12),
76 fuse (since Linux 2.6.16),
77 lustre (since Linux 3.11),
78 and NFS (since Linux 2.1.116).
79 .TP
80 .BR MNT_DETACH " (since Linux 2.4.11)"
81 Perform a lazy unmount: make the mount unavailable for new
82 accesses, immediately disconnect the filesystem and all filesystems
83 mounted below it from each other and from the mount table, and
84 actually perform the unmount when the mount ceases to be busy.
85 .TP
86 .BR MNT_EXPIRE " (since Linux 2.6.8)"
87 Mark the mount as expired.
88 If a mount is not currently in use, then an initial call to
89 .BR umount2 ()
90 with this flag fails with the error
91 .BR EAGAIN ,
92 but marks the mount as expired.
93 The mount remains expired as long as it isn't accessed
94 by any process.
95 A second
96 .BR umount2 ()
97 call specifying
98 .B MNT_EXPIRE
99 unmounts an expired mount.
100 This flag cannot be specified with either
101 .B MNT_FORCE
103 .BR MNT_DETACH .
105 .BR UMOUNT_NOFOLLOW " (since Linux 2.6.34)"
106 .\" Later added to 2.6.33-stable
107 Don't dereference
108 .I target
109 if it is a symbolic link.
110 This flag allows security problems to be avoided in set-user-ID-\fIroot\fP
111 programs that allow unprivileged users to unmount filesystems.
112 .SH RETURN VALUE
113 On success, zero is returned.
114 On error, \-1 is returned, and
115 .I errno
116 is set to indicate the error.
117 .SH ERRORS
118 The error values given below result from filesystem type independent
119 errors.
120 Each filesystem type may have its own special errors and its
121 own special behavior.
122 See the Linux kernel source code for details.
124 .B EAGAIN
125 A call to
126 .BR umount2 ()
127 specifying
128 .B MNT_EXPIRE
129 successfully marked an unbusy filesystem as expired.
131 .B EBUSY
132 .I target
133 could not be unmounted because it is busy.
135 .B EFAULT
136 .I target
137 points outside the user address space.
139 .B EINVAL
140 .I target
141 is not a mount point.
143 .B EINVAL
144 .I target
145 is locked; see
146 .BR mount_namespaces (7).
148 .B EINVAL
149 .BR umount2 ()
150 was called with
151 .B MNT_EXPIRE
152 and either
153 .B MNT_DETACH
155 .BR MNT_FORCE .
157 .BR EINVAL " (since Linux 2.6.34)"
158 .BR umount2 ()
159 was called with an invalid flag value in
160 .IR flags .
162 .B ENAMETOOLONG
163 A pathname was longer than
164 .BR MAXPATHLEN .
166 .B ENOENT
167 A pathname was empty or had a nonexistent component.
169 .B ENOMEM
170 The kernel could not allocate a free page to copy filenames or data into.
172 .B EPERM
173 The caller does not have the required privileges.
174 .SH VERSIONS
175 .BR MNT_DETACH
177 .BR MNT_EXPIRE
178 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=10092
179 are available in glibc since version 2.11.
180 .SH CONFORMING TO
181 These functions are Linux-specific and should not be used in
182 programs intended to be portable.
183 .SH NOTES
184 .SS umount() and shared mounts
185 Shared mounts cause any mount activity on a mount, including
186 .BR umount ()
187 operations, to be forwarded to every shared mount in the
188 peer group and every slave mount of that peer group.
189 This means that
190 .BR umount ()
191 of any peer in a set of shared mounts will cause all of its
192 peers to be unmounted and all of their slaves to be unmounted as well.
194 This propagation of unmount activity can be particularly surprising
195 on systems where every mount is shared by default.
196 On such systems,
197 recursively bind mounting the root directory of the filesystem
198 onto a subdirectory and then later unmounting that subdirectory with
199 .BR MNT_DETACH
200 will cause every mount in the mount namespace to be lazily unmounted.
202 To ensure
203 .BR umount ()
204 does not propagate in this fashion,
205 the mount may be remounted using a
206 .BR mount (2)
207 call with a
208 .I mount_flags
209 argument that includes both
210 .BR MS_REC
212 .BR MS_PRIVATE
213 prior to
214 .BR umount ()
215 being called.
216 .SS Historical details
217 The original
218 .BR umount ()
219 function was called as \fIumount(device)\fP and would return
220 .B ENOTBLK
221 when called with something other than a block device.
222 In Linux 0.98p4, a call \fIumount(dir)\fP was added, in order to
223 support anonymous devices.
224 In Linux 2.3.99-pre7, the call \fIumount(device)\fP was removed,
225 leaving only \fIumount(dir)\fP (since now devices can be mounted
226 in more than one place, so specifying the device does not suffice).
227 .SH SEE ALSO
228 .BR mount (2),
229 .BR mount_namespaces (7),
230 .BR path_resolution (7),
231 .BR mount (8),
232 .BR umount (8)