This blog post introduces VFS and FHS in Linux.

File System
A file system is one of the most important features of an OS, determining how files are organized and accessed. Without a file system, we would need to manually allocate space in memory buffers and storage, and dereference pointers for reading and writing files. A Unix-like file system can also access metadata (e.g., name, size, access permissions) stored in an index node, or inode, allowing files to be organized, searched, and accessed efficiently (often by using B(+) Trees! Check out Road to C++ Programmer #14 - B(+) Trees if you are interested).
Mounting is another key task handled by the file system, making files on external devices accessible in a specific directory (the mount point). Many different file systems have been developed, including ext4, XFS, and HFS, and some of them also keep a history of file modifications in a journal to enable file recovery in extenuating circumstances.
Linux supports various file systems and provides a Virtual File System (VFS) that offers system calls, acting as a shared interface to the userspace, for interacting with different file systems. VFS also organizes all files from different devices as if they reside within a single hierarchy under the root directory. Almost all Linux distributions, including Ubuntu, adhere to specific rules regarding file locations in the hierarchy, known as the Filesystem Hierarchy Standard (FHS).
Filesystem Hierarchy Standard
The FHS is a powerful standard that allows users to switch between different Unix-like operating systems without needing to learn where important files are located. As Linux users, it’s essential to understand FHS and work with various directories and files as intended. Below is a table summarizing the hierarchy and the purpose of each directory.
Directory | Usage |
---|---|
/ | The root directory at the top of the hierarchy. |
/bin | Contains essential commands (binaries) like cat , ls , and cp . |
/boot | Stores all the boot loader files. |
/dev | Holds devices as files. Files can be discarded by moving them to /dev/null . |
/etc | Initially meant "etcetera" but now understood as "editable text configuration," storing various system-wide configuration files. |
/home | Stores user home directories (excluding root). Users typically work within their own home directories. (.bash_profile for environment variables and .bashrc for aliases, etc.) |
/lib | Contains libraries required for essential commands in /bin . |
/media | Serves as a mount point for media like USB drives. |
/mnt | Used as a temporary mount point for a filesystem. |
/opt | Holds optional add-on software application packages. |
/proc | Contains files created by VFS that display process and kernel information. |
/root | The home directory for the root user. |
/run | Stores files related to the running system since the last boot, such as currently logged-in users and running daemons. |
/sbin | Holds essential system binaries, usually runnable only by root. |
/srv | Contains files for site-specific data served by the system, such as scripts, web servers, and version control repositories. |
/sys | Holds files regarding devices, drivers, and kernel features. Unlike /dev , it is more for monitoring than for access. |
/tmp | Stores temporary files that often aren't preserved after a reboot. |
/usr | Contains read-only user data, including user-installed software and utilities. Subdirectories like /usr/bin , /usr/lib , and /usr/local correspond to non-essential binaries, necessary libraries, and binaries or data specific to the host. |
/var | Holds files (variables) that continually change, such as logs and cache data. |
It’s worth noting that some aspects of FHS are subject to interpretation. For example,
opinions vary on the difference between /opt
and /usr/local
(I interpret /opt
as being for third-party software and /usr/local
as for in-house software).
While adhering to FHS isn’t always mandatory, diverging from it too much can lead to issues, such as permission conflicts.
Even if you're new to the OS and unfamiliar with the terms in the table above, you can always return to this article later as we cover key concepts in upcoming articles. For now, just know that Linux has a VFS that treats everything like a file and an FHS that organizes these files in a structured way.
Conclusion
In this article, we covered the concept of file systems, how Linux uses VFS to handle multiple file systems, and how Unix-like OS typically employs FHS to organize directories and files. I recommend exploring these directories using commands covered in previous articles to practice and gain a better understanding of their purposes.
Sources
- Linux Journey. n.d. The Filesystem. Linux Journey.
- Kamimori, K. 2018. Linuxのファイルシステムについて. Qiita.