Skip to content
shellmap

mountAttach a filesystem to a directory in the tree across all 5 shells

Equivalents in every shell

Bashunix
sudo mount /dev/sdb1 /mnt/data

Backed by `util-linux`. Auto-detects most filesystems via libblkid; pass `-t <fs>` (e.g. `-t ext4`, `-t ntfs`, `-t cifs`) when probing fails. The common option triplet `-o ro,noatime,nofail` covers read-only durable mounts that should not break boot if the device is absent.

Zshunix
sudo mount /dev/sdb1 /mnt/data

Identical `/sbin/mount` binary as bash on Linux. On macOS the binary is BSD `mount(8)` instead — flag set differs (no `-o nofail`); the canonical macOS path is `diskutil mount /dev/disk2s1` for removable media and `hdiutil attach` for `.dmg` / `.iso` images.

Fishunix
sudo mount /dev/sdb1 /mnt/data

Same external binary — fish never reinterprets the arguments. Spaces in mountpoints still need quoting: `sudo mount /dev/sdb1 "/mnt/My Backup"`. To run with sudo non-interactively in scripts, configure `NOPASSWD` for the specific mount line in `/etc/sudoers.d/`.

PowerShellwindows
New-PSDrive -Name D -PSProvider FileSystem -Root \\server\share -Persist

Two distinct patterns. `New-PSDrive` maps a drive letter (session-only by default; `-Persist` writes through to the Windows MUP mount table so File Explorer sees it). `Mount-DiskImage -ImagePath disk.iso` mounts ISO / VHD / VHDX files as virtual drives. `Mount-WindowsImage` mounts WIM images for offline servicing.

cmd.exewindows
mountvol C:\Mount \\?\Volume{guid}\

cmd has no Unix-style `mount`. `mountvol` attaches a volume GUID to an empty NTFS folder (Windows volume mount points). For drive letters: `subst X: C:\some\path` (session-scoped, not persisted across reboots). Network shares: `net use Z: \\server\share /persistent:yes`.

Worked examples

Mount an ISO file (read-only)

Bash
sudo mount -o loop,ro disk.iso /mnt/iso
PowerShell
Mount-DiskImage -ImagePath C:\path\to\disk.iso
cmd.exe
powershell -Command "Mount-DiskImage -ImagePath C:\path\to\disk.iso"

Mount an SMB / CIFS network share

Bash
sudo mount -t cifs //server/share /mnt/share -o username=alice,uid=$(id -u)
PowerShell
New-PSDrive -Name Z -PSProvider FileSystem -Root \\server\share -Persist
cmd.exe
net use Z: \\server\share /persistent:yes

List current mounts in a readable form

Bash
mount | column -t
PowerShell
Get-PSDrive -PSProvider FileSystem
cmd.exe
mountvol

Gotchas

  • `mount` requires root on Linux unless `/etc/fstab` lists the entry with the `user` (or `users`) option, which lets a non-root user mount and unmount that exact device. Without the flag the typical "must be superuser" failure appears even when the user owns the mountpoint.
  • On macOS `/etc/fstab` is honored but the canonical way to attach removable / image media is `diskutil mountDisk` or `hdiutil attach`. Plain BSD `mount(8)` only speaks filesystems the kernel ships natively (HFS+, APFS, exFAT, FAT32, read-only NTFS). For writeable NTFS or ext4 on macOS, you need a userspace driver (macFUSE + ntfs-3g / fuse-ext2).
  • PowerShell `New-PSDrive` WITHOUT `-Persist` is **session-only** — the drive vanishes the moment the PowerShell session closes. `-Persist` requires `-Root` to be a UNC path AND the drive name to be a single letter; it then writes through `net use` so File Explorer sees the mapping. `-Persist` cannot persist non-UNC roots (e.g. a local folder).
  • `Mount-DiskImage` returns immediately with the ImageObject, but the assigned drive letter is NOT in the return value. Discover it via `Get-DiskImage -ImagePath ... | Get-Volume | Select DriveLetter` (or pre-assign with `Set-Partition -AccessPath`). Scripts that `Start-Sleep 1` before reading the letter are racy on slow disks.
  • CIFS / SMB on Linux: `uid=` and `gid=` mount options are how the logged-in user gets write access — the server typically does not preserve POSIX ownership, and without those the kernel reports every file as owned by root. Pair with `iocharset=utf8,vers=3.1.1` for Unicode filenames against modern Windows / Samba servers.

WSL & PowerShell Core notes

pwshOn Linux pwsh, `New-PSDrive -PSProvider FileSystem` creates a logical pwsh-only path (e.g. `New-PSDrive Work FileSystem ~/work`) — it does NOT call `mount(8)`. To attach a real filesystem from pwsh on Linux, shell out: `& sudo mount /dev/sdb1 /mnt/data`. On Windows pwsh, `Mount-DiskImage` is the cross-version equivalent for ISO/VHD; `New-PSDrive -Persist` is Windows-only because the persistence layer depends on `mpr.dll` (the MUP).
WSLWSL2 auto-mounts Windows drives at `/mnt/c`, `/mnt/d`, etc. via the DrvFs adapter — no manual `mount` needed. To attach a physical Linux-formatted disk into WSL2, run `wsl --mount \\.\PHYSICALDRIVE2 --partition 1 --type ext4` from an admin Windows pwsh; the disk then appears at `/mnt/wsl/PHYSICALDRIVE2p1` inside the distro. CIFS mounts inside WSL work but require `sudo apt install cifs-utils` first — the kernel module ships, the userspace helper does not.

Related commands