# mount — Mount and Unmount Filesystems

> Attach devices, images and network shares to the directory tree: mount, umount, /etc/fstab, bind, loop and tmpfs mounts.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/mount/

<!-- PROSE:intro -->
mount attaches devices, partitions, images and network shares to your directory tree – only then do their contents become visible under a path. From USB sticks through ISO loops and bind mounts to NFS and SMB shares, this guide walks you through the commands you reach for daily as an administrator. Take care: mounting over a non-empty directory hides its contents, and a mistake in `/etc/fstab` can leave your system unbootable. Most actions require `sudo`.
<!-- PROSE:intro:end -->

## Basic Mount & Unmount

`mount <device> <mountpoint>` — Mount a device to a directory.

```bash
mount /dev/sdb1 /mnt/usb
```

`mount -t <type> <device> <mountpoint>` — Mount with a specific filesystem type.

```bash
mount -t ext4 /dev/sdb1 /mnt/data
```

`mount` — Show all currently mounted filesystems.

```bash
mount
```

`mount | grep <pattern>` — Find specific mounts.

```bash
mount | grep nfs
```

`umount <mountpoint>` — Unmount a filesystem by mount point.

```bash
umount /mnt/usb
```

`umount <device>` — Unmount a filesystem by device.

```bash
umount /dev/sdb1
```

`umount -l <mountpoint>` — Lazy unmount: detach immediately, clean up when idle.

```bash
umount -l /mnt/stuck
```

## Mount Options

`mount -o ro <device> <mountpoint>` — Mount read-only.

```bash
mount -o ro /dev/sdb1 /mnt/readonly
```

`mount -o rw,noexec,nosuid <device> <mountpoint>` — Mount read-write with no exec and no suid.

```bash
mount -o rw,noexec,nosuid /dev/sdb1 /mnt/data
```

`mount -o remount,rw <mountpoint>` — Remount an already mounted filesystem (e.g., change to rw).

```bash
mount -o remount,rw /
```

`mount -o loop <image> <mountpoint>` — Mount an ISO or disk image file.

```bash
mount -o loop ubuntu.iso /mnt/iso
```

`mount -a` — Mount all filesystems from /etc/fstab.

```bash
mount -a
```

## Bind Mounts

`mount --bind <source> <target>` — Bind mount: make a directory available at another location.

```bash
mount --bind /var/www /home/user/www
```

`mount --rbind <source> <target>` — Recursive bind mount (includes submounts).

```bash
mount --rbind /dev /mnt/chroot/dev
```

`mount --bind -o remount,ro <target>` — Make a bind mount read-only.

```bash
mount --bind -o remount,ro /home/user/www
```

## tmpfs & Special Filesystems

`mount -t tmpfs -o size=<size> tmpfs <mountpoint>` — Mount a tmpfs (RAM-based filesystem).

```bash
mount -t tmpfs -o size=512M tmpfs /mnt/ramdisk
```

`mount -t proc proc /proc` — Mount the proc filesystem.

```bash
mount -t proc proc /mnt/chroot/proc
```

`mount -t sysfs sysfs /sys` — Mount the sysfs filesystem.

```bash
mount -t sysfs sysfs /mnt/chroot/sys
```

## Network Filesystems

`mount -t nfs <host>:<path> <mountpoint>` — Mount an NFS share.

```bash
mount -t nfs server:/export/data /mnt/nfs
```

`mount -t cifs //<host>/<share> <mountpoint> -o user=<user>` — Mount a Windows/Samba (CIFS/SMB) share.

```bash
mount -t cifs //server/share /mnt/smb -o user=admin,password=secret
```

`mount -t cifs //<host>/<share> <mountpoint> -o credentials=<file>` — Mount SMB share with credentials file.

```bash
mount -t cifs //server/share /mnt/smb -o credentials=/root/.smbcreds
```

## Troubleshooting

`findmnt` — Show mounted filesystems in tree format.

```bash
findmnt
```

`findmnt -t <type>` — Show mounts of a specific filesystem type.

```bash
findmnt -t ext4
```

`umount -f <mountpoint>` — Force unmount (for unreachable NFS mounts).

```bash
umount -f /mnt/nfs
```

`fuser -m <mountpoint>` — Show processes using a mount point (why umount fails).

```bash
fuser -m /mnt/usb
```

`lsof +f -- <mountpoint>` — List open files on a mounted filesystem.

```bash
lsof +f -- /mnt/data
```

<!-- PROSE:outro -->
## Conclusion

mount and umount are the backbone of filesystem management on Linux, and most actions require `sudo`. Before you commit entries to `/etc/fstab`, test them with `mount -a`: a typo can hang the system on the next boot, and the `nofail` option softens that risk. Remember that mounting over a non-empty directory only hides its contents – the data is not gone, merely obscured. When `umount` fails with "target is busy", `lsof` and `fuser` reveal the blocking process; as a last resort, `umount -l` detaches lazily.

## Further Reading

- [Arch Wiki: fstab](https://wiki.archlinux.org/title/Fstab) – how to configure persistent and safe mounts via /etc/fstab
- [man7: mount(8)](https://man7.org/linux/man-pages/man8/mount.8.html) – the complete reference for the mount command and its options
<!-- PROSE:outro:end -->

## Related Commands

- [lsblk](https://www.jpkc.com/db/en/cheatsheets/shell-system/lsblk/) – list block devices and partitions as a tree
- [fdisk](https://www.jpkc.com/db/en/cheatsheets/shell-system/fdisk/) – view and edit partition tables
- [df-du](https://www.jpkc.com/db/en/cheatsheets/shell-system/df-du/) – check disk space and directory sizes

