1UMOUNT(2) Linux Programmer's Manual UMOUNT(2)
2
3
4
6 umount, umount2 - unmount filesystem
7
9 #include <sys/mount.h>
10
11 int umount(const char *target);
12
13 int umount2(const char *target, int flags);
14
16 umount() and umount2() remove the attachment of the (topmost) filesys‐
17 tem mounted on target.
18
19 Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
20 to unmount filesystems.
21
22 Linux 2.1.116 added the umount2() system call, which, like umount(),
23 unmounts a target, but allows additional flags controlling the behavior
24 of the operation:
25
26 MNT_FORCE (since Linux 2.1.116)
27 Ask the filesystem to abort pending requests before attempting
28 the unmount. This may allow the unmount to complete without
29 waiting for an inaccessible server, but could cause data loss.
30 If, after aborting requests, some processes still have active
31 references to the filesystem, the unmount will still fail. As
32 at Linux 4.12, MNT_FORCE is supported only on the following
33 filesystems: 9p (since Linux 2.6.16), ceph (since Linux 2.6.34),
34 cifs (since Linux 2.6.12), fuse (since Linux 2.6.16), lustre
35 (since Linux 3.11), and NFS (since Linux 2.1.116).
36
37 MNT_DETACH (since Linux 2.4.11)
38 Perform a lazy unmount: make the mount point unavailable for new
39 accesses, immediately disconnect the filesystem and all filesys‐
40 tems mounted below it from each other and from the mount table,
41 and actually perform the unmount when the mount point ceases to
42 be busy.
43
44 MNT_EXPIRE (since Linux 2.6.8)
45 Mark the mount point as expired. If a mount point is not cur‐
46 rently in use, then an initial call to umount2() with this flag
47 fails with the error EAGAIN, but marks the mount point as
48 expired. The mount point remains expired as long as it isn't
49 accessed by any process. A second umount2() call specifying
50 MNT_EXPIRE unmounts an expired mount point. This flag cannot be
51 specified with either MNT_FORCE or MNT_DETACH.
52
53 UMOUNT_NOFOLLOW (since Linux 2.6.34)
54 Don't dereference target if it is a symbolic link. This flag
55 allows security problems to be avoided in set-user-ID-root pro‐
56 grams that allow unprivileged users to unmount filesystems.
57
59 On success, zero is returned. On error, -1 is returned, and errno is
60 set appropriately.
61
63 The error values given below result from filesystem type independent
64 errors. Each filesystem type may have its own special errors and its
65 own special behavior. See the Linux kernel source code for details.
66
67 EAGAIN A call to umount2() specifying MNT_EXPIRE successfully marked an
68 unbusy filesystem as expired.
69
70 EBUSY target could not be unmounted because it is busy.
71
72 EFAULT target points outside the user address space.
73
74 EINVAL target is not a mount point.
75
76 EINVAL umount2() was called with MNT_EXPIRE and either MNT_DETACH or
77 MNT_FORCE.
78
79 EINVAL (since Linux 2.6.34)
80 umount2() was called with an invalid flag value in flags.
81
82 ENAMETOOLONG
83 A pathname was longer than MAXPATHLEN.
84
85 ENOENT A pathname was empty or had a nonexistent component.
86
87 ENOMEM The kernel could not allocate a free page to copy filenames or
88 data into.
89
90 EPERM The caller does not have the required privileges.
91
93 MNT_DETACH and MNT_EXPIRE are available in glibc since version 2.11.
94
96 These functions are Linux-specific and should not be used in programs
97 intended to be portable.
98
100 umount() and shared mount points
101 Shared mount points cause any mount activity on a mount point, includ‐
102 ing umount() operations, to be forwarded to every shared mount point in
103 the peer group and every slave mount of that peer group. This means
104 that umount() of any peer in a set of shared mounts will cause all of
105 its peers to be unmounted and all of their slaves to be unmounted as
106 well.
107
108 This propagation of unmount activity can be particularly surprising on
109 systems where every mount point is shared by default. On such systems,
110 recursively bind mounting the root directory of the filesystem onto a
111 subdirectory and then later unmounting that subdirectory with
112 MNT_DETACH will cause every mount in the mount namespace to be lazily
113 unmounted.
114
115 To ensure umount() does not propagate in this fashion, the mount point
116 may be remounted using a mount() call with a mount_flags argument that
117 includes both MS_REC and MS_PRIVATE prior to umount() being called.
118
119 Historical details
120 The original umount() function was called as umount(device) and would
121 return ENOTBLK when called with something other than a block device.
122 In Linux 0.98p4, a call umount(dir) was added, in order to support
123 anonymous devices. In Linux 2.3.99-pre7, the call umount(device) was
124 removed, leaving only umount(dir) (since now devices can be mounted in
125 more than one place, so specifying the device does not suffice).
126
128 mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)
129
131 This page is part of release 5.04 of the Linux man-pages project. A
132 description of the project, information about reporting bugs, and the
133 latest version of this page, can be found at
134 https://www.kernel.org/doc/man-pages/.
135
136
137
138Linux 2017-09-15 UMOUNT(2)