umount(2)
๐ umount, umount2 โ the "ok bye bestie" syscalls
welcome to the umount(2) page, aka the system calls manual entry you're reading at 2am because something is stuck and won't let go. it's giving "we need to talk". no cap, this one's shorter than most, so we're gonna get through it together ๐ซถ
๐ท๏ธ NAME
umount, umount2 โ unmount filesystem
๐ LIBRARY
Standard C library (libc, -lc)
๐ง SYNOPSIS
#include <sys/mount.h>
int umount(const char *target);
int umount2(const char *target, int flags);
๐ธ DESCRIPTION
okay so real talk: umount() and umount2() remove the attachment of the (topmost) filesystem mounted on target. that's the whole job. it's the breakup text of filesystems.
heads up: you need appropriate privilege to unmount filesystems. on Linux that means the CAP_SYS_ADMIN capability. so like... you can't just do this as a lil guy. ๐
Linux 2.1.116 added the umount2() system call, and it does exactly what umount() does โ unmounts a target โ but it also lets you pass extra flags that control how the operation behaves. and bestie, those flags are where the drama lives:
MNT_FORCE(since Linux 2.1.116) โ asks the filesystem to abort pending requests before it even attempts the unmount. this can let the unmount finish without waiting around for some inaccessible server, but it could cause data loss. ๐ญ and even after aborting requests, if some processes still hold active references to the filesystem, the unmount will still fail. as at Linux 4.12,MNT_FORCEis supported only on these filesystems:9p(since Linux 2.6.16),ceph(since Linux 2.6.34),cifs(since Linux 2.6.12),fuse(since Linux 2.6.16),lustre(since Linux 3.11), andNFS(since Linux 2.1.116). very "only these girls are invited to the party" of it.MNT_DETACH(since Linux 2.4.11) โ does a lazy unmount. it makes the mount unavailable for new accesses, immediately disconnects the filesystem and all filesystems mounted below it from each other and from the mount table, and then actually performs the unmount when the mount stops being busy. it's the "i'm not dealing with this right now, i'll deal with it later" of unmounting. iconic.MNT_EXPIRE(since Linux 2.6.8) โ marks the mount as expired. here's the tea: if a mount isn't currently in use, an initial call toumount2()with this flag fails with the errorEAGAIN, but it marks the mount as expired. the mount stays expired as long as no process accesses it. then a secondumount2()call specifyingMNT_EXPIREunmounts an expired mount. two-step verification but for breaks. also this flag cannot be specified with eitherMNT_FORCEorMNT_DETACHโ pick a lane.UMOUNT_NOFOLLOW(since Linux 2.6.34) โ don't dereference target if it's a symbolic link. this flag lets set-user-ID-root programs that let unprivileged users unmount filesystems avoid security problems. so it's the safety goggles flag. wear it.
๐ซ RETURN VALUE
on success, zero is returned. on error, -1 is returned, and errno is set to indicate the error. classic.
๐จ ERRORS
the error values below are the filesystem-type-independent ones. every filesystem type may have its own special errors and its own special behavior โ check the Linux kernel source code for the details, bestie, i can't read that for you.
EAGAINโ a call toumount2()specifyingMNT_EXPIREsuccessfully marked an unbusy filesystem as expired. yes, this is technically the "success" of the expire dance and it's weird, we know.EBUSYโ target could not be unmounted because it is busy. it's not you, it's the processes.EFAULTโ target points outside the user address space.EINVALโ target is not a mount point.EINVALโ target is locked; seemount_namespaces(7).EINVALโumount2()was called withMNT_EXPIREand eitherMNT_DETACHorMNT_FORCE.EINVAL(since Linux 2.6.34) โumount2()was called with an invalid flag value inflags.ENAMETOOLONGโ a pathname was longer thanMAXPATHLEN.ENOENTโ a pathname was empty or had a nonexistent component.ENOMEMโ the kernel could not allocate a free page to copy filenames or data into. memory said no ๐EPERMโ the caller does not have the required privileges. (it's theCAP_SYS_ADMINthing again. we told you.)
๐ STANDARDS
Linux. that's it. that's the whole section. periodt.
๐ฐ๏ธ HISTORY
MNT_DETACH and MNT_EXPIRE are available since glibc 2.11.
the original umount() function was called as umount(device) and would return ENOTBLK when you called it with something that wasn't a block device. then in Linux 0.98p4, a call umount(dir) was added, in order to support anonymous devices. and then in Linux 2.3.99-pre7, the umount(device) call was removed, leaving only umount(dir) โ because now devices can be mounted in more than one place, so specifying the device doesn't suffice. character development arc fr fr โจ
๐๏ธ NOTES
๐ฆ umount() and shared mounts
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. which means 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. it's giving group chat: one person leaves, everyone leaves. ๐ญ
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. yeah. all of them. no cap.
to make sure umount() doesn't propagate like that, you can remount the mount using a mount(2) call with a mount_flags argument that includes both MS_REC and MS_PRIVATE before umount() gets called. do the remount first, bestie. trust.
๐ SEE ALSO
mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)
and that's the whole page, gorgeous ๐ this one came from Linux man-pages 6.20, dated 2026-02-08, and it's the umount(2) entry. now go unmount something responsibly. mwah ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Rickard E. Faith <faith@cs.unc.edu>
- Copyright 1994, Andries E. Brouwer <aeb@cwi.nl>
- Copyright 2002-2005, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms