Linux Mount Command Guide
Understanding the Mount Command
The mount command in Linux is a fundamental utility
used to attach a file system to a specific directory in the
directory tree. This allows users to access files and directories on
different storage devices or network locations as if they were part
of the local file system. Mastering the mount command
is crucial for system administration and advanced command-line
usage.
Common Mount Command Examples
Here are several practical examples of how to use the
mount command for various scenarios:
Remounting a File System as Read-Write
To remount the root file system (/) as read-write,
especially in a repair mode:
mount -o remount,rw /
Bind Mounting a Directory
Bind mounting allows you to make a directory or a file available at another location. This is useful for creating symbolic links that work at the file system level or for organizing your file system.
mount --bind <source> <destination>
Replace <source> with the path to the directory
or file you want to mount, and <destination> with
the path where you want it to appear.
Mounting a USB Disk for User Write Access
To mount a USB disk (e.g., /dev/sdx) to a specific
mount point (e.g., /mnt/xxx) and grant write
permissions to a particular user and group:
mount -o uid=username,gid=usergroup /dev/sdx /mnt/xxx
Ensure you replace username and
usergroup with the actual username and group ID, and
/dev/sdx with the correct device name for your USB
drive.
Mounting a Remote NFS Directory
To mount a directory shared via NFS from a remote host:
mount -t nfs <host>:<remote-dir> <local-dir>
Here, <host> is the IP address or hostname of the
NFS server, <remote-dir> is the exported
directory on the server, and <local-dir> is the
directory on your local machine where you want to mount it.
Mounting an ISO Image
ISO images can be mounted as loop devices to access their contents as if they were a physical CD/DVD.
mount -o loop disk1.iso /mnt/disk
This command mounts the disk1.iso file to the
/mnt/disk directory.