Mounting before namespaces

Linux exposes files through a directory tree starting at /. A mount attaches a filesystem to a location in that tree; that location is a mount point.

Added example: a USB filesystem contains photos/ and notes.txt. Mounting it at /data makes /data/notes.txt reach the file on the USB. It does not copy the file into the host’s original /data directory. Unmounting removes that attachment, not the USB’s stored contents. Existing files beneath the mount point are hidden by the attachment rather than automatically deleted.

The doorway analogy is useful: a path is a doorway and the mount determines which storage lies behind it. It is a namespace mapping, not a new physical disk.

What a mount namespace separates

It separates mount arrangements. One environment can mount one filesystem at /data, while another mounts different storage there. A newly created mount namespace initially copies the existing mount list, not all file contents and not an empty filesystem.

Mount-propagation settings matter: shared mounts can propagate mount events. To reason about a private arrangement, assume propagation has been configured appropriately. Namespace creation alone is not a universal guarantee that every later mount event is private. Linux mount namespace manual.

Explain unshare --mount

unshare --mount

The command creates a new mount namespace and, when no program is supplied, starts a shell there. That shell initially sees the inherited mount arrangement. Subsequent appropriately isolated mount changes can differ from the original shell’s arrangement. Only the mount namespace is requested: PID, network and user namespaces are not implicitly separated.

The shell may require suitable privileges. Exiting it returns control to the original shell; namespace lifetime also depends on whether other processes or references keep it alive.

The source’s bind-mount trace

A bind mount exposes an existing directory at another location. PDF page 27 illustrates this inside a new mount namespace:

mount --bind /usr/bin /mnt
/usr/bin --+
          +-- same underlying directory
/mnt -----+

The following operations are source examples for reading, not a recommendation to modify a live host’s system directories:

Action / observationMeaning
Inspect /mnt/bash inside the namespaceReaches the same underlying file as /usr/bin/bash
Create /mnt/testfolderCreates a directory in the underlying /usr/bin directory
Exit to the original shellReturns to the original mount arrangement
Inspect /usr/bin/testfolder thereThe created directory still exists
Inspect /mnt/testfolder thereAbsent in the source setup because the private bind mount is not active in this view

Private mount arrangement does not mean private file contents. If two paths or environments expose the same writable storage, file edits through one can be observed through the other. Removing /mnt/bash in the bind-mounted environment would target the underlying /usr/bin/bash, assuming permission.

findmnt on PDF page 28 displays the mount tree. The additional /mnt entry points into the filesystem’s /usr/bin directory; it appears in the environment with that bind mount. The displayed mixed cgroup mounts and storage layout are source-machine details.

Root directory versus mount arrangement

The slide’s claim that chroot creates an empty filesystem is misleading. chroot(path) changes the calling process’s root for pathname resolution to an existing directory. It does not inherently create, empty or populate storage, and is not a complete security boundary. A mount namespace instead separates mount arrangements. Linux chroot manual.

Retrieval practice

A and B have separate mount namespaces but bind the same directory at different paths. Does editing a file in A leave B’s copy unchanged? There is no separate copy; B can see the same underlying modification, subject to access permissions.

Does unshare --mount start with no files? No. It initially inherits mount arrangements and backing filesystems, then permits a different arrangement.

Does an isolated mount operation make writes private? No. Isolating mount metadata and separating the underlying file data are different jobs.

Lecture 06 - Lightweight Virtualization - Cgroups and Namespaces, PDF pages 26-29. USB/doorway examples, propagation and lifetime qualifications, and the chroot correction are added explanations.