114

I've heard the term "mounting" when referring to devices in Linux. What is its actual meaning? How it handling now unlike older versions?

I haven't done that manually via the command-line. Can you give the steps (commands) for mounting a simple device in Linux?

1

4 Answers 4

144

Unix systems have a single directory tree. All accessible storage must have an associated location in this single directory tree. This is unlike Windows where (in the most common syntax for file paths) there is one directory tree per storage component (drive).

Mounting is the act of associating a storage device to a particular location in the directory tree. For example, when the system boots, a particular storage device (commonly called the root partition) is associated with the root of the directory tree, i.e., that storage device is mounted on / (the root directory).

It's worth noting that mounting not only associates the device containing the data with a directory, but also with a filesystem driver, which is a piece of code that understands how the data on the device is organized and presents it as files and directories.

Let's say you now want to access files on a CD-ROM. You must mount the CD-ROM on a location in the directory tree (this may be done automatically when you insert the CD). Let's say the CD-ROM device is /dev/cdrom and the chosen mount point is /media/cdrom. The corresponding command is

mount /dev/cdrom /media/cdrom

After that command is run, a file whose location on the CD-ROM is /dir/file is now accessible on your system as /media/cdrom/dir/file. When you've finished using the CD, you run the command umount /dev/cdrom or umount /media/cdrom (both will work; typical desktop environments will do this when you click on the “eject” or ”safely remove” button).

Mounting applies to anything that is made accessible as files, not just actual storage devices. For example, all Linux systems have a special filesystem mounted under /proc. That filesystem (called proc) does not have underlying storage: the files in it give information about running processes and various other system information; the information is provided directly by the kernel from its in-memory data structures.

5
  • 1
    @Gilles'SO-stopbeingevil' Why not associate /dev/cdrom directly with the filesystem? Why do you need a new directory for that? Commented Jun 24, 2023 at 21:22
  • 2
    @MehdiCharife Mainly because being able to mount a device at a specific location is part of the requirements. This feature is used for all filesystems, not just for removable devices. For example, if you have /home on a separate device, that really has to appear as /home, not as /dev/sdb1. And there's also the root filesystem, which gets mounted in a special way, but there has to be a way to associate / with a filesystem. Also, many filesystems don't have associated device files, but need a mount point anyway. Commented Jun 25, 2023 at 6:20
  • Thanks lot @Gilles'SO-stopbeingevil' !! Am learning lot better from your answers rather following heavy text. Commented Nov 24, 2023 at 6:04
  • So far I understand /dev/sdb1 device file provides you with interface to read/write to disks, is this correct ? meaning corresponding device driver would have implemented Open/Read/Write system calls. But when you try accessing file via mount point, then this being normal file should interface with appropriate FileSystem driver for Read/Write system calls. Somehow the role of /dev/sdb1 during I/O operation is not clicking to me given I/O operation would be performed on file available through mount point path ? Commented Nov 24, 2023 at 6:04
  • thinking bit more; mount /dev/cdrom /media/cdrom is this like telling OS that files under mount point /media/cdrom is associated with FileSystem driver interfaced via device file /dev/cdrom ? Commented Nov 24, 2023 at 8:41
33

What is meant by mounting a device in Linux?

In simple words a mount point is a directory to access your data (files and folders) stored on your disks.

Analogy: Courtesy

Let us read a farmer story who distributed his uncultivated land to his children and what they did from it.

There is a farmer who thought of distributing his whole barren land of 25 Hectares to his three children, he distributed as below.
enter image description here

Child 1: John got eight hectares of land.

Child 2: Barbie got 13 hectares of land.

Child 3: Steve got four hectares of land.

enter image description here

Now the farmer's children planned to improve their respective lands and started ploughing depending on the crops they were going to cultivate.

  • John wants to cultivate Oranges.

  • Barbi wants to cultivate Mangos.

  • Steve wants to cultivate Corn.

For these crops/fruit tree cultivation they require to plough differently to suite their crops. As shown below diagram for cultivating Mangos ploughing is different from cultivating corn. Once this is done they sow their respective crop plants in their lands.
enter image description here

As crops are grown they should be protected from intruders and they arranged a fence around their lands and created an entry point to each of their lands with a gate.

enter image description here
So if anyone to access their lands they have to enter through these gates and get the fruit’s/corn from the land.

THE ANALOGY OF THIS STORY TO OUR DISK MANAGEMENT IS AS BELOW.

  • Farmers land is equal to entire disk
  • Slices which a farmer gives to his children are called partitions
  • Ploughing land for cultivating crops is called as formatting.
  • Planting trees and crops are called is akin to disks/partitions.
  • Protecting the grown crops and trees by arranging a gate is called mounting.

enter image description here

3
  • 3
    According to the previous answer, mounting is more similiar to a human entering one of the parts of the field, and not protecting by building the fence. Quoting the previous answer: "Mounting is the act of associating a storage device to a particular location in the directory tree." Commented May 9, 2018 at 8:04
  • Poor Steve! At least his corn might be used as future fuel. My question is if manual mounting by a human is still needed on Linux systems? On my Ubuntu distro at least, storage devices are automatically mounted once connected to the appropriate port so I may never actually have to use the mount command
    – goonerify
    Commented Jan 13, 2020 at 23:53
  • Isn’t it the case that the devices and the partitions are visible before being mounted because they do have a name, and that mounting checks that the device/partition being mounted contains a valid file system? This analogous to being able to see and name the fields before installing the gate that allows and defines how you can then walk into that field.
    – Don Slowik
    Commented Jan 1, 2021 at 16:52
3

source

What is meant by mounting a drive? Before your computer can use any kind of storage device (such as a hard drive, CD-ROM, or network share), you or your operating system must make it accessible through the computer's file system. This process is called mounting. You can only access files on mounted media.

Formats and mounting Your computer stores data in specific, structured file formats written on a piece of media (such as a disk or CD-ROM). Your computer must be able to read the format on this media in order to interpret its data properly; if the computer does not recognize the format, it will return errors. Also, forcing your computer to work with corrupted or unrecognized formats will cause it to write data incorrectly, possibly rendering unrecoverable all the files stored on the media.

Mounting ensures that your computer recognizes the media's format; if your computer cannot recognize that format, the device cannot be mounted. When media is successfully mounted, your computer incorporates the media's file system into your local file system, and creates a mount point, a locally available link through which you access an external device. In Windows or Mac OS X, the mount point is represented by a disk or other icon; in Unix or Linux, the mount point is a directory. Most operating systems handle mounting and unmounting for you.

1

Explanation by Analogy

Let's consider the job of the Post Master general of Washington DC.

In the early days, all roads which led to anywhere, lead from PA Avenue outwards. If you wanted to get your mail, your location had to be navigable from PA Avenue; If somebody builds a street off PA avenue, and then builds a house, he must tell me:

"My house is at this GPS location. But in order to get mail, start at PA Avenue, then go to K street, then go to my house"

mount GPS_LocationOfMyHouse to PA Avenue / K street / MyHouse

Mounting is simply the process of telling the post master general where the house is relative to PA Avenue, or in this case, the root path.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .