Skip to main content

mount Command

The mount command attaches filesystems to the Linux directory tree, making files and directories accessible. It's essential for accessing storage devices, network shares, and special filesystems.

Syntax

mount [options] device directory
mount [options] | directory | device
mount -a [options]

Basic Usage

Mount a device:

mount /dev/sda1 /mnt/data

Mount with specific options:

mount -o ro /dev/sda1 /mnt/data

Mount all filesystems from /etc/fstab:

mount -a

Common Filesystem Types

TypeDescriptionExample
ext4Linux Extended Filesystem 4mount -t ext4 /dev/sda1 /mnt
xfsXFS Filesystemmount -t xfs /dev/sda1 /mnt
ntfsWindows NTFSmount -t ntfs /dev/sda1 /mnt
vfatFAT32/VFATmount -t vfat /dev/sda1 /mnt
iso9660CD/DVD ISOmount -t iso9660 /dev/cdrom /mnt
nfsNetwork File Systemmount -t nfs server:/share /mnt
cifsWindows/Samba Sharemount -t cifs //server/share /mnt
tmpfsTemporary Filesystemmount -t tmpfs tmpfs /tmp
procProcess Informationmount -t proc proc /proc
sysfsSystem Informationmount -t sysfs sysfs /sys

Mount Options

Read/Write Options

OptionDescription
roRead-only
rwRead-write (default)
syncSynchronous I/O
asyncAsynchronous I/O (default)
remountRemount with different options

Filesystem Behavior

OptionDescription
atimeUpdate access time on read (default)
noatimeDon't update access time
relatimeUpdate access time relative to modification
nodiratimeDon't update directory access time

User and Security Options

OptionDescription
userAllow any user to mount/unmount
usersAllow any user to mount, any user to unmount
nouserOnly root can mount (default)
execAllow execution of binaries (default)
noexecDon't allow execution of binaries
suidHonor setuid and setgid bits (default)
nosuidIgnore setuid and setgid bits
devHonor device files (default)
nodevIgnore device files

Performance Options

OptionDescription
defaultsDefault options: rw, suid, dev, exec, auto, nouser, async
autoMount automatically at boot
noautoDon't mount automatically
noatimeImprove performance by not updating access time

Usage Examples

Basic Mounting

Mount hard disk partition:

mount /dev/sdb1 /mnt/backup

Mount USB drive:

mount /dev/sdb1 /media/usb

Mount with read-only access:

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

Mount with specific user:

mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/userdata

Special Mounts

Mount ISO image:

mount -o loop image.iso /mnt/cdrom

Mount swap file as loop device:

mount -o loop /swapfile /mnt/swap

Mount tmpfs in memory:

mount -t tmpfs -o size=1G tmpfs /tmp

Mount with specific filesystem type:

mount -t ext4 /dev/sda1 /mnt/data

Network Mounts

Mount NFS share:

mount -t nfs server:/path/to/share /mnt/nfs

Mount NFS with options:

mount -t nfs -o rsize=8192,wsize=8192 server:/share /mnt/nfs

Mount Windows/Samba share:

mount -t cifs //server/share /mnt/smb -o username=user,password=pass

Mount WebDAV share:

mount -t davfs https://webdav.example.com /mnt/webdav

Remounting

Remount as read-only:

mount -o remount,ro /mnt/data

Remount as read-write:

mount -o remount,rw /mnt/data

Remount with different options:

mount -o remount,noatime /mnt/data

/etc/fstab Configuration

fstab format:

device         mountpoint     fstype     options      dump  pass
/dev/sda1 / ext4 defaults 0 1
/dev/sda2 /home ext4 defaults 0 2

Common fstab entries:

Standard Linux partition:

/dev/sda1      /data          ext4       defaults,noatime 0 2

Windows partition:

/dev/sdb1      /windows       ntfs-3g    defaults,uid=1000,gid=1000 0 0

USB drive:

/dev/sdc1      /media/usb     vfat       defaults,user,utf8,uid=1000,gid=1000 0 0

Network share:

server:/share  /mnt/nfs       nfs        defaults 0 0

Temporary filesystem:

tmpfs          /tmp           tmpfs      defaults,size=2G 0 0

Advanced Options

Bind Mounts

Create bind mount:

mount --bind /source/path /dest/path

Make bind mount read-only:

mount --bind /source/path /dest/path -o ro

Bind mount in fstab:

/source/path   /dest/path     none       bind      0 0

Overlay Mounts

Create overlay filesystem:

mount -t overlay overlay \
-o lowerdir=/lower,upperdir=/upper,workdir=/work \
/merged

Mount by Label or UUID

Mount by label:

mount -L DATA /mnt/data

Mount by UUID:

mount -U 1234-5678 /mnt/data

Find filesystem UUID:

blkid /dev/sda1
ls -l /dev/disk/by-uuid/

Troubleshooting

Common Issues

Device busy:

# Find processes using the mount
lsof /mnt/data
fuser -m /mnt/data

# Force unmount (may cause data loss)
umount -l /mnt/data

Permission denied:

# Check mount point permissions
ls -la /mnt/data

# Mount with specific permissions
mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/data

Unknown filesystem type:

# Install required filesystem drivers
sudo apt-get install ntfs-3g # for NTFS
sudo apt-get install nfs-common # for NFS

Finding Mount Information

List all mounts:

mount
mount | grep /mnt

Show mount details:

findmnt /mnt/data
mount -l | grep /mnt/data

Check available filesystems:

cat /proc/filesystems

List block devices:

lsblk
fdisk -l

Security Considerations

Secure Mounting Options

User data directory:

mount -o noexec,nosuid,nodev /home/user

Temporary directories:

mount -o noexec,nosuid,nodev /tmp
mount -o noexec,nosuid,nodev /var/tmp

Removable media:

mount -o nosuid,nodev,noexec /media/usb

Encryption and Security

Encrypted filesystem:

cryptsetup open /dev/sdb1 crypt_data
mount /dev/mapper/crypt_data /mnt/data

Mount with nosuid for security:

mount -o nosuid /dev/sdb1 /mnt/data

Performance Optimization

SSD Optimization

Mount SSD with noatime:

/dev/sda1      /              ext4       defaults,noatime,discard 0 1

Disable journaling for performance:

mount -o data=writeback /dev/sda1 /mnt/data

Database Optimization

Database data directory:

mount -o noatime,nodiratime,data=writeback /var/lib/mysql

Best Practices

  1. Always use /etc/fstab for permanent mounts
  2. Test mounts first before adding to fstab
  3. Use appropriate options for security and performance
  4. Monitor mount usage with df -h and mount
  5. Backup important data before mounting
  6. Use UUIDs instead of device names in fstab
  7. Test automatic mounts after reboot

Integration with systemd

Mount unit files:

[Unit]
Description=Data Mount
After=network.target

[Mount]
What=/dev/sdb1
Where=/mnt/data
Type=ext4
Options=defaults

[Install]
WantedBy=multi-user.target

Enable mount unit:

systemctl enable mnt-data.mount
systemctl start mnt-data.mount

Content adapted from the linux-command project. Original content available at https://github.com/jaywcjlove/linux-command