]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/file-hierarchy.xml
Merge pull request #20744 from yuwata/udev-netlink
[thirdparty/systemd.git] / man / file-hierarchy.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="file-hierarchy">
7
8 <refentryinfo>
9 <title>file-hierarchy</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>file-hierarchy</refentrytitle>
15 <manvolnum>7</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>file-hierarchy</refname>
20 <refpurpose>File system hierarchy overview</refpurpose>
21 </refnamediv>
22
23 <refsect1>
24 <title>Description</title>
25
26 <para>Operating systems using the
27 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> system and service
28 manager are organized based on a file system hierarchy inspired by UNIX, more specifically the hierarchy described
29 in the <ulink url="http://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html">File System Hierarchy</ulink>
30 specification and <citerefentry
31 project='man-pages'><refentrytitle>hier</refentrytitle><manvolnum>7</manvolnum></citerefentry>, with various
32 extensions, partially documented in the <ulink
33 url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG Base Directory
34 Specification</ulink> and <ulink url="https://www.freedesktop.org/wiki/Software/xdg-user-dirs/">XDG User
35 Directories</ulink>. This manual page describes a more generalized, though minimal and modernized subset of these
36 specifications that defines more strictly the suggestions and restrictions systemd makes on the file system
37 hierarchy.</para>
38
39 <para>Many of the paths described here can be queried
40 with the
41 <citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry>
42 tool.</para>
43 </refsect1>
44
45 <refsect1>
46 <title>General Structure</title>
47
48 <variablelist>
49 <varlistentry>
50 <term><filename>/</filename></term>
51 <listitem><para>The file system root. Usually writable, but
52 this is not required. Possibly a temporary file system
53 (<literal>tmpfs</literal>). Not shared with other hosts
54 (unless read-only). </para></listitem>
55 </varlistentry>
56
57 <varlistentry>
58 <term><filename>/boot/</filename></term>
59 <listitem><para>The boot partition used for bringing up the
60 system. On EFI systems, this is possibly the EFI System
61 Partition (ESP), also see
62 <citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
63 This directory is usually strictly local to the host, and
64 should be considered read-only, except when a new kernel or
65 boot loader is installed. This directory only exists on
66 systems that run on physical or emulated hardware that
67 requires boot loaders.</para></listitem>
68 </varlistentry>
69
70 <varlistentry>
71 <term><filename>/efi/</filename></term>
72 <listitem><para>If the boot partition <filename>/boot/</filename> is maintained separately from the EFI System
73 Partition (ESP), the latter is mounted here. Tools that need to operate on the EFI system partition should look
74 for it at this mount point first, and fall back to <filename>/boot/</filename> — if the former doesn't qualify
75 (for example if it is not a mount point or does not have the correct file system type
76 <constant>MSDOS_SUPER_MAGIC</constant>).</para></listitem>
77 </varlistentry>
78
79 <varlistentry>
80 <term><filename>/etc/</filename></term>
81 <listitem><para>System-specific configuration. This directory
82 may or may not be read-only. Frequently, this directory is
83 pre-populated with vendor-supplied configuration files, but
84 applications should not make assumptions about this directory
85 being fully populated or populated at all, and should fall
86 back to defaults if configuration is
87 missing.</para></listitem>
88 </varlistentry>
89
90 <varlistentry>
91 <term><filename>/home/</filename></term>
92 <listitem><para>The location for normal user's home
93 directories. Possibly shared with other systems, and never
94 read-only. This directory should only be used for normal
95 users, never for system users. This directory and possibly the
96 directories contained within it might only become available or
97 writable in late boot or even only after user authentication.
98 This directory might be placed on limited-functionality
99 network file systems, hence applications should not assume the
100 full set of file API is available on this directory.
101 Applications should generally not reference this directory
102 directly, but via the per-user <varname>$HOME</varname>
103 environment variable, or via the home directory field of the
104 user database.</para></listitem>
105 </varlistentry>
106
107 <varlistentry>
108 <term><filename>/root/</filename></term>
109 <listitem><para>The home directory of the root user. The root
110 user's home directory is located outside of
111 <filename>/home/</filename> in order to make sure the root user
112 may log in even without <filename>/home/</filename> being
113 available and mounted.</para></listitem>
114 </varlistentry>
115
116 <varlistentry>
117 <term><filename>/srv/</filename></term>
118 <listitem><para>The place to store general server payload,
119 managed by the administrator. No restrictions are made how
120 this directory is organized internally. Generally writable,
121 and possibly shared among systems. This directory might become
122 available or writable only very late during
123 boot.</para></listitem>
124 </varlistentry>
125
126 <varlistentry>
127 <term><filename>/tmp/</filename></term>
128 <listitem><para>The place for small temporary files. This directory is usually mounted as a
129 <literal>tmpfs</literal> instance, and should hence not be used for larger files. (Use
130 <filename>/var/tmp/</filename> for larger files.) This directory is usually flushed at boot-up. Also,
131 files that are not accessed within a certain time may be automatically deleted.</para>
132
133 <para>If applications find the environment variable <varname>$TMPDIR</varname> set, they should use
134 the directory specified in it instead of <filename>/tmp/</filename> (see <citerefentry
135 project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
136 <ulink url="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03">IEEE
137 Std 1003.1</ulink> for details).</para>
138
139 <para>Since <filename>/tmp/</filename> is accessible to other users of the system, it is essential
140 that files and subdirectories under this directory are only created with <citerefentry
141 project='man-pages'><refentrytitle>mkstemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
142 <citerefentry
143 project='man-pages'><refentrytitle>mkdtemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
144 and similar calls. For more details, see <ulink url="https://systemd.io/TEMPORARY_DIRECTORIES">Using
145 /tmp/ and /var/tmp/ Safely</ulink>.</para>
146 </listitem>
147 </varlistentry>
148
149 </variablelist>
150 </refsect1>
151
152 <refsect1>
153 <title>Runtime Data</title>
154
155 <variablelist>
156 <varlistentry>
157 <term><filename>/run/</filename></term>
158 <listitem><para>A <literal>tmpfs</literal> file system for system packages to place runtime data,
159 socket files, and similar. This directory is flushed on boot, and generally writable for privileged
160 programs only. Always writable.</para></listitem>
161 </varlistentry>
162
163 <varlistentry>
164 <term><filename>/run/log/</filename></term>
165 <listitem><para>Runtime system logs. System components may
166 place private logs in this directory. Always writable, even
167 when <filename>/var/log/</filename> might not be accessible
168 yet.</para></listitem>
169 </varlistentry>
170
171 <varlistentry>
172 <term><filename>/run/user/</filename></term>
173 <listitem><para>Contains per-user runtime directories, each
174 usually individually mounted <literal>tmpfs</literal>
175 instances. Always writable, flushed at each reboot and when
176 the user logs out. User code should not reference this
177 directory directly, but via the
178 <varname>$XDG_RUNTIME_DIR</varname> environment variable, as
179 documented in the <ulink
180 url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
181 Base Directory Specification</ulink>.</para></listitem>
182 </varlistentry>
183 </variablelist>
184 </refsect1>
185
186 <refsect1>
187 <title>Vendor-supplied Operating System Resources</title>
188
189 <variablelist>
190
191 <varlistentry>
192 <term><filename>/usr/</filename></term>
193 <listitem><para>Vendor-supplied operating system resources.
194 Usually read-only, but this is not required. Possibly shared
195 between multiple hosts. This directory should not be modified
196 by the administrator, except when installing or removing
197 vendor-supplied packages.</para></listitem>
198 </varlistentry>
199
200 <varlistentry>
201 <term><filename>/usr/bin/</filename></term>
202 <listitem><para>Binaries and executables for user commands
203 that shall appear in the <varname>$PATH</varname> search path.
204 It is recommended not to place binaries in this directory that
205 are not useful for invocation from a shell (such as daemon
206 binaries); these should be placed in a subdirectory of
207 <filename>/usr/lib/</filename> instead.</para></listitem>
208 </varlistentry>
209
210 <varlistentry>
211 <term><filename>/usr/include/</filename></term>
212 <listitem><para>C and C++ API header files of system
213 libraries.</para></listitem>
214 </varlistentry>
215
216 <varlistentry>
217 <term><filename>/usr/lib/</filename></term>
218 <listitem><para>Static, private vendor data that is compatible
219 with all architectures (though not necessarily
220 architecture-independent). Note that this includes internal
221 executables or other binaries that are not regularly invoked
222 from a shell. Such binaries may be for any architecture
223 supported by the system. Do not place public libraries in this
224 directory, use <varname>$libdir</varname> (see below),
225 instead.</para></listitem>
226 </varlistentry>
227
228 <varlistentry>
229 <term><filename>/usr/lib/<replaceable>arch-id</replaceable>/</filename></term>
230 <listitem><para>Location for placing dynamic libraries into, also
231 called <varname>$libdir</varname>. The architecture identifier
232 to use is defined on <ulink
233 url="https://wiki.debian.org/Multiarch/Tuples">Multiarch
234 Architecture Specifiers (Tuples)</ulink> list. Legacy
235 locations of <varname>$libdir</varname> are
236 <filename>/usr/lib/</filename>,
237 <filename>/usr/lib64/</filename>. This directory should not be
238 used for package-specific data, unless this data is
239 architecture-dependent, too. To query
240 <varname>$libdir</varname> for the primary architecture of the
241 system, invoke:
242 <programlisting># systemd-path system-library-arch</programlisting></para></listitem>
243
244 </varlistentry>
245
246 <varlistentry>
247 <term><filename>/usr/share/</filename></term>
248 <listitem><para>Resources shared between multiple packages,
249 such as documentation, man pages, time zone information, fonts
250 and other resources. Usually, the precise location and format
251 of files stored below this directory is subject to
252 specifications that ensure interoperability.</para></listitem>
253 </varlistentry>
254
255 <varlistentry>
256 <term><filename>/usr/share/doc/</filename></term>
257 <listitem><para>Documentation for the operating system or
258 system packages.</para></listitem>
259 </varlistentry>
260
261 <varlistentry>
262 <term><filename>/usr/share/factory/etc/</filename></term>
263 <listitem><para>Repository for vendor-supplied default
264 configuration files. This directory should be populated with
265 pristine vendor versions of all configuration files that may
266 be placed in <filename>/etc/</filename>. This is useful to
267 compare the local configuration of a system with vendor
268 defaults and to populate the local configuration with
269 defaults.</para></listitem>
270 </varlistentry>
271
272 <varlistentry>
273 <term><filename>/usr/share/factory/var/</filename></term>
274
275 <listitem><para>Similar to
276 <filename>/usr/share/factory/etc/</filename>, but for vendor
277 versions of files in the variable, persistent data directory
278 <filename>/var/</filename>.</para></listitem>
279
280 </varlistentry>
281 </variablelist>
282 </refsect1>
283
284 <refsect1>
285 <title>Persistent Variable System Data</title>
286
287 <variablelist>
288 <varlistentry>
289 <term><filename>/var/</filename></term>
290 <listitem><para>Persistent, variable system data. Writable during normal system operation. This
291 directory might be pre-populated with vendor-supplied data, but applications should be able to
292 reconstruct necessary files and directories in this subhierarchy should they be missing, as the
293 system might start up without this directory being populated. Persistency is recommended, but
294 optional, to support ephemeral systems. This directory might become available or writable only very
295 late during boot. Components that are required to operate during early boot hence shall not
296 unconditionally rely on this directory.</para></listitem>
297 </varlistentry>
298
299 <varlistentry>
300 <term><filename>/var/cache/</filename></term>
301 <listitem><para>Persistent system cache data. System
302 components may place non-essential data in this directory.
303 Flushing this directory should have no effect on operation of
304 programs, except for increased runtimes necessary to rebuild
305 these caches.</para></listitem>
306 </varlistentry>
307
308 <varlistentry>
309 <term><filename>/var/lib/</filename></term>
310 <listitem><para>Persistent system data. System components may
311 place private data in this directory.</para></listitem>
312 </varlistentry>
313
314 <varlistentry>
315 <term><filename>/var/log/</filename></term>
316 <listitem><para>Persistent system logs. System components may
317 place private logs in this directory, though it is recommended
318 to do most logging via the
319 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
320 and
321 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>
322 calls.</para></listitem>
323 </varlistentry>
324
325 <varlistentry>
326 <term><filename>/var/spool/</filename></term>
327 <listitem><para>Persistent system spool data, such as printer
328 or mail queues.</para></listitem>
329 </varlistentry>
330
331 <varlistentry>
332 <term><filename>/var/tmp/</filename></term>
333 <listitem><para>The place for larger and persistent temporary files. In contrast to
334 <filename>/tmp/</filename>, this directory is usually mounted from a persistent physical file system
335 and can thus accept larger files. (Use <filename>/tmp/</filename> for small ephemeral files.) This
336 directory is generally not flushed at boot-up, but time-based cleanup of files that have not been
337 accessed for a certain time is applied.</para>
338
339 <para>If applications find the environment variable <varname>$TMPDIR</varname> set, they should use
340 the directory specified in it instead of <filename>/var/tmp/</filename> (see <citerefentry
341 project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
342 details).</para>
343
344 <para>The same security restrictions as with <filename>/tmp/</filename> apply: <citerefentry
345 project='man-pages'><refentrytitle>mkstemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
346 <citerefentry
347 project='man-pages'><refentrytitle>mkdtemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
348 and similar calls should be used. For further details about this directory, see <ulink
349 url="https://systemd.io/TEMPORARY_DIRECTORIES">Using /tmp/ and /var/tmp/ Safely</ulink>.</para>
350 </listitem>
351 </varlistentry>
352
353 </variablelist>
354 </refsect1>
355
356 <refsect1>
357 <title>Virtual Kernel and API File Systems</title>
358
359 <variablelist>
360 <varlistentry>
361 <term><filename>/dev/</filename></term>
362 <listitem><para>The root directory for device nodes. Usually,
363 this directory is mounted as a <literal>devtmpfs</literal>
364 instance, but might be of a different type in
365 sandboxed/containerized setups. This directory is managed
366 jointly by the kernel and
367 <citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
368 and should not be written to by other components. A number of
369 special purpose virtual file systems might be mounted below
370 this directory.</para></listitem>
371 </varlistentry>
372
373 <varlistentry>
374 <term><filename>/dev/shm/</filename></term>
375 <listitem><para>Place for POSIX shared memory segments, as
376 created via
377 <citerefentry project='die-net'><refentrytitle>shm_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
378 This directory is flushed on boot, and is a
379 <literal>tmpfs</literal> file system. Since all users have
380 write access to this directory, special care should be taken
381 to avoid name clashes and vulnerabilities. For normal users,
382 shared memory segments in this directory are usually deleted
383 when the user logs out. Usually, it is a better idea to use
384 memory mapped files in <filename>/run/</filename> (for system
385 programs) or <varname>$XDG_RUNTIME_DIR</varname> (for user
386 programs) instead of POSIX shared memory segments, since these
387 directories are not world-writable and hence not vulnerable to
388 security-sensitive name clashes.</para></listitem>
389 </varlistentry>
390
391 <varlistentry>
392 <term><filename>/proc/</filename></term>
393 <listitem><para>A virtual kernel file system exposing the
394 process list and other functionality. This file system is
395 mostly an API to interface with the kernel and not a place
396 where normal files may be stored. For details, see
397 <citerefentry project='man-pages'><refentrytitle>proc</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
398 A number of special purpose virtual file systems might be
399 mounted below this directory.</para></listitem>
400 </varlistentry>
401
402 <varlistentry>
403 <term><filename>/proc/sys/</filename></term>
404 <listitem><para>A hierarchy below <filename>/proc/</filename>
405 that exposes a number of kernel tunables. The primary way to
406 configure the settings in this API file tree is via
407 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
408 files. In sandboxed/containerized setups, this directory is
409 generally mounted read-only.</para></listitem>
410 </varlistentry>
411
412 <varlistentry>
413 <term><filename>/sys/</filename></term>
414 <listitem><para>A virtual kernel file system exposing
415 discovered devices and other functionality. This file system
416 is mostly an API to interface with the kernel and not a place
417 where normal files may be stored. In sandboxed/containerized
418 setups, this directory is generally mounted read-only. A number
419 of special purpose virtual file systems might be mounted below
420 this directory.</para></listitem>
421 </varlistentry>
422
423 </variablelist>
424 </refsect1>
425
426 <refsect1>
427 <title>Compatibility Symlinks</title>
428
429 <variablelist>
430 <varlistentry>
431 <term><filename>/bin/</filename></term>
432 <term><filename>/sbin/</filename></term>
433 <term><filename>/usr/sbin/</filename></term>
434
435 <listitem><para>These compatibility symlinks point to
436 <filename>/usr/bin/</filename>, ensuring that scripts and
437 binaries referencing these legacy paths correctly find their
438 binaries.</para></listitem>
439 </varlistentry>
440
441 <varlistentry>
442 <term><filename>/lib/</filename></term>
443
444 <listitem><para>This compatibility symlink points to
445 <filename>/usr/lib/</filename>, ensuring that programs
446 referencing this legacy path correctly find their
447 resources.</para></listitem>
448 </varlistentry>
449
450 <varlistentry>
451 <term><filename>/lib64/</filename></term>
452
453 <listitem><para>On some architecture ABIs, this compatibility
454 symlink points to <varname>$libdir</varname>, ensuring that
455 binaries referencing this legacy path correctly find their
456 dynamic loader. This symlink only exists on architectures
457 whose ABI places the dynamic loader in this
458 path.</para></listitem>
459 </varlistentry>
460
461 <varlistentry>
462 <term><filename>/var/run/</filename></term>
463
464 <listitem><para>This compatibility symlink points to
465 <filename>/run/</filename>, ensuring that programs referencing
466 this legacy path correctly find their runtime
467 data.</para></listitem>
468 </varlistentry>
469
470 </variablelist>
471 </refsect1>
472
473 <refsect1>
474 <title>Home Directory</title>
475
476 <para>User applications may want to place files and directories in
477 the user's home directory. They should follow the following basic
478 structure. Note that some of these directories are also
479 standardized (though more weakly) by the <ulink
480 url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
481 Base Directory Specification</ulink>. Additional locations for
482 high-level user resources are defined by <ulink
483 url="https://www.freedesktop.org/wiki/Software/xdg-user-dirs/">xdg-user-dirs</ulink>.</para>
484
485 <variablelist>
486 <varlistentry>
487 <term><filename>~/.cache/</filename></term>
488
489 <listitem><para>Persistent user cache data. User programs may
490 place non-essential data in this directory. Flushing this
491 directory should have no effect on operation of programs,
492 except for increased runtimes necessary to rebuild these
493 caches. If an application finds
494 <varname>$XDG_CACHE_HOME</varname> set, it should use the
495 directory specified in it instead of this
496 directory.</para></listitem>
497 </varlistentry>
498
499 <varlistentry>
500 <term><filename>~/.config/</filename></term>
501
502 <listitem><para>Application configuration and state. When a
503 new user is created, this directory will be empty or not exist
504 at all. Applications should fall back to defaults should their
505 configuration or state in this directory be missing. If an
506 application finds <varname>$XDG_CONFIG_HOME</varname> set, it
507 should use the directory specified in it instead of this
508 directory.</para></listitem>
509 </varlistentry>
510
511 <varlistentry>
512 <term><filename>~/.local/bin/</filename></term>
513
514 <listitem><para>Executables that shall appear in the user's
515 <varname>$PATH</varname> search path. It is recommended not to
516 place executables in this directory that are not useful for
517 invocation from a shell; these should be placed in a
518 subdirectory of <filename>~/.local/lib/</filename> instead.
519 Care should be taken when placing architecture-dependent
520 binaries in this place, which might be problematic if the home
521 directory is shared between multiple hosts with different
522 architectures.</para></listitem>
523 </varlistentry>
524
525 <varlistentry>
526 <term><filename>~/.local/lib/</filename></term>
527
528 <listitem><para>Static, private vendor data that is compatible
529 with all architectures.</para></listitem>
530 </varlistentry>
531
532 <varlistentry>
533 <term><filename>~/.local/lib/<replaceable>arch-id</replaceable>/</filename></term>
534
535 <listitem><para>Location for placing public dynamic libraries.
536 The architecture identifier to use is defined on <ulink
537 url="https://wiki.debian.org/Multiarch/Tuples">Multiarch
538 Architecture Specifiers (Tuples)</ulink>
539 list.</para></listitem>
540 </varlistentry>
541
542 <varlistentry>
543 <term><filename>~/.local/share/</filename></term>
544
545 <listitem><para>Resources shared between multiple packages,
546 such as fonts or artwork. Usually, the precise location and
547 format of files stored below this directory is subject to
548 specifications that ensure interoperability. If an application
549 finds <varname>$XDG_DATA_HOME</varname> set, it should use the
550 directory specified in it instead of this
551 directory.</para></listitem>
552 </varlistentry>
553
554 </variablelist>
555 </refsect1>
556
557 <refsect1>
558 <title>Write Access</title>
559
560 <refsect2>
561 <title>Unprivileged Write Access</title>
562
563 <para>Unprivileged processes generally lack write access to most of the hierarchy.</para>
564
565 <para>The exceptions for normal users are
566 <filename>/tmp/</filename>,
567 <filename>/var/tmp/</filename>,
568 <filename>/dev/shm/</filename>, as well as the home directory
569 <varname>$HOME</varname> (usually found below
570 <filename>/home/</filename>) and the runtime directory
571 <varname>$XDG_RUNTIME_DIR</varname> (found below
572 <filename>/run/user/</filename>) of the user, which are all
573 writable.</para>
574
575 <para>For unprivileged system processes, only
576 <filename>/tmp/</filename>,
577 <filename>/var/tmp/</filename> and
578 <filename>/dev/shm/</filename> are writable. If an
579 unprivileged system process needs a private writable directory in
580 <filename>/var/</filename> or <filename>/run/</filename>, it is
581 recommended to either create it before dropping privileges in the
582 daemon code, to create it via
583 <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
584 fragments during boot, or via the
585 <varname>StateDirectory=</varname> and <varname>RuntimeDirectory=</varname>
586 directives of service units (see
587 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
588 for details).</para>
589
590 <para><filename>/tmp/</filename>, <filename>/var/tmp/</filename> and <filename>/dev/shm/</filename>
591 should be mounted <option>nosuid</option> and <option>nodev</option>, which means that set-user-id mode
592 and character or block special devices are not interpreted on those file systems. In general it is not
593 possible to mount them <option>noexec</option>, because various programs use those directories for
594 dynamically generated or optimized code, and with that flag those use cases would break. Using this
595 flag is OK on special-purpose installations or systems where all software that may be installed is
596 known and doesn't require such functionality. See the discussion of
597 <option>nosuid</option>/<option>nodev</option>/<option>noexec</option> in <citerefentry
598 project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> and
599 <constant>PROT_EXEC</constant> in <citerefentry
600 project='man-pages'><refentrytitle>mmap</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
601 </para>
602 </refsect2>
603
604 <refsect2>
605 <title>Lack of Write Access on Read-Only Systems and during System Recovery</title>
606
607 <para>As noted above, some systems operate with the <filename>/usr</filename> and
608 <filename>/etc</filename> hierarchies mounted read-only, possibly only allowing write access during
609 package upgrades. Other part of the hierarchy are generally mounted read-write (in particular
610 <filename>/var</filename> and <filename>/var/tmp</filename>), but may be read-only when the kernel
611 remounts the file system read-only in response to errors, or when the system is booted read-only for
612 recovery purposes. To the extent reasonable, applications should be prepared to execute without write
613 access, so that for example, failure to save non-essential data to <filename>/var/cache/</filename> or
614 failure to create a custom log file under <filename>/var/log</filename> does not prevent the
615 application from running.</para>
616
617 <para>The <filename>/run/</filename> directory is available since the earliest boot and is always
618 writable. It should be used for any runtime data and sockets, so that write access to e.g.
619 <filename>/etc</filename> or <filename>/var</filename> is not needed.</para>
620 </refsect2>
621 </refsect1>
622
623 <refsect1>
624 <title>Node Types</title>
625
626 <para>Unix file systems support different types of file nodes,
627 including regular files, directories, symlinks, character and
628 block device nodes, sockets and FIFOs.</para>
629
630 <para>It is strongly recommended that <filename>/dev/</filename> is
631 the only location below which device nodes shall be placed.
632 Similarly, <filename>/run/</filename> shall be the only location to
633 place sockets and FIFOs. Regular files, directories and symlinks
634 may be used in all directories.</para>
635 </refsect1>
636
637 <refsect1>
638 <title>System Packages</title>
639
640 <para>Developers of system packages should follow strict rules when placing their files in the file
641 system. The following table lists recommended locations for specific types of files supplied by the
642 vendor.</para>
643
644 <table>
645 <title>System package vendor files locations</title>
646 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
647 <colspec colname="directory" />
648 <colspec colname="purpose" />
649 <thead>
650 <row>
651 <entry>Directory</entry>
652 <entry>Purpose</entry>
653 </row>
654 </thead>
655 <tbody>
656 <row>
657 <entry><filename>/usr/bin/</filename></entry>
658 <entry>Package executables that shall appear in the <varname>$PATH</varname> executable search path, compiled for any of the supported architectures compatible with the operating system. 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 taken to pick unique names for files placed here, that are unlikely to clash with other package's files.</entry>
659 </row>
660 <row>
661 <entry><filename>/usr/lib/<replaceable>arch-id</replaceable>/</filename></entry>
662 <entry>Public shared libraries of the package. As above, be careful with using too generic names, and pick unique names for your libraries to place here to avoid name clashes.</entry>
663 </row>
664 <row>
665 <entry><filename>/usr/lib/<replaceable>package</replaceable>/</filename></entry>
666 <entry>Private static vendor resources of the package, including private binaries and libraries, or any other kind of read-only vendor data.</entry>
667 </row>
668 <row>
669 <entry><filename>/usr/lib/<replaceable>arch-id</replaceable>/<replaceable>package</replaceable>/</filename></entry>
670 <entry>Private other vendor resources of the package that are architecture-specific and cannot be shared between architectures. Note that this generally does not include private executables since binaries of a specific architecture may be freely invoked from any other supported system architecture.</entry>
671 </row>
672 <row>
673 <entry><filename>/usr/include/<replaceable>package</replaceable>/</filename></entry>
674 <entry>Public C/C++ APIs of public shared libraries of the package.</entry>
675 </row>
676 </tbody>
677 </tgroup>
678 </table>
679
680 <para>Additional static vendor files may be installed in the
681 <filename>/usr/share/</filename> hierarchy to the locations
682 defined by the various relevant specifications.</para>
683
684 <para>The following directories shall be used by the package for local configuration and files created
685 during runtime:</para>
686
687 <table>
688 <title>System package variable files locations</title>
689 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
690 <colspec colname="directory" />
691 <colspec colname="purpose" />
692 <thead>
693 <row>
694 <entry>Directory</entry>
695 <entry>Purpose</entry>
696 </row>
697 </thead>
698 <tbody>
699 <row>
700 <entry><filename>/etc/<replaceable>package</replaceable>/</filename></entry>
701 <entry>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 <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> fragment may be used to copy or symlink the necessary files and directories from <filename>/usr/share/factory/</filename> during boot, via the <literal>L</literal> or <literal>C</literal> directives.</entry>
702 </row>
703 <row>
704 <entry><filename>/run/<replaceable>package</replaceable>/</filename></entry>
705 <entry>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 <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> fragment may be used to create the necessary directories during boot, or the <varname>RuntimeDirectory=</varname> directive of service units may be used to create them at service startup (see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details).</entry>
706 </row>
707 <row>
708 <entry><filename>/run/log/<replaceable>package</replaceable>/</filename></entry>
709 <entry>Runtime log data for the package. As above, the package needs to make sure to create this directory if necessary, as it will be flushed on every boot.</entry>
710 </row>
711 <row>
712 <entry><filename>/var/cache/<replaceable>package</replaceable>/</filename></entry>
713 <entry>Persistent cache data of the package. If this directory is flushed, the application should work correctly on next invocation, though possibly slowed down due to the need to rebuild any local cache files. The application must be capable of recreating this directory should it be missing and necessary. To create an empty directory, a <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> fragment or the <varname>CacheDirectory=</varname> directive of service units (see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>) may be used.</entry>
714 </row>
715 <row>
716 <entry><filename>/var/lib/<replaceable>package</replaceable>/</filename></entry>
717 <entry>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. To create an empty directory, a <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> fragment or the <varname>StateDirectory=</varname> directive of service units (see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>) may be used.</entry>
718 </row>
719 <row>
720 <entry><filename>/var/log/<replaceable>package</replaceable>/</filename></entry>
721 <entry>Persistent log data of the package. As above, the package should make sure to create this directory if necessary, possibly using <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> or <varname>LogsDirectory=</varname> (see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>), as it might be missing.</entry>
722 </row>
723 <row>
724 <entry><filename>/var/spool/<replaceable>package</replaceable>/</filename></entry>
725 <entry>Persistent spool/queue data of the package. As above, the package should make sure to create this directory if necessary, as it might be missing.</entry>
726 </row>
727 </tbody>
728 </tgroup>
729 </table>
730 </refsect1>
731
732 <refsect1>
733 <title>User Packages</title>
734
735 <para>Programs running in user context should follow strict rules when placing their own files in the
736 user's home directory. The following table lists recommended locations in the home directory for specific
737 types of files supplied by the vendor if the application is installed in the home directory. (User
738 applications installed system-wide are covered by the rules outlined above for vendor files.)</para>
739
740 <table>
741 <title>Vendor package file locations under the home directory of the user</title>
742 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
743 <colspec colname="directory" />
744 <colspec colname="purpose" />
745 <thead>
746 <row>
747 <entry>Directory</entry>
748 <entry>Purpose</entry>
749 </row>
750 </thead>
751 <tbody>
752 <row>
753 <entry><filename>~/.local/bin/</filename></entry>
754 <entry>Package executables that shall appear in the <varname>$PATH</varname> executable search path. It is not recommended to place internal executables or executables that are not commonly invoked from the shell in this directory, such as daemon executables. As this directory is shared with most other packages of the user, special care should be taken to pick unique names for files placed here, that are unlikely to clash with other package's files.</entry>
755 </row>
756 <row>
757 <entry><filename>~/.local/lib/<replaceable>arch-id</replaceable>/</filename></entry>
758 <entry>Public shared libraries of the package. As above, be careful with using overly generic names, and pick unique names for your libraries to place here to avoid name clashes.</entry>
759 </row>
760 <row>
761 <entry><filename>~/.local/lib/<replaceable>package</replaceable>/</filename></entry>
762 <entry>Private, static vendor resources of the package, compatible with any architecture, or any other kind of read-only vendor data.</entry>
763 </row>
764 <row>
765 <entry><filename>~/.local/lib/<replaceable>arch-id</replaceable>/<replaceable>package</replaceable>/</filename></entry>
766 <entry>Private other vendor resources of the package that are architecture-specific and cannot be shared between architectures.</entry>
767 </row>
768 </tbody>
769 </tgroup>
770 </table>
771
772 <para>Additional static vendor files may be installed in the <filename>~/.local/share/</filename>
773 hierarchy, mirroring the subdirectories specified in the section "Vendor-supplied operating system
774 resources" above.</para>
775
776 <para>The following directories shall be used by the package for per-user local configuration and files
777 created during runtime:</para>
778
779 <table>
780 <title>User package variable file locations</title>
781 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
782 <colspec colname="directory" />
783 <colspec colname="purpose" />
784 <thead>
785 <row>
786 <entry>Directory</entry>
787 <entry>Purpose</entry>
788 </row>
789 </thead>
790 <tbody>
791 <row>
792 <entry><filename>~/.config/<replaceable>package</replaceable>/</filename></entry>
793 <entry>User-specific configuration and state for the package. It is required to default to safe fallbacks if this configuration is missing.</entry>
794 </row>
795 <row>
796 <entry><filename><varname>$XDG_RUNTIME_DIR</varname>/<replaceable>package</replaceable>/</filename></entry>
797 <entry>User runtime data for the package.</entry>
798 </row>
799 <row>
800 <entry><filename>~/.cache/<replaceable>package</replaceable>/</filename></entry>
801 <entry>Persistent cache data of the package. If this directory is flushed, the application should work correctly on next invocation, though possibly slowed down due to the need to rebuild any local cache files. The application must be capable of recreating this directory should it be missing and necessary.</entry>
802 </row>
803 </tbody>
804 </tgroup>
805 </table>
806 </refsect1>
807
808 <refsect1>
809 <title>See Also</title>
810 <para>
811 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
812 <citerefentry project='man-pages'><refentrytitle>hier</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
813 <citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
814 <citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
815 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
816 <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
817 <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
818 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
819 </para>
820 </refsect1>
821
822 </refentry>