]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/file-hierarchy.xml
man: add a minimized, modernized description of the file system hierarchy systemd...
[thirdparty/systemd.git] / man / file-hierarchy.xml
CommitLineData
9546c6ed
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5<!--
6 This file is part of systemd.
7
8 Copyright 2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
24<refentry id="file-hierarchy">
25
26 <refentryinfo>
27 <title>file-hierarchy</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>file-hierarchy</refentrytitle>
42 <manvolnum>7</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>file-hierarchy</refname>
47 <refpurpose>File system hierarchy overview</refpurpose>
48 </refnamediv>
49
50 <refsect1>
51 <title>Description</title>
52
53 <para>Operating systems using the
54 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
55 system and service manager are organized based on a
56 file system hierarchy inspired by UNIX, more
57 specificaly the hierarchy described in the <ulink
58 url="http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html">File
59 System Hierarchy</ulink> specification and
60 <citerefentry><refentrytitle>hier</refentrytitle><manvolnum>7</manvolnum></citerefentry>. This
61 manual page describes a more minimal, modernized
62 subset of these specifications that defines more
63 strictly the suggestions and restrictions systemd
64 makes on the file system hierarchy.</para>
65 </refsect1>
66
67 <refsect1>
68 <title>General Structure</title>
69
70 <variablelist>
71 <varlistentry>
72 <term><filename>/</filename></term>
73 <listitem><para>The file system
74 root. Usually writable, but this is
75 not required. Possibly a temporary
76 file system (<literal>tmpfs</literal>). Not shared with
77 other hosts (unless read-only). The
78 administrator may create additional
79 top-level subdirectories in this tree,
80 if required and the name does not
81 conflict with any of the directories
82 listed below.</para></listitem>
83 </varlistentry>
84
85 <varlistentry>
86 <term><filename>/boot</filename></term>
87 <listitem><para>The boot partition
88 used for bringing up the system. On
89 EFI systems this is possibly the EFI
90 System Partition, also see
91 <citerefentry><refentrytitle>systemd-boot-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>. This
92 directory is usually strictly local
93 the host, and should be considered
94 read-only, except when a new kernel or
95 boot loader is installed. This
96 directory only exists on systems that
97 run on physical or emulated hardware
98 that requires boot
99 loaders.</para></listitem>
100 </varlistentry>
101
102 <varlistentry>
103 <term><filename>/etc</filename></term>
104 <listitem><para>System-specific
105 configuration. This directory may or
106 may not be read-only. Frequently, this
107 directory is pre-populated with
108 vendor-supplied configuration files,
109 but applications should not make
110 assumptions about this directory
111 being fully populated or populated at
112 all, and should fall back to defaults
113 if configuration is missing.</para></listitem>
114 </varlistentry>
115
116 <varlistentry>
117 <term><filename>/home</filename></term>
118 <listitem><para>The location for
119 normal user's home
120 directories. Possibly shared with
121 other systems, and never
122 read-only. This directory should only
123 be used for normal users, never for
124 system users. This directory and
125 possibly the directories contained
126 within it might only become available
127 or writable in late boot or even on
128 user login only. This directory might
129 be placed on limited-functionality
130 network file systems, hence
131 applications should not assume the
132 full set of file API is available on
133 this directory.</para></listitem>
134 </varlistentry>
135
136 <varlistentry>
137 <term><filename>/root</filename></term>
138 <listitem><para>The home directory of
139 the root user. The root user's home
140 directory is located outside of
141 <filename>/home</filename> in order to
142 make sure the root user may log in
143 even without <filename>/home</filename>
144 being available and
145 mounted.</para></listitem>
146 </varlistentry>
147
148 <varlistentry>
149 <term><filename>/srv</filename></term>
150 <listitem><para>The place to store
151 general server payload, managed by the
152 administrator. No restrictions are
153 made how this directory is organized
154 internally. Generally writable, and
155 possibly shared among systems. This
156 directory might become available or
157 writable only very late during
158 boot.</para></listitem>
159 </varlistentry>
160
161 <varlistentry>
162 <term><filename>/tmp</filename></term>
163 <listitem><para>The place for small
164 temporary files. This directory is
165 usually mounted as
166 <literal>tmpfs</literal> instance, and
167 should hence not be used for larger
168 files. Since the directory is
169 accessible to other users of the
170 system it is essential that this
171 directory is only written to with the
172 <citerefentry><refentrytitle>mkstemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
173 <citerefentry><refentrytitle>mkdtemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>
174 and related calls. This directory is
175 usually flushed at boot-up. Also,
176 files that are not accessed within a
177 certain time are usually automatically
178 deleted.</para></listitem>
179 </varlistentry>
180
181 </variablelist>
182 </refsect1>
183
184 <refsect1>
185 <title>Runtime Data</title>
186
187 <variablelist>
188 <varlistentry>
189 <term><filename>/run</filename></term>
190 <listitem><para>A
191 <literal>tmpfs</literal> file system
192 for system packages to place runtime
193 data in. This directory is flushed on
194 boot, and generally writable for
195 priviliged programs
196 only. Always writable.</para></listitem>
197 </varlistentry>
198
199 <varlistentry>
200 <term><filename>/run/log</filename></term>
201 <listitem><para>Runtime system
202 logs. System components may place
203 private logs in this directory. Always
204 writable, even when
205 <filename>/var/log</filename> might
206 not be accessible
207 yet.</para></listitem>
208 </varlistentry>
209
210 <varlistentry>
211 <term><filename>/run/user</filename></term>
212 <listitem><para>Contains per-user
213 runtime directories, each usually
214 invidually mounted
215 <literal>tmpfs</literal>
216 instances. Always writable, flushed at
217 each reboot and when the user logs
218 out. User code should not reference
219 this directory directly, but via the
220 <varname>$XDG_RUNTIME_DIR</varname>
221 environment variable, as documented in
222 the <ulink
223 url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
224 Base Directory
225 Specification</ulink>.</para></listitem>
226 </varlistentry>
227 </variablelist>
228 </refsect1>
229
230 <refsect1>
231 <title>Vendor-supplied Operating System Resources</title>
232
233 <variablelist>
234
235 <varlistentry>
236 <term><filename>/usr</filename></term>
237 <listitem><para>Vendor-supplied
238 operating system resources. Usually
239 read-only, but this is not
240 required. Possibly shared between
241 multiple hosts. This directory should
242 not be modified by the administrator,
243 except when installing or removing
244 vendor-supplied
245 packages.</para></listitem>
246 </varlistentry>
247
248 <varlistentry>
249 <term><filename>/usr/bin</filename></term>
250 <listitem><para>Binaries for user
251 commands, that shall appear in the
252 <varname>$PATH</varname> search
253 path. It is recommended not to place
254 binaries in this directory that are
255 not useful for invocation from a shell
256 (such as daemon binaries); these
257 should be placed in a subdirectory of
258 <filename>/usr/lib</filename>
259 instead.</para></listitem>
260 </varlistentry>
261
262 <varlistentry>
263 <term><filename>/usr/include</filename></term>
264 <listitem><para>C and C++ API header
265 files of system
266 libraries.</para></listitem>
267 </varlistentry>
268
269 <varlistentry>
270 <term><filename>/usr/lib</filename></term>
271 <listitem><para>System libraries and
272 package-specific
273 data.</para></listitem>
274 </varlistentry>
275
276 <varlistentry>
277 <term><filename>/usr/lib64</filename></term>
278 <listitem><para>Secondary library
279 directory for placing 64bit versions
280 of system libraries in, if the primary
281 architecture of the system is
282 32bit. This directory should not be
283 used for package-specific data, unless
284 this data requires 64bit-specific
285 versions, too.</para></listitem>
286 </varlistentry>
287
288 <varlistentry>
289 <term><filename>/usr/share</filename></term>
290 <listitem><para>Resources shared
291 betwen multiple packages, such as
292 documentation, man pages, time zone
293 information, fonts and other
294 resources.</para></listitem>
295 </varlistentry>
296
297 <varlistentry>
298 <term><filename>/usr/share/doc</filename></term>
299 <listitem><para>Documentation for the
300 operating system or system
301 packages.</para></listitem>
302 </varlistentry>
303
304 <varlistentry>
305 <term><filename>/usr/share/factory/etc</filename></term>
306 <listitem><para>Repository for
307 vendor-supplied default configuration
308 files. This directory should be
309 populated with pristine vendor versions
310 of all configuration files that may be
311 placed in
312 <filename>/etc</filename>. This is
313 useful to compare the local
314 configuration of a system with vendor
315 defaults and to populate the local
316 configuration with
317 defaults.</para></listitem>
318 </varlistentry>
319
320 <varlistentry>
321 <term><filename>/usr/share/factory/var</filename></term>
322
323 <listitem><para>Similar to
324 <filename>/usr/share/factory/etc</filename>
325 but for vendor versions of files in
326 the variable, persistent data
327 directory
328 <filename>/var</filename>.</para></listitem>
329
330 </varlistentry>
331 </variablelist>
332 </refsect1>
333
334 <refsect1>
335 <title>Persistent Variable System Data</title>
336
337 <variablelist>
338 <varlistentry>
339 <term><filename>/var</filename></term>
340 <listitem><para>Persistent, variable
341 system data. Must be writable. This
342 directory might be pre-populated with
343 vendor-supplied data, but applications
344 should be able to reconstruct
345 necessary files and directories in
346 this subhierarchy should they be
347 missing, as the system might start up
348 without this directory being
349 populated. Persistency is recommended,
350 but optional, to support ephemeral
351 systems. This directory might become
352 available or writable only very late
353 during boot. Components that are
354 required to operate during early boot
355 hence shall not unconditionally rely
356 on this directory.</para></listitem>
357 </varlistentry>
358
359 <varlistentry>
360 <term><filename>/var/cache</filename></term>
361 <listitem><para>Persistent system
362 cache data. System components may
363 place non-essential data in this
364 directory. Flushing this directory
365 should have no effect on operation of
366 programs, except for increased
367 runtimes necessary to rebuild these
368 caches.</para></listitem>
369 </varlistentry>
370
371 <varlistentry>
372 <term><filename>/var/lib</filename></term>
373 <listitem><para>Persistent system
374 data. System components may
375 place private data in this
376 directory.</para></listitem>
377 </varlistentry>
378
379 <varlistentry>
380 <term><filename>/var/log</filename></term>
381 <listitem><para>Persistent system
382 logs. System components may place
383 private logs in this directory, though
384 it is recommended to do most logging
385 via the
386 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
387 and
388 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>
389 calls.</para></listitem>
390 </varlistentry>
391
392 <varlistentry>
393 <term><filename>/var/spool</filename></term>
394 <listitem><para>Persistent system
395 spool data, such as printer or mail
396 queues.</para></listitem>
397 </varlistentry>
398
399 <varlistentry>
400 <term><filename>/var/tmp</filename></term>
401 <listitem><para>The place for larger
402 and persistent temporary files. In
403 contrast to <filename>/tmp</filename>
404 this directory is usually mounted from
405 a persistent physical file system and
406 can thus accept larger files. This
407 directory is generally not flushed at
408 boot-up, but time-based cleanup of
409 files that have not been accessed for
410 a certain time is applied. The same
411 security restrictions as with
412 <filename>/tmp</filename> apply, and
413 hence only
414 <citerefentry><refentrytitle>mkstemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
415 <citerefentry><refentrytitle>mkdtemp</refentrytitle><manvolnum>3</manvolnum></citerefentry>
416 or similar calls should be used to
417 make use of this directory.
418 </para></listitem>
419 </varlistentry>
420
421 </variablelist>
422 </refsect1>
423
424 <refsect1>
425 <title>Virtual Kernel and API File Systems</title>
426
427 <variablelist>
428 <varlistentry>
429 <term><filename>/dev</filename></term>
430 <listitem><para>The root directory for
431 device nodes. Usually this directory
432 is mounted as
433 <literal>devtmpfs</literal> instance,
434 but might be of a different type in
435 sandboxed/containerized setups. This
436 directory is managed jointly by the
437 kernel and
438 <citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
439 and should not be written to by other
440 components. A number of special
441 purpose virtual file systems might be
442 mounted below this
443 directory.</para></listitem>
444 </varlistentry>
445
446 <varlistentry>
447 <term><filename>/dev/shm</filename></term>
448 <listitem><para>Place for POSIX shared
449 memory segments, as created via
450 <citerefentry><refentrytitle>shm_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>. This
451 directory is flushed on boot, and is a
452 <literal>tmpfs</literal> file
453 system. Since all users have write
454 access to this directory, special care
455 should be taken to avoid name clashes
456 and vulnerabilities. For normal users,
457 shared memory segments in this
458 directory are usually deleted when the
459 user logs out. Usually it is a better
460 idea to use memory mapped files in
461 <filename>/run</filename> (for system
462 programs) or
463 <varname>$XDG_RUNTIME_DIR</varname>
464 (for user programs) instead of POSIX
465 shared memory segments, since they
466 directories are not world-writable and
467 hence not vulnerable to
468 security-sensitive name
469 clashes.</para></listitem>
470 </varlistentry>
471
472 <varlistentry>
473 <term><filename>/proc</filename></term>
474 <listitem><para>A virtual kernel file
475 system exposing the process list and
476 other functionality. This file system
477 is mostly an API to interface with the
478 kernel and not a place where normal
479 files may be stored. For details, see
480 <citerefentry><refentrytitle>proc</refentrytitle><manvolnum>5</manvolnum></citerefentry>. A
481 number of special purpose virtual file
482 systems might be mounted below this
483 directory.</para></listitem>
484 </varlistentry>
485
486 <varlistentry>
487 <term><filename>/proc/sys</filename></term>
488 <listitem><para>A hierarchy below
489 <filename>/proc</filename> that
490 exposes a number of kernel
491 tunables. The primary way to configure
492 the settings in this API file tree is
493 via
494 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
495 files. In sandboxed/containerized
496 setups this directory is generally
497 mounted read-only.</para></listitem>
498 </varlistentry>
499
500 <varlistentry>
501 <term><filename>/sys</filename></term>
502 <listitem><para>A virtual kernel file
503 system exposing discovered devices and
504 other functionality. This file system
505 is mostly an API to interface with the
506 kernel and not a place where normal
507 files may be stored. In
508 sandboxed/containerized setups this
509 directory is generally mounted
510 read-only. A number of special purpose
511 virtual file systems might be mounted
512 below this
513 directory.</para></listitem>
514 </varlistentry>
515
516
517 </variablelist>
518 </refsect1>
519
520 <refsect1>
521 <title>Compatibility Symlinks</title>
522
523 <variablelist>
524 <varlistentry>
525 <term><filename>/bin</filename></term>
526 <term><filename>/sbin</filename></term>
527 <term><filename>/usr/sbin</filename></term>
528
529 <listitem><para>These compatibility
530 symlinks point to
531 <filename>/usr/bin</filename>,
532 ensuring that scripts and binaries
533 referencing these legacy paths
534 correctly find their binaries.</para></listitem>
535 </varlistentry>
536
537 <varlistentry>
538 <term><filename>/lib</filename></term>
539
540 <listitem><para>This compatibility
541 symlink points to
542 <filename>/usr/lib</filename>,
543 ensuring that binaries referencing
544 this legacy path correctly find
545 their libraries.</para></listitem>
546 </varlistentry>
547
548 <varlistentry>
549 <term><filename>/lib64</filename></term>
550
551 <listitem><para>This compatibility
552 symlink points to
553 <filename>/usr/lib64</filename>,
554 ensuring that binaries referencing
555 this legacy path correctly find their
556 libraries. This symlink only exists on
557 architectures whose ABI requires a
558 64bit version of the library
559 directory.</para></listitem>
560 </varlistentry>
561
562 <varlistentry>
563 <term><filename>/var/run</filename></term>
564
565 <listitem><para>This compatibility
566 symlink points to
567 <filename>/run</filename>, ensuring
568 that programs referencing this legacy
569 path correctly find their runtime
570 data.</para></listitem>
571 </varlistentry>
572
573 </variablelist>
574 </refsect1>
575
576 <refsect1>
577 <title>System Packages</title>
578
579 <para>Developers of system packages should follow
580 strict rules when placing their own files in the file
581 system. The following table lists recommended
582 locations for specific types of files.</para>
583
584 <table>
585 <title>System Package Data Location</title>
586 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
587 <colspec colname="directory" />
588 <colspec colname="purpose" />
589 <thead>
590 <row>
591 <entry>Directory</entry>
592 <entry>Purpose</entry>
593 </row>
594 </thead>
595 <tbody>
596 <row>
597 <entry><filename>/usr/bin</filename></entry>
598 <entry>Package executables that shall appear in the <varname>$PATH</varname> 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.</entry>
599 </row>
600 <row>
601 <entry><filename>/usr/lib</filename></entry>
602 <entry>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.</entry>
603 </row>
604 <row>
605 <entry><filename>/usr/lib/<replaceable>package</replaceable></filename></entry>
606 <entry>Private other vendor resources of the package, including private binaries and libraries, but also including any other kind of read-only vendor data.</entry>
607 </row>
608 <row>
609 <entry><filename>/usr/lib64</filename></entry>
610 <entry>Public shared libraries of the package, compiled for the secondary, 64bit architecture, if this is part of the Operating System ABI.</entry>
611 </row>
612 <row>
613 <entry><filename>/usr/lib64/<replaceable>package</replaceable></filename></entry>
614 <entry>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.</entry>
615 </row>
616 <row>
617 <entry><filename>/usr/include/<replaceable>package</replaceable></filename></entry>
618 <entry>Public C/C++ APIs of public shared libraries of the package.</entry>
619 </row>
620 <row>
621 <entry><filename>/etc/<replaceable>package</replaceable></filename></entry>
622 <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 directores from <filename>/usr/share/factory</filename> during boot, via the <literal>L</literal> or <literal>C</literal> directives.</entry>
623 </row>
624 <row>
625 <entry><filename>/run/<replaceable>package</replaceable></filename></entry>
626 <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.</entry>
627 </row>
628 <row>
629 <entry><filename>/run/log/<replaceable>package</replaceable></filename></entry>
630 <entry>Runtime log data for the package.</entry>
631 </row>
632 <row>
633 <entry><filename>/var/cache/<replaceable>package</replaceable></filename></entry>
634 <entry>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.</entry>
635 </row>
636 <row>
637 <entry><filename>/var/lib/<replaceable>package</replaceable></filename></entry>
638 <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. Alternatively, a <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> fragment may be used to create the necessary directories during boot.</entry>
639 </row>
640 <row>
641 <entry><filename>/var/log/<replaceable>package</replaceable></filename></entry>
642 <entry>Persistent log data of the package.</entry>
643 </row>
644 <row>
645 <entry><filename>/var/spool/<replaceable>package</replaceable></filename></entry>
646 <entry>Persistent spool/queue data of the package.</entry>
647 </row>
648 </tbody>
649 </tgroup>
650 </table>
651 </refsect1>
652
653 <refsect1>
654 <title>See Also</title>
655 <para>
656 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
657 <citerefentry><refentrytitle>hier</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
658 <citerefentry><refentrytitle>systemd-boot-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
659 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
660 </para>
661 </refsect1>
662
663</refentry>