file-hierarchy systemd Developer Lennart Poettering lennart@poettering.net file-hierarchy 7 file-hierarchy File system hierarchy overview Description Operating systems using the systemd1 system and service manager are organized based on a file system hierarchy inspired by UNIX, more specificaly the hierarchy described in the File System Hierarchy specification and hier7. This manual page describes a more minimal, modernized subset of these specifications that defines more strictly the suggestions and restrictions systemd makes on the file system hierarchy. General Structure / The file system root. Usually writable, but this is not required. Possibly a temporary file system (tmpfs). Not shared with other hosts (unless read-only). The administrator may create additional top-level subdirectories in this tree, if required and the name does not conflict with any of the directories listed below. /boot The boot partition used for bringing up the system. On EFI systems this is possibly the EFI System Partition, also see systemd-boot-generator8. This directory is usually strictly local the host, and should be considered read-only, except when a new kernel or boot loader is installed. This directory only exists on systems that run on physical or emulated hardware that requires boot loaders. /etc System-specific configuration. This directory may or may not be read-only. Frequently, this directory is pre-populated with vendor-supplied configuration files, but applications should not make assumptions about this directory being fully populated or populated at all, and should fall back to defaults if configuration is missing. /home The location for normal user's home directories. Possibly shared with other systems, and never read-only. This directory should only be used for normal users, never for system users. This directory and possibly the directories contained within it might only become available or writable in late boot or even on user login only. This directory might be placed on limited-functionality network file systems, hence applications should not assume the full set of file API is available on this directory. Applications should generally not reference this directory directly, but via the per-user $HOME environment variable, or via the home directory field of the user database. /root The home directory of the root user. The root user's home directory is located outside of /home in order to make sure the root user may log in even without /home being available and mounted. /srv The place to store general server payload, managed by the administrator. No restrictions are made how this directory is organized internally. Generally writable, and possibly shared among systems. This directory might become available or writable only very late during boot. /tmp The place for small temporary files. This directory is usually mounted as tmpfs instance, and should hence not be used for larger files. (Use /var/tmp for larger files.) Since the directory is accessible to other users of the system it is essential that this directory is only written to with the mkstemp3, mkdtemp3 and related calls. This directory is usually flushed at boot-up. Also, files that are not accessed within a certain time are usually automatically deleted. If applications find the environment variable $TMP set they should prefer using the directory specified in it over directly referencing /tmp. Runtime Data /run A tmpfs file system for system packages to place runtime data in. This directory is flushed on boot, and generally writable for priviliged programs only. Always writable. /run/log Runtime system logs. System components may place private logs in this directory. Always writable, even when /var/log might not be accessible yet. /run/user Contains per-user runtime directories, each usually invidually mounted tmpfs instances. Always writable, flushed at each reboot and when the user logs out. User code should not reference this directory directly, but via the $XDG_RUNTIME_DIR environment variable, as documented in the XDG Base Directory Specification. Vendor-supplied Operating System Resources /usr Vendor-supplied operating system resources. Usually read-only, but this is not required. Possibly shared between multiple hosts. This directory should not be modified by the administrator, except when installing or removing vendor-supplied packages. /usr/bin Binaries for user commands, that shall appear in the $PATH search path. It is recommended not to place binaries in this directory that are not useful for invocation from a shell (such as daemon binaries); these should be placed in a subdirectory of /usr/lib instead. /usr/include C and C++ API header files of system libraries. /usr/lib System libraries and package-specific data. /usr/lib64 Secondary library directory for placing 64bit versions of system libraries in, if the primary architecture of the system is 32bit, and /usr/lib64 is defined in the platform ABI. This directory should not be used for package-specific data, unless this data requires 64bit-specific versions, too. /usr/share Resources shared betwen multiple packages, such as documentation, man pages, time zone information, fonts and other resources. Usually, the precise location and format of files stored below this directory is subject to specifications that ensure interoperability. /usr/share/doc Documentation for the operating system or system packages. /usr/share/factory/etc Repository for vendor-supplied default configuration files. This directory should be populated with pristine vendor versions of all configuration files that may be placed in /etc. This is useful to compare the local configuration of a system with vendor defaults and to populate the local configuration with defaults. /usr/share/factory/var Similar to /usr/share/factory/etc but for vendor versions of files in the variable, persistent data directory /var. Persistent Variable System Data /var Persistent, variable system data. Must be writable. This directory might be pre-populated with vendor-supplied data, but applications should be able to reconstruct necessary files and directories in this subhierarchy should they be missing, as the system might start up without this directory being populated. Persistency is recommended, but optional, to support ephemeral systems. This directory might become available or writable only very late during boot. Components that are required to operate during early boot hence shall not unconditionally rely on this directory. /var/cache Persistent system cache data. System components may place non-essential data in this directory. Flushing this directory should have no effect on operation of programs, except for increased runtimes necessary to rebuild these caches. /var/lib Persistent system data. System components may place private data in this directory. /var/log Persistent system logs. System components may place private logs in this directory, though it is recommended to do most logging via the syslog3 and sd_journal_print3 calls. /var/spool Persistent system spool data, such as printer or mail queues. /var/tmp The place for larger and persistent temporary files. In contrast to /tmp this directory is usually mounted from a persistent physical file system and can thus accept larger files. (Use /tmp for smaller files.) This directory is generally not flushed at boot-up, but time-based cleanup of files that have not been accessed for a certain time is applied. The same security restrictions as with /tmp apply, and hence only mkstemp3, mkdtemp3 or similar calls should be used to make use of this directory. If applications find the environment variable $TMP set they should prefer using the directory specified in it over directly referencing /var/tmp. Virtual Kernel and API File Systems /dev The root directory for device nodes. Usually this directory is mounted as devtmpfs instance, but might be of a different type in sandboxed/containerized setups. This directory is managed jointly by the kernel and systemd-udevd8, and should not be written to by other components. A number of special purpose virtual file systems might be mounted below this directory. /dev/shm Place for POSIX shared memory segments, as created via shm_open3. This directory is flushed on boot, and is a tmpfs file system. Since all users have write access to this directory, special care should be taken to avoid name clashes and vulnerabilities. For normal users, shared memory segments in this directory are usually deleted when the user logs out. Usually it is a better idea to use memory mapped files in /run (for system programs) or $XDG_RUNTIME_DIR (for user programs) instead of POSIX shared memory segments, since they directories are not world-writable and hence not vulnerable to security-sensitive name clashes. /proc A virtual kernel file system exposing the process list and other functionality. This file system is mostly an API to interface with the kernel and not a place where normal files may be stored. For details, see proc5. A number of special purpose virtual file systems might be mounted below this directory. /proc/sys A hierarchy below /proc that exposes a number of kernel tunables. The primary way to configure the settings in this API file tree is via sysctl.d5 files. In sandboxed/containerized setups this directory is generally mounted read-only. /sys A virtual kernel file system exposing discovered devices and other functionality. This file system is mostly an API to interface with the kernel and not a place where normal files may be stored. In sandboxed/containerized setups this directory is generally mounted read-only. A number of special purpose virtual file systems might be mounted below this directory. Compatibility Symlinks /bin /sbin /usr/sbin These compatibility symlinks point to /usr/bin, ensuring that scripts and binaries referencing these legacy paths correctly find their binaries. /lib This compatibility symlink points to /usr/lib, ensuring that binaries referencing this legacy path correctly find their libraries. /lib64 This compatibility symlink points to /usr/lib64, ensuring that binaries referencing this legacy path correctly find their libraries. This symlink only exists on architectures whose ABI requires a 64bit version of the library directory. /var/run This compatibility symlink points to /run, ensuring that programs referencing this legacy path correctly find their runtime data. System Packages Developers of system packages should follow strict rules when placing their own files in the file system. The following table lists recommended locations for specific types of files. System Package Data Location Directory Purpose /usr/bin Package executables that shall appear in the $PATH executable search path. It is not recommended to place internal binaries or binaries that are not commonly invoked from the shell in this directory, such as daemon binaries. As this directory is shared with most other packages of the system special care should be take to pick unique names for files placed here, that are unlikely to clash with other package's files. /usr/lib Public shared libraries of the package, compiled for the primary architecture of the operating system. As above, be careful with using too generic names, and pick unique names for your libraries to place here to avoid name clashes. /usr/lib/package Private other vendor resources of the package, including private binaries and libraries, but also including any other kind of read-only vendor data. /usr/lib64 Public shared libraries of the package, compiled for the secondary, 64bit architecture, if this is part of the platform ABI of the architecture. /usr/lib64/package Private other vendor resources of the package that are architecture-specific and cannot be shared between primary and secondary architectures. Note that this generally does not include private binaries since binaries of the primary architecture may generally be invoked from secondary architecture code just fine. /usr/include/package Public C/C++ APIs of public shared libraries of the package. /etc/package System-specific configuration for the package. It is recommended to default to safe fallbacks if this configuration is missing, if this is possible. Alternatively, a tmpfiles.d5 fragment may be used to copy or symlink the necessary files and directores from /usr/share/factory during boot, via the L or C directives. /run/package Runtime data for the package. Packages must be able to create the necessary subdirectories in this tree on their own, since the directory is flushed automatically on boot. Alternatively, a tmpfiles.d5 fragment may be used to create the necessary directories during boot. /run/log/package Runtime log data for the package. /var/cache/package Persistent cache data of the package. If this directory is flushed the application should work correctly on next invocation, though possibly slowed done due to the need to rebuild any local cache files. /var/lib/package Persistent private data of the package. This is the primary place to put persistent data that does not fall into the other categories listed. Packages should be able to create the necessary subdirectories in this tree on their own, since the directory might be missing on boot. Alternatively, a tmpfiles.d5 fragment may be used to create the necessary directories during boot. /var/log/package Persistent log data of the package. /var/spool/package Persistent spool/queue data of the package.
See Also systemd1, hier7, systemd-boot-generator8, sysctl.d5,