Understanding the mount Command in Linux (With Examples)

Mounting is a core concept in Linux, allowing users to attach filesystems to a directory tree so they can be accessed like any other directory. The mount command is the gateway to this process, enabling access to different storage devices, network shares, and special virtual filesystems.

In this article, we’ll dive into the basics of the mount command, discuss its options, and walk through several practical examples.

What Is the mount Command?

In Linux, all files and directories exist under a single hierarchical directory structure known as the filesystem. Devices such as hard drives, USB sticks, or remote filesystems must be “mounted” to a directory (mount point) before they can be accessed.

The mount command attaches a filesystem on a device to a specified directory so it becomes part of the main filesystem tree.

Syntax

mount [OPTIONS] DEVICE MOUNT_POINT
  • DEVICE – The device or filesystem to mount (e.g., /dev/sdb1).
  • MOUNT_POINT – The directory where the filesystem will be mounted (e.g., /mnt/usb).
  • OPTIONS – Optional flags to control behavior (e.g., -t, -o, etc.).

Basic Examples

1. Mounting a USB Drive

Assume you plug in a USB drive and it’s assigned as /dev/sdb1.

sudo mount /dev/sdb1 /mnt/usb

Now, contents of the USB drive will be available at /mnt/usb.

Tip: Always create the mount point directory if it doesn’t exist:

sudo mkdir -p /mnt/usb

2. Mounting with Filesystem Type

Specifying the filesystem type (e.g., vfat for FAT32, ext4, ntfs) can help ensure correct mounting:

sudo mount -t vfat /dev/sdb1 /mnt/usb

Viewing Mounted Filesystems

To see all currently mounted filesystems:

mount

Or use:

findmnt

Or the more modern:

lsblk -f

Unmounting a Filesystem

When you’re done, unmount it using umount (yes, it’s umount, not unmount):

sudo umount /mnt/usb

If the device is busy (used by a process or shell), it won’t unmount until the resource is free.

Useful Options with mount

1. Mounting Read-Only

sudo mount -o ro /dev/sdb1 /mnt/usb

2. Mounting with Specific User Permissions

Useful for FAT/NTFS filesystems:

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

Replace 1000 with your actual user and group IDs (you can get them with id command).

Mounting ISO Images

Mount an ISO file without burning it to a disk:

sudo mount -o loop file.iso /mnt/iso

Mounting a Network Share (NFS or CIFS)

NFS Example:

sudo mount -t nfs 192.168.1.100:/share /mnt/nfs

SMB/CIFS (Windows Share) Example:

sudo mount -t cifs -o username=youruser,password=yourpass //192.168.1.200/shared /mnt/windows

Automatically Mounting at Boot

To make a mount persistent across reboots, you can add it to /etc/fstab:

Example entry for a USB drive:

/dev/sdb1  /mnt/usb  vfat  defaults  0  0

Or using UUID for more reliable mounting:

UUID=1234-5678 /mnt/usb vfat defaults 0 0

Find UUIDs with:

blkid

Conclusion

The mount command is an essential Linux tool that provides powerful control over storage access and organization. From temporary USB drives to permanent network shares, knowing how to mount (and unmount) devices properly is key to managing a Linux system effectively.

Whether you’re a beginner or an experienced sysadmin, mastering mount makes your Linux environment more flexible and robust.

Leave a Reply

Your email address will not be published. Required fields are marked *