Skip to main content

Command Palette

Search for a command to run...

Cheatsheet & Examples: mount

Updated
4 min read
H

I am a developer from Malaysia. I work with PHP most of the time, recently I fell in love with Go. When I am not working, I will be ballroom dancing :-)

The mount command is used to attach a storage device or file system to a specific point (directory) in the existing file system, making its contents accessible. It essentially integrates a storage device or network share into your computer's directory structure.

Mounting a Device (Most Common)

Example Usage: mount /dev/sdb1 /mnt/mydrive

What it does: This mounts the first partition of the second SCSI drive (or the first SATA drive, if no SCSI drives are present) at the /mnt/mydrive directory, allowing you to access its contents through that directory.

Command-line Arguments Explained:

  • /dev/sdb1: Specifies the device to mount. This is the device node representing the storage partition. The device naming convention uses /dev/ followed by a device identifier (e.g., sda, sdb for SATA drives; hda, hdb for older IDE drives) and a partition number (e.g., 1, 2, 3). Listing devices and partitions can be done using the lsblk or fdisk -l commands.
  • /mnt/mydrive: Specifies the mount point, the directory where the contents of the device will be accessible. /mnt is a common directory for temporarily mounting file systems. The directory must exist before running this command.

Mounting a File System Specifying Type

Example Usage: mount -t ext4 /dev/sdb1 /mnt/mydrive

What it does: This mounts the first partition of the second SCSI drive (or the first SATA drive, if no SCSI drives are present) at the /mnt/mydrive directory, but explicitly specifies that the file system type is ext4.

Command-line Arguments Explained:

  • -t ext4: Specifies the file system type. ext4 is a commonly used file system. Other options include ext3, vfat, ntfs, iso9660 (for CD-ROM/DVD images), nfs (for network file systems), etc.
  • /dev/sdb1: Specifies the device to mount. This is the device node representing the storage partition.
  • /mnt/mydrive: Specifies the mount point.

Mounting a Read-Only File System

Example Usage: mount -o ro /dev/sr0 /mnt/cdrom

What it does: This mounts a CD-ROM drive (represented by /dev/sr0) at the /mnt/cdrom directory in read-only mode.

Command-line Arguments Explained:

  • -o ro: Specifies mount options. ro stands for read-only, which prevents any writes to the mounted file system.
  • /dev/sr0: Specifies the device to mount, typically a CD-ROM or DVD drive.
  • /mnt/cdrom: Specifies the mount point.

Mounting with Specific Permissions and User/Group Ownership

Example Usage: mount -o uid=1000,gid=1000,umask=002 /dev/sdb1 /mnt/mydrive

What it does: This mounts /dev/sdb1 to /mnt/mydrive and sets the user ID and group ID of the mount to 1000 and applies a umask of 002.

Command-line Arguments Explained:

  • -o uid=1000: Sets the user ID (UID) of the owner of all files on the mounted file system to 1000. This is useful for controlling file permissions, giving the specified user access to the mounted content.
  • -o gid=1000: Sets the group ID (GID) of the owner of all files on the mounted file system to 1000.
  • -o umask=002: Sets the file creation mask (umask), which affects the default permissions of new files and directories created on the mounted file system. The 002 umask means that group write permission will be disabled for any newly created file on the mounted volume.
  • /dev/sdb1: Specifies the device to mount.
  • /mnt/mydrive: Specifies the mount point.

Mounting a Network Share (NFS)

Example Usage: mount -t nfs 192.168.1.100:/share /mnt/networkshare

What it does: This mounts an NFS (Network File System) share located at the IP address 192.168.1.100 and exported as /share to the local /mnt/networkshare directory.

Command-line Arguments Explained:

  • -t nfs: Specifies that the file system type is NFS.
  • 192.168.1.100:/share: Specifies the network share. This is the IP address or hostname of the server and the path of the shared directory on the server, separated by a colon.
  • /mnt/networkshare: Specifies the local mount point.

Mounting an ISO Image

Example Usage: mount -t iso9660 -o loop /path/to/image.iso /mnt/iso

What it does: This mounts an ISO image file (typically a CD-ROM or DVD image) as a file system, allowing you to access its contents. The -o loop option allows the image to be mounted as a loop device.

Command-line Arguments Explained:

  • -t iso9660: Specifies that the file system type is iso9660, the standard file system for CD-ROMs.
  • -o loop: The loop option tells mount to associate the image file with a loop device. This enables mounting a file as if it were a block device.
  • /path/to/image.iso: Specifies the path to the ISO image file.
  • /mnt/iso: Specifies the mount point.

Listing Currently Mounted File Systems

Example Usage: mount

What it does: This command, without any arguments, displays a list of all currently mounted file systems, along with their types, options, and mount points.

Command-line Arguments Explained:

  • None: The command takes no specific arguments for this use case.

More from this blog

Hong's Tech Blog

110 posts

The blog is older than you know. I prefer counting from the emergence of one integral anomaly to the emergence of the next, in which case this is the forth version.