The Concept of Mounting
In the world of Microsoft Windows, there exists a single directory tree for every storage component. A storage component is considered to be a drive (i.e. CD-ROM, hard drive, thumb drive, et al.) To be specific, when you click on your C: drive in Windows Explorer, the directory structure of that drive is displayed. These are the directoreis that are associated with that drive. When you click on your D: drive (if you have one), a different directory structure is displayed. This new directory structure is specific to the D: drive.
Unix systems have a single directory tree. All accessible storage must have an associated location in this single directory tree.
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).
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). Assuming 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).
Why do we need to mount the CD-ROM if we already have access to it in
/dev/cdrom
?
In other words, why do we need to create a separate "mount point" under
/media/cdrom
? Does this mean that the filesystem in the
CD-ROM is not available if we access it from /dev/cdrom
.
Why does the CD-ROMs filesystem hierarchy "come alive" when we "mount" it?
It is possible to read and/or write /dev/cdrom
(e.g. using
dd
or cat
) but when this done, you are just reading
or writing the raw bytes of the device. That can be useful in various
circumstances (like cloning a partition), but generally we want to see the
directories and files stored on the device.
When you mount a device, you're telling the kernel to use a layer of software (the filesystem driver) to translate those raw bytes into an actual filesystem. Thus mounting a device associates the filesystem on that device to the directory hierarchy.
Determine Partition/Mount a Directory is on
To determine the partition or mount point a specific directory is located or associated with, use the following command:
df -P file/goes/here | tail -1 | cut -d' ' -f 1
Commands
lsblk
Use lsblk
to to list information about all available, or specified, block devices.
In this screen shot, the name of DVD drive is sr0.
Create a directory that will be the mount point for the device sr0.
This is done with the mkdir command. The option -p
, or --parent
option, creates the /mount
directory if it does not exist
already. Ensure you have the proper permissions.
mkdir -p /mount/DVD
mount
Use mount
to mount a filesystem.
Mount the sr0 device to the directory, or mount point. The
-t
option defines the filesystem type. The -o
option, or --options, is used to specify mount options.
mount -t iso9660 -o ro /dev/sr0 /mount/DVD
umount
Use umount
to unmount a filesystem.