Skip to main content

mount — Mount a Filesystem

mount attaches a filesystem — a disk partition, block device, loop file, or remote share — to a directory so its contents become accessible under that path. On a WordPress VPS, you commonly use mount to attach a backup disk at /mnt/backups, a dedicated database volume at /var/lib/mysql, or extra storage for the uploads directory. Mounting the wrong device or forgetting to verify after a mount can cause backups to silently fill the root partition, so always confirm every mount with findmnt and df after the operation.

System Check

which mount # Expected: /bin/mount
mount --version # Expected: mount from util-linux x.xx
warning

Mounting on a non-empty directory hides the existing files until you unmount. If the backup mount is missing at job time, backup archives will be written to the root partition (/) instead of the dedicated disk.


Best Practices

  • Always verify after mounting — run findmnt -T TARGET and df -h TARGET immediately after every mount command.
  • Prefer UUID-based mounts — device names like /dev/sdb1 can change across reboots; UUIDs are stable. Use blkid to find the UUID.
  • Check the device before mounting — run lsblk -p -f and blkid to confirm the source device, filesystem type, and UUID before issuing mount.
  • Use an empty mount point — create a dedicated empty directory for the mount point via mkdir -p. Mounting over an existing non-empty directory hides files.
  • Persist mounts in /etc/fstab — ad-hoc mounts are lost on reboot. Add the entry to /etc/fstab and test it with mount -a before relying on it.
  • Test bind mounts on staging first--bind is powerful and easy to misconfigure; validate paths and permissions before applying to production.
  • Use ro for inspection — always mount recovery disks or unfamiliar devices read-only (-o ro) to avoid accidental writes.
  • Pair mount with umount — cleanly unmount (sudo umount TARGET) before detaching any physical or virtual disk.

Tips & Strategy

Verify every mount with two commands
findmnt -T /mnt/backups # confirm the mount is active and shows correct source
df -h /mnt/backups # confirm available space on the newly mounted device

Running both after every mount prevents silent failures where the mount command appeared to succeed but the disk is missing or wrong.

Find the UUID before writing fstab
sudo blkid /dev/sdb1

Copy the UUID from the output and use it in /etc/fstab instead of the device path — this survives disk reordering after a reboot or hardware change.

Test fstab without rebooting
sudo mount -a

After editing /etc/fstab, run mount -a to mount all new entries. If it errors, you can fix the entry before the next reboot causes a failed boot.

Use noatime on busy WordPress sites
sudo mount -o remount,noatime /var/www/html

Adding noatime suppresses the access-time write on every file read, reducing write amplification on high-traffic sites. Add it to the fstab entry for persistence.

Always use --bind after verifying source is mounted

Before bind-mounting uploads to another volume, confirm the source volume is itself mounted:

findmnt /mnt/storage # must show before you bind from it

If the source isn't mounted, the bind will point at an empty directory on the root disk.


Syntax & Options Reference

Core Syntax

mount [OPTIONS] SOURCE TARGET
mount [OPTIONS] -a
mount # list all current mounts
  • SOURCE — the device, UUID, label, or filesystem image to mount.
  • TARGET — the directory (mount point) where the filesystem will be accessible.
  • -a — mount everything listed in /etc/fstab.

Source Formats

FormatExampleWhen to use
Device path/dev/sdb1Quick ad-hoc mounts, known device
UUIDUUID=66666666-7777-8888-9999-000000000000fstab entries, stable across reboots
LabelLABEL=BACKUPWhen you assigned a label with e2label or tune2fs
Loop file/path/to/image.isoMounting ISO images or disk images
NFS shareserver:/export/pathRemote NFS mounts

Complete Options Table

OptionLong FormDescriptionExample
-t TYPE--types=TYPESpecify filesystem type (auto-detected if omitted)mount -t ext4 /dev/sdb1 /mnt/backups
-o OPTIONS--options=OPTIONSComma-separated mount optionsmount -o ro,noatime /dev/sdb1 /mnt/backups
-a--allMount all filesystems listed in /etc/fstabmount -a
--bind--bindBind mount a directory to another locationmount --bind /mnt/storage/uploads /var/www/html/wp-content/uploads
--rbind--rbindRecursively bind mount (includes submounts)mount --rbind /mnt/storage /mnt/mirror
--move--moveMove a mount point to a new locationmount --move /mnt/old /mnt/new
-r--read-onlyMount read-only (same as -o ro)mount -r /dev/sdb1 /mnt/backups
-w--rwMount read-write (default)mount -w /dev/sdb1 /mnt/backups
-n--no-mtabDo not write to /etc/mtabmount -n /dev/sdb1 /mnt
-v--verbosePrint more informationmount -v /dev/sdb1 /mnt/backups
-f--fakeSimulate the mount (dry run)mount -f /dev/sdb1 /mnt/backups
-l--show-labelsShow labels when listing mountsmount -l
--source SRC--source=SRCSpecify source explicitlymount --source /dev/sdb1 /mnt/backups
--target TGT--target=TGTSpecify target explicitlymount --target /mnt/backups
-L LABELMount by filesystem labelmount -L BACKUP /mnt/backups
-U UUIDMount by UUIDmount -U 66666666-7777-... /mnt/backups

