Skip to content
shellmap

umountDetach a mounted filesystem, flushing pending writes first across all 5 shells

Equivalents in every shell

Bashunix
sudo umount /mnt/data

POSIX spelling is `umount` (one "n"). Either the source device or the mountpoint may be passed. `-l` (lazy) detaches the filesystem from the namespace immediately but defers the actual unmount until no process holds a reference — useful for hung NFS but DANGEROUS in scripts because `umount -l` always exits 0.

Zshunix
sudo umount /mnt/data

Same external. macOS has `umount` and also a higher-level `diskutil unmount /Volumes/Foo` (and `diskutil unmountDisk /dev/disk2` to unmount every slice on a physical disk). `diskutil` returns better diagnostics when the unmount is blocked by an open file.

Fishunix
sudo umount /mnt/data

Same external binary. To find which process is keeping the mount busy: `lsof +D /mnt/data` (or `fuser -vm /mnt/data` from `psmisc`). Killing the holder usually lets `umount` succeed without resorting to the lazy / force flags.

PowerShellwindows
Remove-PSDrive -Name D

For `New-PSDrive` mappings: `Remove-PSDrive -Name D -Force` (with `-Force` if it is currently the location of the session). For `Mount-DiskImage` mounts: `Dismount-DiskImage -ImagePath disk.iso` (must pass the same path used to mount). The two are NOT interchangeable — calling the wrong one returns a misleading "drive not found".

cmd.exewindows
mountvol C:\Mount /D

`mountvol /D` removes a volume mount point. For drive-letter unmounts: `subst X: /D` (matching the original `subst`), `net use Z: /delete` (matching the original `net use`), or `mountvol X: /D` for `mountvol`-created drive letters. Each command only undoes mounts it created — they are not interchangeable.

Worked examples

Unmount and dismount an ISO image

Bash
sudo umount /mnt/iso
PowerShell
Dismount-DiskImage -ImagePath C:\path\to\disk.iso
cmd.exe
powershell -Command "Dismount-DiskImage -ImagePath C:\path\to\disk.iso"

Disconnect a mapped network share

Bash
sudo umount /mnt/share
PowerShell
Remove-PSDrive -Name Z
cmd.exe
net use Z: /delete

Force-unmount a hung filesystem (only as a last resort)

Bash
sudo umount -f /mnt/nfs
Zsh
sudo umount -f /mnt/nfs

Gotchas

  • The spelling is `umount`, NOT `unmount`. Typing `unmount` on Linux returns "command not found"; on macOS it returns the same. (`diskutil unmount` is the only common command that uses the full "unmount" spelling.)
  • `umount -l` (lazy) detaches the filesystem from the namespace but lets in-flight writes complete in the background. It ALWAYS returns 0 — even if the underlying device dies mid-flush. Production scripts should NEVER use `-l` and then assume the data is durable; pair with `sync` and an explicit `lsof` check.
  • `umount -f` (force) is for NETWORK filesystems only — it kicks the kernel into discarding pending writes and returning errors to processes still holding the mount. For local ext4 / xfs it accomplishes nothing because the kernel needs to flush dirty pages before unmount; `-f` won't skip that step.
  • `Remove-PSDrive -Persist`-ed drives need `Remove-PSDrive -Name Z` AND a separate `net use Z: /delete` if the drive was persisted via `net use` outside the current pwsh session — `Remove-PSDrive` only knows about session-scoped or pwsh-`-Persist`ed mappings. Using `net use Z: /delete` is the universal disconnect because it talks to the same MUP that File Explorer uses.
  • Windows volume-mount-point removal via `mountvol /D` only removes the access path — the volume is still mounted, just unreachable from that folder. To take an entire volume offline use `Set-Disk -Number N -IsOffline $true` (PowerShell) or `diskpart` `offline volume`.

WSL & PowerShell Core notes

pwshOn Linux/macOS pwsh, `Remove-PSDrive` only removes pwsh-internal drive mappings — it does NOT call `umount(8)`. Shell out: `& sudo umount /mnt/data`. On Windows pwsh, `Dismount-DiskImage` is the cross-version counterpart to `Mount-DiskImage` and is shipped in the `Storage` module starting Windows 8 / Server 2012 — older boxes need `Get-WmiObject Win32_DiskDrive` + WMI eject methods instead.
WSLInside WSL `umount /mnt/wsl/PHYSICALDRIVE2p1` detaches a `wsl --mount`-ed disk from the distro's view but does NOT release the disk to Windows. To fully release it, run `wsl --unmount \\.\PHYSICALDRIVE2` from an admin Windows pwsh — that's the symmetric operation to `wsl --mount`. Trying to `wsl --unmount` while a WSL process still has files open returns `WSL_E_VHD_MOUNTED` until the holders close.

Related commands