mount — Attach a filesystem
💬 "mount command"
mount connects a device or network share to a directory. The connection point is called a mount point.
It is also often used to view the current mount status.
- Concept: Connects a device (or remote share) to a directory.
- Left argument: A device path (e.g., /dev/vdc1) or a remote share (e.g., 10.0.0.5:/data).
- Right argument: The directory to connect to (mount point).
- View status: Running without arguments shows the current mount list.
Commonly used options
| Option | Description |
|---|---|
| -t <type> | Specifies the filesystem type (ext4, nfs, xfs, etc.) |
| -o <options> | Specifies options (ro, noatime, noexec, etc.) |
| -a | Mounts all entries defined in /etc/fstab |
| --bind | Exposes an existing directory at another path as-is |
3 essential command combinations
mount | column -t | head— Check the current mount status in column-aligned formatmount -o noexec,nosuid /dev/vdc1 /data— Mount with security optionsmount --bind /srv/app/public /var/www/html— Connect a directory to the web root
💬 "Show me how to find bottlenecks with this command"
Here are common situations on production servers, organized in order.
Step 1 · Check the device
Check the device and filesystem to mount.
lsblk -f /dev/vdc
Step 2 · Prepare the mount point and connect
Create an empty directory and mount.
mkdir -p /data && mount /dev/vdc1 /data
Step 3 · Persist after reboot
Add it to fstab and test.
grep /data /etc/fstab && mount -a
In practice, it is used like this
1. Attaching a new data disk
Situation — You want to use a 500G volume as /data.
mkfs.ext4 /dev/vdc1 && mkdir -p /data && mount /dev/vdc1 /data
Result — When you enter /data, you see the contents of the new volume.
Tip — Formatting a device that has existing data makes recovery difficult. Check the device first with lsblk.
2. Exposing a deployment directory
Situation — The app uses /srv/app/public, but the web server root is /var/www/html.
mount --bind /srv/app/public /var/www/html
Result — The same content is visible at both paths without copying.
Tip — Bind mounts disappear on reboot, so add them to fstab or consider a symbolic link as well.
Cautionary notes
- If you mount over a directory that already has files, those contents are hidden (not deleted). They can be recovered if needed.
- Incorrect fstab syntax can lead to boot failure. After editing, verify with mount -a.
- Network filesystems can hang on access during a network failure, so set timeout options.
- Formatting (mkfs) erases data. Never run it without confirming the device name.
Actual execution screen
This is the result of checking the currently mounted filesystems and options.
!mount command execution result: mount list and options
Production server
Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/mount.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments