Skip to main content

Mount

Mounting attaches a filesystem (from a disk partition, network share, or virtual source) to a directory in the Linux directory tree. After mounting, its files appear at that directory path.

Understanding Mounts in Linux

What Does Mounting Mean in Linux?

Linux has a single directory tree starting at /. A new disk or network share is not reachable until you mount it at a mount point, which is any existing directory. There are no drive letters. The mounted filesystem's root simply appears at that directory.

◈ DIAGRAM
Before: mount /dev/sdb1 /mnt/data After:
/mnt/data/ (empty directory) /mnt/data/ -> contents of /dev/sdb1
backups/ archives/ database.dump

Mounting over a non-empty directory hides its existing files until you unmount; they are not deleted.

Common Mount Points

TEXT
/ root filesystem
/boot kernel and boot files
/home user data, often a separate disk
/var variable data, often separate so logs cannot fill root
/tmp temporary files, often tmpfs
/mnt manual temporary mounts
/media removable media
/data common convention for extra disks

How to Mount and Unmount Filesystems

Bash
findmnt # current mounts as a tree
df -hT # usage and type
sudo mount /dev/sdb1 /mnt/data
sudo mount -o ro /dev/sdb1 /mnt/data # read-only
sudo mount -t nfs 10.0.1.5:/exports/data /mnt/nfs # network share
sudo mount -t tmpfs -o size=2G tmpfs /mnt/ramdisk
sudo umount /mnt/data
lsof +f -- /mnt/data # who is keeping it busy
fuser -vm /mnt/data
sudo umount -l /mnt/data # lazy: detach now, clean up when free

How to Make Mounts Persistent With /etc/fstab

Bash
blkid /dev/sdb1 # get the UUID
# /etc/fstab line:
# UUID=ghi789 /data xfs defaults,noatime 0 2
sudo mount -a # test fstab without rebooting

Use UUIDs, not /dev/sdb1 names, because device names can change when disks are added or removed.

Security Mount Options

TEXT
ro read-only
noexec binaries cannot run from this filesystem
nosuid setuid bits are ignored
nodev device files are ignored
Example: tmpfs /tmp tmpfs defaults,noexec,nosuid,nodev 0 0

Troubleshooting Mounts

Symptom Command What to Look For
Mount fails dmesg | tail -20 Device or filesystem error
Cannot unmount, busy lsof +f -- /mnt Open files or shells inside
Gone after reboot cat /etc/fstab No entry or wrong UUID
Files seem missing findmnt /path Something mounted on top
Common Mistake

Running mount by hand and expecting it to survive a reboot. Without an /etc/fstab entry the mount is gone after restart.

Security

Mount /tmp with noexec,nosuid,nodev where your workloads allow it. Many attacks upload a binary to /tmp and run it. Some installers need exec on /tmp, so test first.

Remember

A bad /etc/fstab line can stop a server booting. Run sudo mount -a to validate before rebooting, and consider the nofail option for non-critical disks.

Frequently Asked Questions

What happens when I mount a filesystem?

The kernel attaches the filesystem's root to the mount-point directory, so its contents appear there and any previous contents of that directory are hidden until unmount.

Why did my files disappear after mounting a disk?

If you wrote files into the mount-point directory before mounting, the new mount covers them. Unmount and they reappear, since they were never deleted.

What does a lazy unmount do?

`umount -l` detaches the filesystem from the tree immediately and finishes cleanup once nothing is using it. It does not wait before detaching, so processes with open files keep working on the old mount.

Found a mistake, an outdated step or a broken link?