After talking on the Linux File Types in the previous entries, is time to learn the basic on mounting linux file systems. For the data contained on hard disks, disk partitions, network drives, and removable media to be accessed under Linux, it is necessary to attach – or mount – the devices containing the data to the Linux directory structure. The reason for this is that Linux treats every device or partition as a separate and independent file system. It also views all data as though it were in a subdirectory of the root (/) directory, regardless of the kind of device on which it is stored – even when it is kept on a separate computer.
It is an important part of the role of the Linux system administrator to ensure that file systems are mounted correctly, whether at boot time or manually, to ensure that all required data is available at the expected locations.
Advantages of mounting Linux file systems and devices
Devices are mounted at predetermined directories below the root file system. These are usually, although not always, special directories created for the purpose. The file systems that belong under the /var, /home, and /usr directories, for example, are kept on separate partitions or devices from the root file system. Network machines are frequently configured so that the /home data for all machines is actually stored on a single Network File System (NFS) server, which is then mounted under the /home directory on each individual machine. This enables users to access their own home directories in the usual locations, regardless of which computers they are actually logged on at.
Because all devices and file systems appear below the root directory, the transition from one device or file system to another is entirely seamless. So a user can access a file on an NFS server over a network as though the file were on the local hard drive.
Linux makes it easy to expand the space available to overloaded file systems by mounting new partitions. For example, say the directory /home/project is filling up with so much data that it threatens to take over the hard drive on which it is stored. The system administrator can easily move the data from the existing /home/project to an empty disk partition with more available space, and remount the new partition at /home/project. To users, there won’t be a difference between the old configuration and the new one – they still access their files under /home/project, even though the files are now stored on a completely different hard drive.
It is important to mount file systems in the correct order. This is sometimes necessary to ensure that the mount point required by a given file system exists and is available when the mount command is issued. Taking the /home/project example again, the project data exists on one disk partition and all the remaining /home data is on another, including the /home/project directory under which the /home/project partition is to be mounted. Clearly, if an attempt is made to mount the /home/project partition before the /home partition, this will result in an error, as the /home/project directory doesn’t yet exist. The correct order is to mount the /home partition first, followed by the /home/project partition.
It is also important to be aware when mounting devices under a given directory that any files previously available under that directory will be hidden while the device is mounted. So any files that still remain in the /home/project directory of the /home partition will become invisible as soon as the /home/project partition is mounted in that directory. Furthermore, the disk space those files occupy will remain unavailable to the system until the project partition is unmounted. You should therefore check what already exists in a directory before you use it as the mount point for some other file system, to avoid duplicating files or wasting disk space.
File system mounting management
To assist in the management of file system mounting, a special directory called /mnt exists in most Linux distributions. This directory contains dedicated directories for mounting specific devices such as CD-ROM, floppy disk, and zip disk drives. This is a convenient way to ensure that such devices have a suitable mount point available to them at all times.
Removable media
It is impossible to access the data on removable media without mounting them first. To use a floppy disk drive, for example, you need to issue the mount command before the disk contents will be visible to the system.
Similarly, when you have finished using any kind of removable medium, it is very important to unmount the device using the umount command before removing the disk from the drive. This is because Linux improves efficiency by often storing information in memory buffers rather than writing it directly to the disk. If a removable disk is removed without being unmounted first, there is a high probability of data loss, just as there is from a hard drive if you shut down the system by turning off the power without running the proper shutdown procedure.
I always love this part in Linux, but not so good in setting up the NFS mount point. Usually I rely on Storage Engineer on this 🙂