Linux online course

How to Mount and Unmount File Systems in Linux

Learn how Linux mounts devices, how to inspect and safely unmount file systems, and how to configure persistent mounts with /etc/fstab.

Linux makes storage available by attaching a file system to the directory tree. This operation is called mounting. Once mounted, the files on a disk, partition, optical disc, or other storage device appear beneath a directory called a mount point.

A device and a mount point are different things. A device is the storage source, such as /dev/sdb1. A mount point is an existing directory, such as /mnt/data, where Linux attaches that file system.

How Linux Mounting Works

Linux uses one directory hierarchy that begins at /. Separate storage devices are not automatically separate directory trees from the user's perspective. Mounting connects a file system to a directory within that hierarchy.

  • Device or partition: The storage source, commonly represented by a path such as /dev/sdb1.
  • File system: The on-disk format, such as ext4, xfs, vfat, exfat, ntfs, or iso9660.
  • Mount point: An existing directory where the file system becomes accessible.

For example, mounting /dev/sdb1 at /mnt/data makes the partition's contents available as /mnt/data/report.txt. The directory itself is not the disk; it is the location used to access the disk.

Any files that were already in a nonempty mount-point directory are hidden while another file system is mounted there. They become visible again after unmounting. For this reason, use an empty directory whenever possible.

View Currently Mounted File Systems

Run mount without arguments to list currently mounted file systems:

mount

A typical line contains the source device, the target directory, the file system type, and mount options. The general shape is similar to:

/dev/sdb1 on /mnt/data type ext4 (rw,relatime)
  • /dev/sdb1 is the source device or partition.
  • /mnt/data is the target mount point.
  • ext4 is the file system type.
  • rw,relatime are mount options. Here, rw means read/write.

Modern tools often make inspection easier:

findmnt
df -h
lsblk -f
sudo blkid /dev/sdb1
  • findmnt displays mounts in a tree-oriented format and can inspect a particular path.
  • df -h reports used and available space in human-readable units.
  • lsblk -f lists disks and partitions with file system types, labels, UUIDs, and mount points.
  • blkid displays identifying information such as a file system's UUID.

Manually Mount a File System

The general form of the mount command is:

sudo mount -t FILESYSTEM_TYPE DEVICE MOUNT_POINT
ElementPurposeExample
mountAttaches a file system, or displays current mounts when used without arguments.mount
-t file_system_typeSpecifies the on-disk file system format.-t ext4
deviceIdentifies the device or partition containing the file system./dev/sdb1
mount_pointSpecifies the existing directory where the file system will appear./mnt/data

The -t option is often optional for common file systems because Linux can usually detect the type:

sudo mount DEVICE MOUNT_POINT

Administrative privileges are normally required. The target directory must exist before mounting.

Create a Mount Point

Use mkdir -p to create the directory and any missing parent directories:

sudo mkdir -p /mnt/data

/mnt is a conventional location for temporary, manually managed mounts. /media is commonly used for removable media. Distribution and organization conventions can differ.

Mount a Disk Partition

After identifying the correct partition with lsblk -f, mount it without explicitly specifying the type:

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
findmnt /mnt/data

If automatic detection is unsuitable, specify the known type:

sudo mount -t ext4 /dev/sdb1 /mnt/data

Do not guess the device name. Device names can change when disks are detected in a different order. Confirm the partition, label, type, and UUID first.

Mount an Optical Disc

An optical drive is often represented by /dev/sr0, and an optical file system commonly uses the iso9660 type:

sudo mkdir -p /mnt/cdrom
sudo mount -t iso9660 /dev/sr0 /mnt/cdrom
ls /mnt/cdrom

Optical media is normally read-only. When finished, unmount it before ejecting the disc.

Unmount a File System Safely

The command is spelled umount, not unmount. You can specify either the mount-point path or the device path:

sudo umount /mnt/data
sudo umount /dev/sdb1

Before unmounting:

  1. Leave the mounted directory in every shell. A shell whose current working directory is inside the mount can keep it busy.
  2. Save files and close applications using the mounted storage.
  3. Stop background jobs that read or write the mount.
  4. Unmount the file system, then safely disconnect or eject the device.

Handle a Busy Mount Point

If a process still has an open file or working directory there, umount may report that the target is busy. Identify users of the mount with:

sudo lsof +f -- /mnt/data
sudo fuser -vm /mnt/data

Close the reported application or change the working directory of the reported shell, then retry:

sudo umount /mnt/data

A busy mount should not be forcibly detached as a first response, because doing so can cause data loss or application errors.

Configure Persistent Mounts with /etc/fstab