Common -o Mount Options

Mount OptionDescriptionExample
roRead-only-o ro
rwRead-write (default)-o rw
noatimeDo not update access time on reads-o noatime
relatimeUpdate atime only if newer than mtime (default on most distros)-o relatime
noexecPrevent execution of binaries on this filesystem-o noexec
nosuidIgnore setuid bits-o nosuid
nodevIgnore device files-o nodev
syncAll I/O is synchronous-o sync
asyncAll I/O is asynchronous (default)-o async
remountRemount with new options without unmounting-o remount,ro
defaultsEquivalent to rw,suid,dev,exec,auto,nouser,async-o defaults
userAllow non-root users to mount-o user
nouserOnly root can mount (default)-o nouser
autoMount automatically with -a-o auto
noautoDo not mount with -a-o noauto

Practical Use Cases

1. List all current mounts

mount-list-current.sh
mount
example-output-mount-list.txt
/dev/sda1 on / type ext4 (rw,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
/dev/sdb1 on /mnt/backups type ext4 (rw,relatime)

Use case: Confirm what is currently mounted, on which device, with which options.


2. Mount a backup disk by device path

mount-backup-disk.sh
sudo mkdir -p /mnt/backups
sudo mount /dev/sdb1 /mnt/backups
findmnt -T /mnt/backups
example-output-mount-backup-disk.txt
TARGET SOURCE FSTYPE OPTIONS
/mnt/backups /dev/sdb1 ext4 rw,relatime

Use case: Attach a dedicated backup disk so backup jobs write to /mnt/backups instead of the root partition.


mount-by-uuid.sh
sudo mount UUID=66666666-7777-8888-9999-000000000000 /mnt/backups
example-output-mount-by-uuid.txt
(no output on success)

Use case: UUID-based mounts survive device reordering across reboots — always prefer this over /dev/sdX paths.


4. Mount by label

mount-by-label.sh
sudo mount -L BACKUP /mnt/backups
example-output-mount-by-label.txt
(no output on success)

Use case: When the disk has a meaningful label set, this is more readable than a raw UUID in scripts and runbooks.


5. Mount read-only for safe inspection

mount-read-only.sh
sudo mount -o ro /dev/sdb1 /mnt/inspect
findmnt -T /mnt/inspect
example-output-mount-ro.txt
TARGET SOURCE FSTYPE OPTIONS
/mnt/inspect /dev/sdb1 ext4 ro,relatime

Use case: Inspect a disk without any risk of writes — essential for recovery scenarios and forensic investigation.


6. Mount with explicit filesystem type

mount-with-fstype.sh
sudo mount -t ext4 /dev/sdb1 /mnt/backups
example-output-mount-fstype.txt
(no output on success)

Use case: Use when auto-detection fails, or to be explicit in runbooks and documentation.


7. Mount with noatime to reduce write amplification

mount-noatime.sh
sudo mount -o noatime /dev/sdb1 /mnt/backups
example-output-mount-noatime.txt
(no output on success)

Use case: Lower unnecessary writes on high-traffic filesystems — effective for the WordPress uploads and cache partitions.


8. Remount with new options (without unmounting)

mount-remount.sh
sudo mount -o remount,ro /mnt/backups
findmnt -T /mnt/backups
example-output-mount-remount.txt
TARGET SOURCE FSTYPE OPTIONS
/mnt/backups /dev/sdb1 ext4 ro,relatime

Use case: Switch a live mount between read-only and read-write without a full unmount cycle.


9. Bind mount (move uploads to a larger volume)

mount-bind-uploads.sh
sudo mkdir -p /mnt/storage/uploads
sudo mkdir -p /var/www/html/wp-content/uploads

# mount the storage volume at /mnt/storage first (device/UUID example omitted)
# then bind it into the WordPress uploads path
sudo mount --bind /mnt/storage/uploads /var/www/html/wp-content/uploads
findmnt -T /var/www/html/wp-content/uploads -o TARGET,SOURCE,FSTYPE,OPTIONS
example-output-mount-bind.txt
TARGET SOURCE FSTYPE OPTIONS
/var/www/html/wp-content/uploads /mnt/storage/uploads ext4 rw,relatime

Use case: Keep WordPress media on a larger disk while the application code stays on the smaller root volume.

caution

Test bind mounts on staging first. Validate permissions and WordPress write access before adding the entry to /etc/fstab.


10. Mount all entries from /etc/fstab

mount-all-from-fstab.sh
sudo mount -a
example-output-mount-a.txt
(no output on success)

Use case: Validate a new /etc/fstab entry or re-mount anything that was skipped at boot — without rebooting.


11. Verbose mount for debugging

mount-verbose.sh
sudo mount -v /dev/sdb1 /mnt/backups
example-output-mount-verbose.txt
mount: /dev/sdb1 mounted on /mnt/backups.

Use case: Confirm the exact device and target when scripting or troubleshooting a suspected silent failure.


12. Simulate a mount (dry run)

mount-fake.sh
sudo mount -f -v /dev/sdb1 /mnt/backups
example-output-mount-fake.txt
mount: /dev/sdb1 mounted on /mnt/backups.

Use case: Verify the command syntax and options are valid before committing a real mount operation.


WordPress VPS Use Cases

SituationWhat you are mountingCommandWhy it matters
Dedicated backup diskBackup disk at /mnt/backupsmount UUID=... /mnt/backupsPrevents backups from filling /
Separate database storageDB volume at /var/lib/mysqlmount UUID=... /var/lib/mysqlLimits blast radius of DB growth
Separate uploads storageUploads via bind mountmount --bind /mnt/storage/uploads /var/www/html/wp-content/uploadsMedia growth does not consume the root disk
Recovery / forensic accessExternal or recovery diskmount -o ro /dev/sdb1 /mnt/recoverSafe inspection without accidental writes

Hands-On Practice

Quick Lab (5 Exercises)

  1. Run mount with no arguments and identify every currently mounted filesystem and its options.
  2. Run lsblk -p -f to list all block devices, their filesystems, and UUIDs.
  3. If you have an unmounted partition, mount it read-only: sudo mount -o ro /dev/sdXN /mnt/test.
  4. Verify the mount with findmnt -T /mnt/test and df -h /mnt/test.
  5. Add the mount to /etc/fstab using the UUID, then test it with sudo mount -a.

Task: Safe Backup Disk Mount

Write the full sequence of commands to safely mount /dev/sdb1 as a backup disk at /mnt/backups, verify it is correct, and confirm space is available.

Solution
safe-backup-mount-sequence.sh
# 1. Confirm the device exists and its filesystem
lsblk -p -f /dev/sdb1
sudo blkid /dev/sdb1

# 2. Create the mount point
sudo mkdir -p /mnt/backups

# 3. Mount using UUID for stability
sudo mount UUID=<uuid-from-blkid> /mnt/backups

# 4. Verify the mount
findmnt -T /mnt/backups

# 5. Confirm available space
df -h /mnt/backups

Mini Quiz

  1. What is the difference between mounting by device path (/dev/sdb1) and by UUID?
  2. Which option mounts a filesystem read-only?
  3. What does mount -a do and when would you use it?
  4. Why should you always run findmnt and df after a mount command?
  5. What is a bind mount and when is it useful for WordPress?
  6. What happens if you mount a device on a non-empty directory?
  7. Which mount option reduces write amplification on busy filesystems?
  8. How do you change mount options on a live filesystem without unmounting it?

Cheat Sheet
mount-cheat-sheet.sh
mount # List all current mounts
lsblk -p -f # List block devices with FS and UUID
sudo blkid /dev/sdb1 # Get UUID and filesystem type
sudo mkdir -p /mnt/backups # Create mount point
sudo mount /dev/sdb1 /mnt/backups # Mount by device path
sudo mount UUID=<uuid> /mnt/backups # Mount by UUID (recommended)
sudo mount -L BACKUP /mnt/backups # Mount by label
sudo mount -t ext4 /dev/sdb1 /mnt/backups # Mount with explicit FS type
sudo mount -o ro /dev/sdb1 /mnt/inspect # Read-only mount
sudo mount -o noatime /dev/sdb1 /mnt/backups # Mount with noatime
sudo mount -o remount,ro /mnt/backups # Remount with new options
sudo mount --bind /mnt/storage/uploads /var/www/html/wp-content/uploads # Bind mount
sudo mount -a # Mount all fstab entries
sudo mount -v /dev/sdb1 /mnt/backups # Verbose output
sudo mount -f -v /dev/sdb1 /mnt/backups # Dry run (fake)
findmnt -T /mnt/backups # Verify mount
df -h /mnt/backups # Check available space

What's Next