Mounts
Most important commands to remember
findmnt -T PATH— find the filesystem serving a path.mount— attach a filesystem to a directory.umount— detach it. The command is spelledumount, not “unmount”.
Commands and flags
These commands appear in the short example below.
| Command or option | Meaning |
|---|---|
mktemp -d |
Create a uniquely named temporary directory. |
sudo mount -t tmpfs -o size=1M tmpfs "$mount_dir" |
Mount a temporary filesystem at the saved directory. sudo supplies administrator privileges, -t selects its type, and -o supplies mount options. |
size=1M |
Limit this tmpfs to 1 MiB: 1,024 × 1,024 bytes. |
findmnt -T "$mount_dir" -o TARGET,SOURCE,FSTYPE |
-T selects a path; -o selects mount point, source, and filesystem type as output columns. |
sudo umount "$mount_dir" |
Detach the temporary filesystem. |
rmdir "$mount_dir" |
Remove the directory, but only if it is empty. |
Bash syntax: mount_dir=$(…) saves a command’s output; "$mount_dir" inserts the saved path as one argument. The two uses of -o have different meanings: mount settings for mount, output columns for findmnt.
The concepts that matter
1. Mounting connects a filesystem to a path
Linux presents files through one directory tree starting at /. A mount makes a filesystem accessible at a directory in that tree, its mount point.
If you can see Linux directories, a root filesystem is already mounted at /. Directories such as /home, /etc, and /var can all belong to that one filesystem; each directory does not need its own mount. Creating an ordinary directory simply adds it to the filesystem that already contains its parent directory.
For example, a separate filesystem mounted at /data supplies the files accessed below /data. The path is where you access storage; it is not itself a disk.
2. Mounting changes what is visible
Mounting does not copy files into a directory. It attaches another filesystem there. Existing contents underneath that mount become hidden through that path and reappear after unmounting.
This matters when an expected mount is missing: an application might write into the underlying directory instead. The pathname alone does not prove that data is reaching the intended storage.
3. A filesystem does not have to live on a disk
A mount can expose disk storage, a remote filesystem, or memory-backed storage. tmpfs keeps file contents in virtual memory, normally RAM, and can use swap.
Its contents are temporary. In this example, unmounting discards the tmpfs contents. The size option sets a ceiling; it does not allocate that amount of RAM immediately. Creating a mount also does not automatically configure it to return after reboot.
4. Unmounting detaches access, not necessarily data
Unmounting a disk filesystem does not erase its stored files. It detaches that filesystem from the directory tree. Temporary filesystems such as this tmpfs have a different lifetime.
An unmount can report “target is busy” if a process is using the filesystem, for example through an open file or current directory. Finish that use before retrying. Applications and open resources matter as well as paths.
One small example
Optional: use a Linux VM that permits mounts and one Bash terminal. Stay outside the temporary directory and run each line separately. If creation or mounting fails, resolve the error before continuing.
mount_dir=$(mktemp -d)
sudo mount -t tmpfs -o size=1M tmpfs "$mount_dir"
findmnt -T "$mount_dir" -o TARGET,SOURCE,FSTYPE
sudo umount "$mount_dir"
rmdir "$mount_dir"
In findmnt, look for your temporary directory as TARGET and tmpfs as both SOURCE and FSTYPE. Source identifies what is mounted; type identifies how it is implemented. Here the source is a label, not a disk device.
Successful mounting, unmounting, and directory removal normally print nothing. The last two lines are cleanup: run the removal only after unmounting succeeds. No files are written and no persistent mount configuration is created.
Keep this idea: a path tells you where you access data; findmnt tells you which filesystem supplies it.