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 unavailable for new ac‐
38              cesses, 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  ceases  to  be
41              busy.
42
43       MNT_EXPIRE (since Linux 2.6.8)
44              Mark  the mount as expired.  If a mount is not currently in use,
45              then an initial call to umount2() with this flag fails with  the
46              error EAGAIN, but marks the mount as expired.  The mount remains
47              expired as long as it isn't accessed by any process.   A  second
48              umount2()  call specifying MNT_EXPIRE unmounts an expired mount.
49              This flag cannot be specified with either MNT_FORCE  or  MNT_DE‐
50              TACH.
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 target is locked; see mount_namespaces(7).
76
77       EINVAL umount2()  was  called  with MNT_EXPIRE and either MNT_DETACH or
78              MNT_FORCE.
79
80       EINVAL (since Linux 2.6.34)
81              umount2() was called with an invalid flag value in flags.
82
83       ENAMETOOLONG
84              A pathname was longer than MAXPATHLEN.
85
86       ENOENT A pathname was empty or had a nonexistent component.
87
88       ENOMEM The kernel could not allocate a free page to copy  filenames  or
89              data into.
90
91       EPERM  The caller does not have the required privileges.
92

VERSIONS

94       MNT_DETACH and MNT_EXPIRE are available in glibc since version 2.11.
95

CONFORMING TO

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

NOTES

101   umount() and shared mounts
102       Shared mounts cause any mount activity on a mount,  including  umount()
103       operations, to be forwarded to every shared mount in the peer group and
104       every slave mount of that peer group.  This means that umount() of  any
105       peer  in  a  set of shared mounts will cause all of its peers to be un‐
106       mounted and all of their slaves to be unmounted as well.
107
108       This propagation of unmount activity can be particularly surprising  on
109       systems  where  every mount is shared by default.  On such systems, re‐
110       cursively bind mounting the root directory of  the  filesystem  onto  a
111       subdirectory  and  then later unmounting that subdirectory with MNT_DE‐
112       TACH will cause every mount in the mount namespace  to  be  lazily  un‐
113       mounted.
114
115       To ensure umount() does not propagate in this fashion, the mount may be
116       remounted using a mount(2) call with a mount_flags  argument  that  in‐
117       cludes 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

SEE ALSO

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

COLOPHON

131       This page is part of release 5.13 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                             2021-08-27                         UMOUNT(2)
Impressum