umount(2) | System Calls Manual | umount(2) |
umount, umount2 - unmount filesystem
Standard C library (libc, -lc)
#include <sys/mount.h>
int umount(const char *target); int umount2(const char *target, int flags);
umount() and umount2() remove the attachment of the (topmost) filesystem mounted on target.
Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to unmount filesystems.
Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behavior of the operation:
On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error.
The error values given below result from filesystem type independent errors. Each filesystem type may have its own special errors and its own special behavior. See the Linux kernel source code for details.
MNT_DETACH and MNT_EXPIRE are available since glibc 2.11.
These functions are Linux-specific and should not be used in programs intended to be portable.
Shared mounts cause any mount activity on a mount, including umount() operations, to be forwarded to every shared mount in the peer group and every slave mount of that peer group. This means that umount() of any peer in a set of shared mounts will cause all of its peers to be unmounted and all of their slaves to be unmounted as well.
This propagation of unmount activity can be particularly surprising on systems where every mount is shared by default. On such systems, recursively bind mounting the root directory of the filesystem onto a subdirectory and then later unmounting that subdirectory with MNT_DETACH will cause every mount in the mount namespace to be lazily unmounted.
To ensure umount() does not propagate in this fashion, the mount may be remounted using a mount(2) call with a mount_flags argument that includes both MS_REC and MS_PRIVATE prior to umount() being called.
The original umount() function was called as umount(device) and would return ENOTBLK when called with something other than a block device. In Linux 0.98p4, a call umount(dir) was added, in order to support anonymous devices. In Linux 2.3.99-pre7, the call umount(device) was removed, leaving only umount(dir) (since now devices can be mounted in more than one place, so specifying the device does not suffice).
mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)
2022-12-04 | Linux man-pages 6.03 |