/etc/fstab is the system configuration file for predefined file systems. Entries can be processed during boot, and mount -a attempts to mount eligible entries from this file.

Each entry has six standard fields separated by whitespace:

source  mount_point  type  options  dump  fsck_pass
FieldMeaningTypical Example
Source device or UUIDThe file system to mount.UUID=7c2a...
Mount pointThe existing directory where it will be attached./mnt/data
File system typeThe on-disk format.ext4
Mount optionsComma-separated settings controlling mounting behavior.defaults
Dump fieldLegacy backup-dump setting; commonly 0.0
fsck pass fieldOrder for file system checks at boot. Root commonly uses 1; other native file systems commonly use 2.2

Use UUIDs for Stable Device Identification

A UUID is a unique file system identifier. It is usually more stable than a path such as /dev/sdb1, because device names can change with hardware detection order.

Find the UUID and type:

sudo blkid /dev/sdb1

Create the mount point, back up the configuration, and edit the file:

sudo mkdir -p /mnt/data
sudo cp /etc/fstab /etc/fstab.backup
sudoedit /etc/fstab

Add a line like this, replacing the placeholder with the actual UUID:

UUID=<filesystem-uuid> /mnt/data ext4 defaults 0 2

Test the entry before rebooting:

sudo mount -a
findmnt /mnt/data

If mount -a reports an error, correct the entry before restarting the system.

Useful Mount Options

OptionPurposeNotes
defaultsUses a standard set of options.A common starting point for local Linux file systems.
roMounts read-only.Useful when writes must be prevented.
rwMounts read/write.Only works when the file system and device permit writing.
nofailAllows boot to continue if the device is absent or cannot be mounted.Appropriate for nonessential removable or backup devices.
noautoPrevents the entry from being mounted automatically by mount -a or normal boot processing.It can still be mounted explicitly.
userAllows a user to mount the file system under approved conditions.Apply only when suitable for the local security policy.
uid, gid, umaskControls apparent ownership and permissions on file systems that do not store normal Linux ownership metadata.Commonly relevant to formats such as vfat and some removable-media configurations, not generally needed for native ext4.

An optional removable drive might use:

UUID=<filesystem-uuid> /mnt/backup ext4 defaults,nofail 0 2

Common Inspection and Management Commands

CommandUse CaseNotes
mountList current mounts.Also performs manual mounts with suitable arguments.
findmntInspect mounts in a tree-oriented format.Use findmnt /mnt/data for one path.
df -hCheck capacity and free space.Uses human-readable units.
lsblk -fDiscover disks, partitions, types, labels, UUIDs, and mount points.Useful before choosing a device.
blkidDisplay file system identifiers and types.Use sudo blkid DEVICE for a specific device.
mount -aMount eligible entries from /etc/fstab.Useful for testing edits without rebooting.
umountDetach a mounted file system.Use a mount point or device path.

Troubleshooting Mount Problems

Mount Point Does Not Exist

Create the missing directory and retry:

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

Wrong Device or Partition

If expected files are missing or the device path fails, inspect the available storage:

lsblk -f
sudo blkid

Confirm the intended partition, label, UUID, and file system type before mounting.

Unknown or Incorrect File System Type

An unknown type or bad-superblock-style error can mean that the type was specified incorrectly, the required support is unavailable, or the file system has a problem. Check the actual type with lsblk -f or blkid. For common formats, retry without -t, or specify the correct type explicitly. Install the appropriate file system support package when your distribution requires one.

Permission Denied

Use sudo when administrative mounting is required. User-managed mounts should be enabled only through appropriate /etc/fstab options and local security policy. Options such as uid, gid, and umask may be needed for non-native file systems.

Boot Problems After Editing /etc/fstab

Check the UUID, mount-point directory, file system type, option spelling, and all six fields. Test with:

sudo mount -a

Use nofail for optional devices that may be disconnected, but do not use it to conceal an error in an essential mount.

Exam-Relevant Notes

  • Mounting attaches a file system to an existing directory in the Linux directory hierarchy.
  • umount is the correct command name for detaching a file system.
  • The device, such as /dev/sdb1, is not the same as its mount point, such as /mnt/data.
  • mount -t TYPE DEVICE DIRECTORY is the explicit manual-mount form; -t can often be omitted.
  • /etc/fstab has six standard fields: source, mount point, type, options, dump, and fsck pass.
  • mount -a processes eligible /etc/fstab entries.
  • UUIDs are generally preferable to volatile device names in persistent configurations.
  • A busy mount point usually indicates an open file, active application, or shell whose working directory is inside the mount.

Related skills include identifying file types, managing file ownership, and understanding GPT partitions.