1UMOUNT(2)                  Linux Programmer's Manual                 UMOUNT(2)
2
3
4

NAME

6       umount, umount2 - unmount filesystem
7

SYNOPSIS

9       #include <sys/mount.h>
10
11       int umount(const char *target);
12       int umount2(const char *target, int flags);
13

DESCRIPTION

15       umount()  and umount2() remove the attachment of the (topmost) filesys‐
16       tem mounted on target.
17
18       Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
19       to unmount filesystems.
20
21       Linux  2.1.116  added  the umount2() system call, which, like umount(),
22       unmounts a target, but allows additional flags controlling the behavior
23       of the operation:
24
25       MNT_FORCE (since Linux 2.1.116)
26              Ask  the  filesystem to abort pending requests before attempting
27              the unmount.  This may allow the  unmount  to  complete  without
28              waiting  for  an inaccessible server, but could cause data loss.
29              If, after aborting requests, some processes  still  have  active
30              references  to  the filesystem, the unmount will still fail.  As
31              at Linux 4.12, MNT_FORCE is  supported  only  on  the  following
32              filesystems: 9p (since Linux 2.6.16), ceph (since Linux 2.6.34),
33              cifs (since Linux 2.6.12), fuse  (since  Linux  2.6.16),  lustre
34              (since Linux 3.11), and NFS (since Linux 2.1.116).
35
36       MNT_DETACH (since Linux 2.4.11)
37              Perform a lazy unmount: make the mount point unavailable for new
38              accesses, immediately disconnect the filesystem and all filesys‐
39              tems  mounted below it from each other and from the mount table,
40              and actually perform the unmount when the mount point ceases  to
41              be busy.
42
43       MNT_EXPIRE (since Linux 2.6.8)
44              Mark  the  mount point as expired.  If a mount point is not cur‐
45              rently in use, then an initial call to umount2() with this  flag
46              fails  with  the  error EAGAIN, but marks the mount point as ex‐
47              pired.  The mount point remains expired as long as it isn't  ac‐
48              cessed  by  any  process.   A  second  umount2() call specifying
49              MNT_EXPIRE unmounts an expired mount point.  This flag cannot be
50              specified with either MNT_FORCE or MNT_DETACH.
51
52       UMOUNT_NOFOLLOW (since Linux 2.6.34)
53              Don't  dereference  target  if it is a symbolic link.  This flag
54              allows security problems to be avoided in set-user-ID-root  pro‐
55              grams that allow unprivileged users to unmount filesystems.
56

RETURN VALUE

58       On  success,  zero is returned.  On error, -1 is returned, and errno is
59       set to indicate the error.
60

ERRORS

62       The error values given below result from  filesystem  type  independent
63       errors.   Each  filesystem type may have its own special errors and its
64       own special behavior.  See the Linux kernel source code for details.
65
66       EAGAIN A call to umount2() specifying MNT_EXPIRE successfully marked an
67              unbusy filesystem as expired.
68
69       EBUSY  target could not be unmounted because it is busy.
70
71       EFAULT target points outside the user address space.
72
73       EINVAL target is not a mount point.
74
75       EINVAL umount2()  was  called  with MNT_EXPIRE and either MNT_DETACH or
76              MNT_FORCE.
77
78       EINVAL (since Linux 2.6.34)
79              umount2() was called with an invalid flag value in flags.
80
81       ENAMETOOLONG
82              A pathname was longer than MAXPATHLEN.
83
84       ENOENT A pathname was empty or had a nonexistent component.
85
86       ENOMEM The kernel could not allocate a free page to copy  filenames  or
87              data into.
88
89       EPERM  The caller does not have the required privileges.
90

VERSIONS

92       MNT_DETACH and MNT_EXPIRE are available in glibc since version 2.11.
93

CONFORMING TO

95       These  functions  are Linux-specific and should not be used in programs
96       intended to be portable.
97

NOTES

99   umount() and shared mount points
100       Shared mount points cause any mount activity on a mount point,  includ‐
101       ing umount() operations, to be forwarded to every shared mount point in
102       the peer group and every slave mount of that peer  group.   This  means
103       that  umount()  of any peer in a set of shared mounts will cause all of
104       its peers to be unmounted and all of their slaves to  be  unmounted  as
105       well.
106
107       This  propagation of unmount activity can be particularly surprising on
108       systems where every mount point is shared by default.  On such systems,
109       recursively  bind  mounting the root directory of the filesystem onto a
110       subdirectory and then later unmounting that subdirectory  with  MNT_DE‐
111       TACH  will  cause  every  mount in the mount namespace to be lazily un‐
112       mounted.
113
114       To ensure umount() does not propagate in this fashion, the mount  point
115       may be remounted using a mount(2) call with a mount_flags argument that
116       includes both MS_REC and MS_PRIVATE prior to umount() being called.
117
118   Historical details
119       The original umount() function was called as umount(device)  and  would
120       return  ENOTBLK  when  called with something other than a block device.
121       In Linux 0.98p4, a call umount(dir) was  added,  in  order  to  support
122       anonymous  devices.   In Linux 2.3.99-pre7, the call umount(device) was
123       removed, leaving only umount(dir) (since now devices can be mounted  in
124       more than one place, so specifying the device does not suffice).
125

SEE ALSO

127       mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)
128

COLOPHON

130       This  page  is  part of release 5.12 of the Linux man-pages project.  A
131       description of the project, information about reporting bugs,  and  the
132       latest     version     of     this    page,    can    be    found    at
133       https://www.kernel.org/doc/man-pages/.
134
135
136
137Linux                             2021-03-22                         UMOUNT(2)
Impressum