mount Filesystem

mount cheatsheet — mount filesystems, NFS shares, USB drives. mount /dev/sdb1 /mnt/data, mount -t nfs server:/share /mnt, mount -o ro. Full mount options reference.

6 min read

What it is

mount is a command-line utility used to attach a filesystem to a specific location in your directory tree, making its contents accessible. You reach for mount when you need to access data on a new storage device, partition, or network share.

Installation

mount is a fundamental part of most Unix-like operating systems and is almost always installed by default.

  • Linux: Usually pre-installed. If not, it’s part of the util-linux package.
    sudo apt update && sudo apt install util-linux  # Debian/Ubuntu
    sudo yum install util-linux                     # CentOS/RHEL
    sudo dnf install util-linux                     # Fedora
    
  • macOS: Pre-installed.
  • Windows: Not directly applicable. Windows uses drive letters (C:, D:) and has its own mechanisms for managing mounted volumes.

Core Concepts

  • Mount Point: This is an existing directory in your filesystem tree where the new filesystem will be attached. For example, /mnt or /media/usb.
  • Filesystem Type: The kind of filesystem on the device (e.g., ext4, ntfs, vfat, nfs, cifs, iso9660). mount often auto-detects this, but you can specify it with the -t option.
  • Block Device: The physical or logical device containing the filesystem (e.g., /dev/sda1, /dev/nvme0n1p2, sr0).
  • Remounting: Re-attaching an already mounted filesystem, often to change its options.

Commands / Usage

Mounting Filesystems

  • Mount a device to a directory:

    sudo mount /dev/sdb1 /mnt/data
    

    Attaches the filesystem on /dev/sdb1 to the directory /mnt/data.

  • Mount a device with a specific filesystem type:

    sudo mount -t ntfs /dev/sdc1 /media/windows
    

    Attaches the NTFS filesystem on /dev/sdc1 to /media/windows.

  • Mount a device with specific options:

    sudo mount -o ro,nosuid /dev/loop0 /mnt/iso
    

    Attaches the filesystem on /dev/loop0 to /mnt/iso in read-only (ro) mode and prevents the execution of setuid binaries (nosuid).

  • Mount an ISO image:

    sudo mount -o loop ubuntu-22.04-desktop-amd64.iso /mnt/iso
    

    Mounts the ISO file ubuntu-22.04-desktop-amd64.iso as a loop device at /mnt/iso.

  • Mount a network share (NFS):

    sudo mount nas.example.com:/exports/share /mnt/nfs_share
    

    Mounts the NFS share from nas.example.com:/exports/share to /mnt/nfs_share.

  • Mount a network share (CIFS/SMB):

    sudo mount -t cifs //server.example.com/share /mnt/smb_share -o username=myuser,password=mypass
    

    Mounts the CIFS/SMB share from //server.example.com/share to /mnt/smb_share using provided credentials.

  • Mount a filesystem with automatic type detection:

    sudo mount /dev/nvme0n1p3 /home/user/backup
    

    Attempts to automatically detect the filesystem type on /dev/nvme0n1p3 and mount it to /home/user/backup.

Unmounting Filesystems

  • Unmount a device:

    sudo umount /mnt/data
    

    Detaches the filesystem currently mounted at /mnt/data.

  • Unmount a device by its source:

    sudo umount /dev/sdb1
    

    Detaches the filesystem from /dev/sdb1, regardless of its mount point.

  • Force unmount (use with caution):

    sudo umount -f /mnt/stuck_device
    

    Attempts to force the unmounting of /mnt/stuck_device. This can lead to data loss if the filesystem is actively being used.

  • Lazy unmount (detach now, clean up later):

    sudo umount -l /mnt/slow_network
    

    Performs a lazy unmount of /mnt/slow_network. The filesystem is detached immediately, and cleanup occurs when it is no longer busy.

Viewing Mounted Filesystems

  • List all currently mounted filesystems:

    mount
    

    Displays a list of all active mount points, their sources, types, and options.

  • List only filesystems of a specific type:

    mount -t ext4
    

    Shows only mounted filesystems of type ext4.

  • List mount points for a specific directory:

    mount | grep /home/user
    

    Shows which filesystem (if any) is mounted at or contains /home/user.

