mount command in Linux with Examples - GeeksforGeeks (2024)

  • Read

  • Improve

    All files in a Linux filesystem are arranged in form of a big tree rooted at ‘/‘.These files can be spread out on various devices based on your partition table, initially your parent directory is mounted(i.e attached) to this tree at ‘/‘, others can be mounted manually using GUI interface(if available) or using mount command.
    mount command is used to mount the filesystem found on a device to big tree structure(Linux filesystem) rooted at ‘/‘. Conversely, another command umount can be used to detach these devices from the Tree.

    Syntax:

    mount -t type device dir

    Other forms:

    mount [-l|-h|-V]mount -a [-fFnrsvw] [-t fstype] [-O optlist]mount [-fnrsvw] [-o options] device|dirmount [-fnrsvw] [-t fstype] [-o options] device dir

    These commands tells the Kernel to attach the filesystem found at device to the dir.

    Note:

    • If you leave the dir part of syntax it looks for a mount point in /etc/fstab.
    • You can use –source or –target to avoid ambivalent interpretation.
      mount --target /mountpoint
    • /etc/fstab usually contains information about which device is need to be mounted where.
    • Most of the devices are indicated by files like /dev/sda4, etc. But it can be different for certain filesystems. Please refer below for more information.
      man mount

    Note: It is important to note that we are only discussing the standard form of mount command given as syntax. Different forms are somewhat discussed because it has certain limitations on different kernels.

    Some Important Options:

    • l : Lists all the file systems mounted yet.
    • h : Displays options for command.
    • V : Displays the version information.
    • a : Mounts all devices described at /etc/fstab.
    • t : Type of filesystem device uses.
    • T : Describes an alternative fstab file.
    • r : Read-only mode mounted.

    Examples:

    • Displays information about file systems mounted:

      mount command in Linux with Examples - GeeksforGeeks (1)

    • Mounts file systems:

      mount command in Linux with Examples - GeeksforGeeks (2)

    • Displays version information:

      mount command in Linux with Examples - GeeksforGeeks (3)

    • Unmounts file systems:

      mount command in Linux with Examples - GeeksforGeeks (4)

    Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


    Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.

    Last Updated : 23 May, 2019

    Like Article

    Save Article

    Share your thoughts in the comments

    Please Login to comment...

    mount command in Linux with Examples - GeeksforGeeks (2024)

    FAQs

    What is mount in Linux with example? ›

    In Linux, the mount command is used to attach (or mount) a file system (a storage device eg. USB flash drive or hard disk) to a specified directory(eg. /usr/local) in the file system hierarchy. This makes the files and directories of the mounted device accessible to the user and the system.

    How to mount a file in Linux? ›

    Mounting a File System on Linux, Red Hat, or CentOS
    1. Log into the instance where you want to mount the file system. ...
    2. Install the NFS client using this command: sudo yum install nfs-utils.
    3. Create a directory that will be used as the mount point. ...
    4. Mount the file system. ...
    5. View the mounted file system.
    Nov 21, 2023

    How do I list all mounts in Linux? ›

    In Linux, you can use the mount, mount -l, and cat /proc/mounts commands to list all mount points.

    What is mounting in Linux explain in brief? ›

    Mounting makes file systems, files, directories, devices, and special files available for use at a particular location. It is the only way a file system is made accessible. The mount command instructs the operating system to attach a file system at a specified directory.

    What is mount point in Linux in simple words? ›

    A mount point can be simply described as a directory to access the data stored in your hard drives. In more specific terms, a mount point is a (usually empty) directory in the currently accessible filesystem on which an additional filesystem is mounted (attached).

    How to use mount command in Linux? ›

    The basic usage of the mount command involves specifying the device and the mount point. The device is the file system you want to access, and the mount point is the directory where you want the file system to be accessible. In this example, '/dev/sdb1' is the device, and '/media/usb' is the mount point.

    How to use mount Linux? ›

    Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command.

    When to use mount Linux? ›

    The mount command is utilized when you need to access files or directories from a device (like a hard drive, CD-ROM, or network location) on your system. It's especially useful for accessing partitions on a hard disk, external storage devices, or file systems on remote machines.

    Where do I mount in Linux? ›

    The classic directory for permanent mount points is /mnt , for example sudo mkdir /mnt/exthdd and use that as a mountpoint. /mnt is for internal disks. /media for external.

    How do I mount a Linux folder in Linux? ›

    Some commonly used options are:
    1. loop – mount as a loop device.
    2. rw – mount the filesystem read-write (default)
    3. ro – mount the filesystem read-only.
    4. iocharset=value – character to use for accessing the filesystem (default iso8859-1)
    5. noauto – the filesystem will not be mounted automatically during system boot.
    Mar 18, 2024

    How do I mount a specific user in Linux? ›

    4. Using Specific User Rights. In Linux, we can mount a device with specific user rights by using the mount command with the -o option. The -o flag allows us to specify various mount options, including the user and group that should have access to the mounted device.

    How to check mount status in Linux? ›

    Using the findmnt Command

    Yes, the "findmnt" command is another way to check if a directory is a mount point on a Linux system. To check a specific mount point, you can use the -T option followed by the path to the mount point.

    What are the different types of mounts in Linux? ›

    There are two types of mounts, a remote mount and a local mount. Remote mounts are done on a remote system on which data is transmitted over a telecommunication line. Remote file systems, such as Network File System (NFS), require that the files be exported before they can be mounted.

    How do I mount multiple files in Linux? ›

    Example /etc/fstab entries to mount three filesystems, each with a different config directory. Note: To add other mount options, you can add them after the config directory separated by comma. Here is an entry using an additional mount option ( mt ).

    What happens when you mount in Linux? ›

    In Linux, "mounting" just associates the FS with the path, and will mark the underlying device as in-use.

    Why is mount command used? ›

    The mount command instructs the operating system to make a file system available for use at a specified location (the mount point). In addition, you can use the mount command to build other file trees made up of directory and file mounts.

    Top Articles
    Latest Posts
    Article information

    Author: Amb. Frankie Simonis

    Last Updated:

    Views: 6052

    Rating: 4.6 / 5 (76 voted)

    Reviews: 83% of readers found this page helpful

    Author information

    Name: Amb. Frankie Simonis

    Birthday: 1998-02-19

    Address: 64841 Delmar Isle, North Wiley, OR 74073

    Phone: +17844167847676

    Job: Forward IT Agent

    Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

    Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.