1umount(2)                     System Calls Manual                    umount(2)
2
3
4

NAME

6       umount, umount2 - unmount filesystem
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/mount.h>
13
14       int umount(const char *target);
15       int umount2(const char *target, int flags);
16

DESCRIPTION

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

RETURN VALUE

61       On  success,  zero is returned.  On error, -1 is returned, and errno is
62       set to indicate the error.
63

ERRORS

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

STANDARDS

97       Linux.
98

HISTORY

100       MNT_DETACH and MNT_EXPIRE are available since glibc 2.11.
101
102       The  original  umount() function was called as umount(device) and would
103       return ENOTBLK when called with something other than  a  block  device.
104       In  Linux  0.98p4,  a  call  umount(dir) was added, in order to support
105       anonymous devices.  In Linux 2.3.99-pre7, the call  umount(device)  was
106       removed,  leaving only umount(dir) (since now devices can be mounted in
107       more than one place, so specifying the device does not suffice).
108

NOTES

110   umount() and shared mounts
111       Shared mounts cause any mount activity on a mount,  including  umount()
112       operations, to be forwarded to every shared mount in the peer group and
113       every slave mount of that peer group.  This means that umount() of  any
114       peer  in  a  set of shared mounts will cause all of its peers to be un‐
115       mounted and all of their slaves to be unmounted as well.
116
117       This propagation of unmount activity can be particularly surprising  on
118       systems  where  every mount is shared by default.  On such systems, re‐
119       cursively bind mounting the root directory of  the  filesystem  onto  a
120       subdirectory  and  then later unmounting that subdirectory with MNT_DE‐
121       TACH will cause every mount in the mount namespace  to  be  lazily  un‐
122       mounted.
123
124       To ensure umount() does not propagate in this fashion, the mount may be
125       remounted using a mount(2) call with a mount_flags  argument  that  in‐
126       cludes both MS_REC and MS_PRIVATE prior to umount() being called.
127

SEE ALSO

129       mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)
130
131
132
133Linux man-pages 6.05              2023-03-30                         umount(2)
Impressum