Remounting Filesystems

  • Remount to change options (e.g., make read-write):

    sudo mount -o remount,rw /mnt/readonly_drive
    

    Changes the mount options for /mnt/readonly_drive to allow writing (rw).

  • Remount to change options (e.g., disable execution):

    sudo mount -o remount,noexec /dev/loop1 /opt/app
    

    Changes the mount options for /opt/app to prevent execution of binaries (noexec).

Common Mount Options (-o)

  • ro: Read-only.
  • rw: Read-write.
  • defaults: Uses default options (usually rw, suid, dev, exec, auto, nouser, async).
  • auto: Mount automatically at boot or with mount -a.
  • noauto: Do not mount automatically.
  • user: Allow a regular user to mount.
  • nouser: Only root can mount.
  • exec: Allow execution of binaries.
  • noexec: Do not allow execution of binaries.
  • suid: Honor set-user-identifier (SUID) bits.
  • nosuid: Do not honor SUID bits.
  • dev: Interpret character or block special devices.
  • nodev: Do not interpret character or block special devices.
  • sync: Use synchronous I/O.
  • async: Use asynchronous I/O.
  • loop: Used to mount a file as a filesystem (e.g., ISO images).
  • remount: Used to change options on an already mounted filesystem.

Common Patterns

  • Mounting all filesystems defined in /etc/fstab:

    sudo mount -a
    

    This is crucial after editing /etc/fstab to apply the changes without rebooting.

  • Mounting a USB drive automatically: Ensure the device entry is in /etc/fstab with the auto option. Example /etc/fstab line:

    UUID=1234-ABCD  /media/usb_drive  vfat  defaults,auto  0  2
    
  • Mounting a read-only filesystem for safety:

    sudo mount -o ro /dev/sdc1 /mnt/data_backup
    

    Ensures data on /mnt/data_backup cannot be accidentally modified.

  • Mounting a network share and making it writable:

    sudo mount -t cifs //192.168.1.100/shared /mnt/network_share -o username=guest,uid=$(id -u),gid=$(id -g)
    

    Mounts a Windows share, using the guest account, and sets ownership to the current user.

  • Quickly checking if a device is mounted:

    mount | grep /dev/sda1
    

    If there’s output, /dev/sda1 is mounted.

  • Unmounting all filesystems in a specific directory tree:

    sudo umount -R /mnt/large_directory
    

    Recursively unmounts all filesystems nested under /mnt/large_directory. Use with extreme caution.

Gotchas

  • Mount point must exist: The directory you specify as the mount point must already exist before you run the mount command.

    # Incorrect: Mount point doesn't exist
    sudo mount /dev/sdb1 /mnt/new_storage
    
    # Correct: Create the directory first
    sudo mkdir -p /mnt/new_storage
    sudo mount /dev/sdb1 /mnt/new_storage
    
  • Permissions: You typically need root privileges (using sudo) to mount most filesystems. Users can only mount filesystems explicitly allowed for them (e.g., via /etc/fstab with the user option).

  • Busy devices: You cannot unmount a device if any process is currently using files or directories within that mounted filesystem. You’ll get a "target is busy" error. Use lsof | grep /mnt/point or fuser -m /mnt/point to identify the offending processes, then stop them or use umount -f / umount -l cautiously.

  • /etc/fstab errors: Incorrect entries in /etc/fstab can prevent your system from booting correctly. Always double-check syntax and UUIDs/device names. Test changes with sudo mount -a before rebooting.

  • Loop device limitations: Loop devices are virtual block devices that allow you to mount regular files (like ISOs) as filesystems. They are convenient but might have performance implications compared to physical devices.

  • Network filesystem issues: Mounting network shares (NFS, CIFS) depends on network connectivity and server availability. Firewalls can also interfere. Ensure the share path and server are correct.

  • Filesystem corruption: If mount fails with errors related to filesystem inconsistency, the filesystem might be corrupted. You may need to run fsck (e.g., sudo fsck /dev/sdb1) on the unmounted device to repair it. Never run fsck on a mounted filesystem.