munotes®

Mounting

Get access to whole semester resourcesSemester Pass

Chapter One Hundred Two

Syllabus topic Module 2, "File System Interface - File-System Mounting"

Pages 412 to 415 of 452

In one line

Mounting attaches the root of a file system on a device to a chosen directory in the tree already there, so that one tree spans many devices.

What a mount is

A file system must be mounted before any file in it can be used, and mounting means naming the place in the existing tree where its root is to appear. That place is the mount point.

The operating system is givenExample
the device holding the file systema partition such as the vda1 of Chapter ninety three
the mount point: a directory in the tree already mounted/home, or /mnt/backup

What it does before it agrees

StepWhat happens
1ask the device driver to read the device's directory structure, the superblock of Chapter one hundred five
2check that it is a file system of a format the system understands, and that it is consistent
3note in the kernel's own mount table that a file system is mounted at that directory
4from then on, any path that reaches that directory continues into the mounted file system

Step 2 is the reason a mount can fail. A device holding no file system, or one left inconsistent by a crash, is refused. That refusal is a feature: it stops the system reading rubbish as though it were directories.

What happens to what was already there

The question every examiner asks, and there are two answers because systems differ.

PolicyWhat happens
hide the old contentsthe directory's own files become inaccessible for as long as the file system is mounted, and reappear when it is unmounted. Nothing is lost
refuse a non empty mount pointthe mount fails unless the directory is empty, which prevents the surprise

The first is what UNIX does. A file at /mnt/notes.txt is invisible while a file system is mounted at /mnt, and nothing has happened to it: the path now resolves into the other file system.

The same reasoning covers unmounting. A file system that is busy, because some process has a file open in it or has its current directory inside it, cannot be unmounted: the system refuses rather than pull the tree out from under a running program.

Who mounts, and when

PolicyHow it works
at boot, automaticallya table on disk lists devices and their mount points, and the system mounts each one as it starts
on demandthe system mounts a file system the first time a path into it is used, which is how a network file system is often arranged
by handa command, usually restricted to the administrator, because mounting affects every user
munotes.in412

Mounting

Mounting is a privileged operation for a simple reason: whoever mounts a file system chooses the owners and permissions recorded in it, so an ordinary user who could mount could bring a file owned by anybody into the tree.

One tree or many

The design difference worth knowing, because it changes what a path looks like.

SystemHow several devices appear
UNIX and Linuxone tree. Every file system is mounted somewhere inside it, and a path never says which device it is on
Windowsone namespace per volume, named by a drive letter: C: and D: are separate trees, and a path begins with the device
macOSone tree, with removable volumes mounted automatically under a standard directory

The UNIX arrangement means a program never knows or cares which device its file is on, and an administrator can move a directory to a new disk by mounting it in the same place. The Windows arrangement makes the device visible in every path, which is simpler to explain and harder to change.

The lab machine's own tree

Four different file systems, four different types, in one tree, and one of them is not a disk at all.

$ stat -f -c '%n is a file system of type %T' / /proc /sys /dev/shm
/ is a file system of type overlayfs
/proc is a file system of type proc
/sys is a file system of type sysfs
/dev/shm is a file system of type tmpfs
$ awk '$2 == "/proc" || $2 == "/sys" {print $2, "is mounted, and holds a", $3, "file system"}' /proc/mounts
/proc is mounted, and holds a proc file system
/sys is mounted, and holds a sysfs file system
$ test "$(stat -c %d /)" != "$(stat -c %d /proc)" && echo "the root and /proc are on different devices, in one tree"
the root and /proc are on different devices, in one tree

Read the last line first. /proc is on a different device from /, and a path walks from one to the other without saying so. That is mounting doing its work: /proc/self/status, which Chapter eighty read, is a path through two file systems.

The mounted file systemWhat is really behind it
overlayfs at /two directories on the host, layered so that writes go to one of them
proc at /procno storage at all: the kernel makes up the files as they are read
sysfs at /systhe kernel's own objects, which is how Chapter ninety three read the disk's block count
tmpfs at /dev/shmmemory, not disk: files in it disappear when the machine stops

Three of the four store nothing on a disk. Mounting is not a disk operation; it is a namespace operation, and a file system is anything that can answer the file system interface of Chapter one hundred four. That is worth one sentence in an answer about mounting.

munotes.in413

Mounting

Distinctions that carry marks

MountingFormatting
What it doesattaches an existing file system to the treecreates a file system on a device
How oftenevery bootonce
Destroys datanoyes
Mount pointRoot of the mounted file system
Belongs tothe existing treethe new file system
After mountingits own contents are hiddenit is what the path now reaches
UNIXWindows
Several devicesone treeone namespace per volume
A path says which devicenoyes, the drive letter
Moving a directory to another diskmount it in the same placethe paths change

What it does not mean

Mounting does not copy anything. It records where a file system's root is to appear.

A hidden mount point directory is not deleted. Its contents come back when the file system is unmounted.

A file system is not always a disk. On the lab machine three of four are not.

Unmounting is not always possible. A busy file system is refused.

Mounting is not something an ordinary user does. It is privileged, because the mounted file system carries its own owners and permissions.

Quick revision

  • Mounting attaches a file system on a device to a mount point in the tree already there;

nothing in it can be used before that.

  • Before agreeing, the system reads the superblock, checks the format and the

consistency, and records the mount in its mount table.

  • Files already in the mount point directory are hidden while the mount lasts, or the mount

is refused if the directory is not empty. Nothing is lost either way.

  • A busy file system, one with an open file or a process's current directory inside it,

cannot be unmounted.

  • Mounting happens at boot from a table, on demand, or by hand, and it is

privileged because the mounted file system carries its own owners and permissions.

  • UNIX has one tree; Windows has a namespace per volume, named by a drive letter.
  • Measured on the lab machine: / is overlayfs, /proc is proc, /sys is sysfs,

/dev/shm is tmpfs, and / and /proc are on different devices in one tree. Three of the four store nothing on a disk.

Test yourself

  1. What does mounting do? It attaches the root of a file system on a device to a directory,

the mount point, in the tree that is already mounted, so that paths reaching that directory continue into the new file system.

munotes.in414

Mounting

  1. What does the operating system check before it mounts? That the device holds a file system

of a format it understands and that it is consistent, by reading its superblock through the device driver.

  1. What happens to files already in the mount point directory? They become inaccessible while

the file system is mounted and reappear when it is unmounted; some systems instead refuse to mount onto a non empty directory.

  1. Why can a file system be impossible to unmount? Because it is busy: a process has a file

open in it or has its current directory inside it.

  1. Give three policies for when a file system is mounted. Automatically at boot from a table

of devices and mount points; on demand when a path into it is first used; or by hand with a privileged command.

  1. Why is mounting privileged? Because a mounted file system carries its own record of owners

and permissions, so anyone who could mount could introduce files owned by anybody.

  1. How do UNIX and Windows differ in handling several devices? UNIX mounts every file system

into one tree, so a path never names a device; Windows gives each volume its own namespace under a drive letter, so every path begins with the device. 8. The lab machine has four file systems of four types and three store nothing on disk. What does that show about mounting? That it is an operation on the namespace, not on a disk: anything that can answer the file system interface can be mounted, including the kernel's own made up files and a file system in memory.

munotes.in415

The rest of this subject

These notes are cut from the University's printed syllabus. Open the syllabus itself, or the past papers, for the same subject.

Issue
Done!