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.
Before: mount /dev/sdb1 /mnt/data After:/mnt/data/ (empty directory) /mnt/data/ -> contents of /dev/sdb1 backups/ archives/ database.dumpMounting over a non-empty directory hides its existing files until you unmount; they are not deleted.
Common Mount Points
/ 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 disksHow to Mount and Unmount Filesystems
findmnt # current mounts as a treedf -hT # usage and type sudo mount /dev/sdb1 /mnt/datasudo mount -o ro /dev/sdb1 /mnt/data # read-onlysudo mount -t nfs 10.0.1.5:/exports/data /mnt/nfs # network sharesudo mount -t tmpfs -o size=2G tmpfs /mnt/ramdisk sudo umount /mnt/datalsof +f -- /mnt/data # who is keeping it busyfuser -vm /mnt/datasudo umount -l /mnt/data # lazy: detach now, clean up when freeHow to Make Mounts Persistent With /etc/fstab
blkid /dev/sdb1 # get the UUID # /etc/fstab line:# UUID=ghi789 /data xfs defaults,noatime 0 2 sudo mount -a # test fstab without rebootingUse UUIDs, not /dev/sdb1 names, because device names can change when disks are added or removed.
Security Mount Options
ro read-onlynoexec binaries cannot run from this filesystemnosuid setuid bits are ignorednodev device files are ignored Example: tmpfs /tmp tmpfs defaults,noexec,nosuid,nodev 0 0Troubleshooting 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 MistakeRunning
mountby hand and expecting it to survive a reboot. Without an/etc/fstabentry the mount is gone after restart.
SecurityMount
/tmpwithnoexec,nosuid,nodevwhere your workloads allow it. Many attacks upload a binary to/tmpand run it. Some installers need exec on/tmp, so test first.
RememberA bad
/etc/fstabline can stop a server booting. Runsudo mount -ato validate before rebooting, and consider thenofailoption 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.