Linux Filesystem Hierarchy Standard Explained
The Filesystem Hierarchy Standard (FHS) is a reference specification that defines the directory structure and directory contents in Linux and other Unix-like operating systems. This article provides a clear, concise overview of what the FHS is, why it was established, and the specific roles of the primary directories located within the root filesystem. Understanding this layout allows system administrators, developers, and users to navigate, manage, and troubleshoot any standardized Linux distribution effectively.
What is the Filesystem Hierarchy Standard?
Maintained by the Linux Foundation, the Filesystem Hierarchy Standard establishes a predictable layout for files and directories. Prior to standardizing this structure, different Unix-like distributions often stored configuration files, executables, and libraries in varying locations. The FHS eliminates this fragmentation by ensuring that software developers, system administrators, and users can rely on consistent file locations across various Linux distributions, such as Ubuntu, Fedora, Debian, and CentOS.
The standard categorizes files along two main axes:
- Shareable vs. Unshareable: Shareable files can be stored on one host and used on another (e.g., user home directories or application libraries), whereas unshareable files are unique to a specific system (e.g., bootloader configurations or lock files).
- Static vs. Variable: Static files remain unchanged without direct administrator intervention (e.g., binaries, documentation), while variable files change continuously during normal operation (e.g., logs, spool queues).
The Root Directory (/) and Essential Subdirectories
In Linux, all files and directories exist under a single hierarchy
originating at the root directory, represented by a single forward slash
(/). Under the FHS, the root partition contains only the
directories necessary to boot, restore, recover, or repair the
system.
- /bin: Essential user command binaries required for
system booting, repairing, or running in single-user mode (e.g.,
ls,cp,cat). On modern systems, this is often a symlink to/usr/bin. - /sbin: Essential system binaries used primarily for
system maintenance, administration, and booting by the root user (e.g.,
iptables,fdisk,reboot). Frequently symlinked to/usr/sbin. - /boot: Static files required to boot the system,
including the Linux kernel, the initial RAM disk image
(
initramfs), and bootloader configurations (such as GRUB). - /dev: Location of special device files that
represent hardware devices (like hard drives, partitions, and terminals)
or pseudo-devices (like
/dev/nulland/dev/random). - /etc: Host-specific system-wide configuration files and startup scripts. It contains only static configuration data and must not contain executable binaries.
- /home: Default location for regular user home directories, storing personal data, settings, and user-specific configurations.
- /root: The home directory for the administrative
superuser (
root), kept separate from/hometo ensure access even if the/homepartition fails to mount. - /lib, /lib64: Essential shared
libraries and kernel modules required to boot the system and run
commands found in
/binand/sbin.
Secondary Hierarchies and Data Stores
- /usr: The secondary hierarchy intended for
shareable, read-only user data. It mirrors the root layout with its own
/usr/bin,/usr/sbin, and/usr/libcontaining non-critical applications, libraries, and documentation. - /var: Variable data files generated dynamically by
system services. This includes system logs (
/var/log), mail and print spools (/var/spool), temporary operational caches (/var/cache), and lock files. - /tmp: Temporary files created by the system and running applications. Files placed here are typically cleared upon reboot or automatically deleted after a specified period.
- /opt: Add-on application software packages, typically used by third-party, proprietary, or self-contained applications that do not follow the standard distribution packaging scheme.
- /media: Mount points for removable media, such as USB drives, CDs, and SD cards, typically handled automatically by modern desktop environments.
- /mnt: Temporarily mounted filesystems manually attached by a system administrator for maintenance or migration.
- /srv: Site-specific data served by the system, such
as data for web servers (
/srv/www) or FTP repositories.
Virtual Filesystems
- /proc: A pseudo-filesystem providing a mechanism for the kernel to send information to and receive information from processes. Files here do not exist on disk; they reside in memory and represent process and kernel states.
- /sys: A sysfs virtual filesystem that exports information about kernel subsystems, hardware devices, and associated device drivers to user space.
The Importance of the FHS
Adherence to the FHS ensures software interoperability across the broader Linux ecosystem. It guarantees that scripts, compiled binaries, and package managers work reliably without extensive path reconfigurations, maintaining stability, security, and predictability across heterogeneous system environments.