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-linuxpackage.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,
/mntor/media/usb. - Filesystem Type: The kind of filesystem on the device (e.g.,
ext4,ntfs,vfat,nfs,cifs,iso9660).mountoften auto-detects this, but you can specify it with the-toption. - 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/dataAttaches the filesystem on
/dev/sdb1to the directory/mnt/data. -
Mount a device with a specific filesystem type:
sudo mount -t ntfs /dev/sdc1 /media/windowsAttaches the NTFS filesystem on
/dev/sdc1to/media/windows. -
Mount a device with specific options:
sudo mount -o ro,nosuid /dev/loop0 /mnt/isoAttaches the filesystem on
/dev/loop0to/mnt/isoin 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/isoMounts the ISO file
ubuntu-22.04-desktop-amd64.isoas a loop device at/mnt/iso. -
Mount a network share (NFS):
sudo mount nas.example.com:/exports/share /mnt/nfs_shareMounts the NFS share from
nas.example.com:/exports/shareto/mnt/nfs_share. -
Mount a network share (CIFS/SMB):
sudo mount -t cifs //server.example.com/share /mnt/smb_share -o username=myuser,password=mypassMounts the CIFS/SMB share from
//server.example.com/shareto/mnt/smb_shareusing provided credentials. -
Mount a filesystem with automatic type detection:
sudo mount /dev/nvme0n1p3 /home/user/backupAttempts to automatically detect the filesystem type on
/dev/nvme0n1p3and mount it to/home/user/backup.
Unmounting Filesystems
-
Unmount a device:
sudo umount /mnt/dataDetaches the filesystem currently mounted at
/mnt/data. -
Unmount a device by its source:
sudo umount /dev/sdb1Detaches the filesystem from
/dev/sdb1, regardless of its mount point. -
Force unmount (use with caution):
sudo umount -f /mnt/stuck_deviceAttempts 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_networkPerforms 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:
mountDisplays a list of all active mount points, their sources, types, and options.
-
List only filesystems of a specific type:
mount -t ext4Shows only mounted filesystems of type
ext4. -
List mount points for a specific directory:
mount | grep /home/userShows 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_driveChanges the mount options for
/mnt/readonly_driveto allow writing (rw). -
Remount to change options (e.g., disable execution):
sudo mount -o remount,noexec /dev/loop1 /opt/appChanges the mount options for
/opt/appto prevent execution of binaries (noexec).
Common Mount Options (-o)
ro: Read-only.rw: Read-write.defaults: Uses default options (usuallyrw,suid,dev,exec,auto,nouser,async).auto: Mount automatically at boot or withmount -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 -aThis is crucial after editing
/etc/fstabto apply the changes without rebooting. -
Mounting a USB drive automatically: Ensure the device entry is in
/etc/fstabwith theautooption. Example/etc/fstabline: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_backupEnsures data on
/mnt/data_backupcannot 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/sda1If there’s output,
/dev/sda1is mounted. -
Unmounting all filesystems in a specific directory tree:
sudo umount -R /mnt/large_directoryRecursively 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
mountcommand.# 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
rootprivileges (usingsudo) to mount most filesystems. Users can only mount filesystems explicitly allowed for them (e.g., via/etc/fstabwith theuseroption). -
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/pointorfuser -m /mnt/pointto identify the offending processes, then stop them or useumount -f/umount -lcautiously. -
/etc/fstaberrors: Incorrect entries in/etc/fstabcan prevent your system from booting correctly. Always double-check syntax and UUIDs/device names. Test changes withsudo mount -abefore 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
mountfails with errors related to filesystem inconsistency, the filesystem might be corrupted. You may need to runfsck(e.g.,sudo fsck /dev/sdb1) on the unmounted device to repair it. Never runfsckon a mounted filesystem.