1<?xml version='1.0'?>
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="portablectl" conditional='ENABLE_PORTABLED'
7    xmlns:xi="http://www.w3.org/2001/XInclude">
8
9  <refentryinfo>
10    <title>portablectl</title>
11    <productname>systemd</productname>
12  </refentryinfo>
13
14  <refmeta>
15    <refentrytitle>portablectl</refentrytitle>
16    <manvolnum>1</manvolnum>
17  </refmeta>
18
19  <refnamediv>
20    <refname>portablectl</refname>
21    <refpurpose>Attach, detach or inspect portable service images</refpurpose>
22  </refnamediv>
23
24  <refsynopsisdiv>
25    <cmdsynopsis>
26      <command>portablectl</command>
27      <arg choice="opt" rep="repeat">OPTIONS</arg>
28      <arg choice="req">COMMAND</arg>
29      <arg choice="opt" rep="repeat">NAME</arg>
30    </cmdsynopsis>
31  </refsynopsisdiv>
32
33  <refsect1>
34    <title>Description</title>
35
36    <para><command>portablectl</command> may be used to attach, detach or inspect portable service images. It's
37    primarily a command interfacing with
38    <citerefentry><refentrytitle>systemd-portabled.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
39
40    <para>Portable service images contain an OS file system tree along with
41    <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> unit file
42    information. A service image may be "attached" to the local system. If attached, a set of unit files are copied
43    from the image to the host, and extended with <varname>RootDirectory=</varname> or <varname>RootImage=</varname>
44    assignments (in case of service units) pointing to the image file or directory, ensuring the services will run
45    within the file system context of the image.</para>
46
47    <para>Portable service images are an efficient way to bundle multiple related services and other units together,
48    and transfer them as a whole between systems. When these images are attached the local system the contained units
49    may run in most ways like regular system-provided units, either with full privileges or inside strict sandboxing,
50    depending on the selected configuration. For more details, see
51    <ulink url="https://systemd.io/PORTABLE_SERVICES">Portable Services</ulink>.</para>
52
53    <para>Specifically portable service images may be of the following kind:</para>
54
55    <itemizedlist>
56      <listitem><para>Directory trees containing an OS, including the top-level directories <filename>/usr/</filename>,
57      <filename>/etc/</filename>, and so on.</para></listitem>
58
59      <listitem><para>btrfs subvolumes containing OS trees, similar to normal directory trees.</para></listitem>
60
61      <listitem><para>Binary "raw" disk images containing MBR or GPT partition tables and Linux file system
62      partitions. (These must be regular files, with the <filename>.raw</filename> suffix.)</para></listitem>
63    </itemizedlist>
64
65  </refsect1>
66
67  <refsect1>
68    <title>Commands</title>
69
70    <para>The following commands are understood:</para>
71
72    <variablelist>
73
74      <varlistentry>
75        <term><command>list</command></term>
76
77        <listitem><para>List available portable service images. This will list all portable service images discovered
78        in the portable image search paths (see below), along with brief metadata and state information. Note that many
79        of the commands below may both operate on images inside and outside of the search paths. This command is hence
80        mostly a convenience option, the commands are generally not restricted to what this list
81        shows.</para></listitem>
82      </varlistentry>
83
84      <varlistentry>
85        <term><command>attach</command> <replaceable>IMAGE</replaceable> [<replaceable>PREFIX…</replaceable>]</term>
86
87        <listitem><para>Attach a portable service image to the host system. Expects a file system path to a portable
88        service image file or directory as first argument. If the specified path contains no slash character
89        (<literal>/</literal>) it is understood as image filename that is searched for in the portable service image
90        search paths (see below). To reference a file in the current working directory prefix the filename with
91        <literal>./</literal> to avoid this search path logic.</para>
92
93        <para>When a portable service is attached four operations are executed:</para>
94
95        <orderedlist>
96
97          <listitem><para>All unit files of types <filename>.service</filename>, <filename>.socket</filename>,
98          <filename>.target</filename>, <filename>.timer</filename> and <filename>.path</filename> which match the
99          indicated unit file name prefix are copied from the image to the host's
100          <filename>/etc/systemd/system.attached/</filename> directory (or
101          <filename>/run/systemd/system.attached/</filename> — depending whether <option>--runtime</option> is
102          specified, see above), which is included in the built-in unit search path of the system service
103          manager.</para></listitem>
104
105          <listitem><para>For unit files of type <filename>.service</filename> a drop-in is added to these copies that
106          adds <varname>RootDirectory=</varname> or <varname>RootImage=</varname> settings (see
107          <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
108          details), that ensures these services are run within the file system of the originating portable service
109          image.</para></listitem>
110
111          <listitem><para>A second drop-in is created: the "profile" drop-in, that may contain additional security
112          settings (and other settings). A number of profiles are available by default but administrators may define
113          their own ones. See below.</para></listitem>
114
115          <listitem><para>If the portable service image file is not already in the search path (see below), a symbolic
116          link to it is created in <filename>/etc/portables/</filename> or
117          <filename>/run/portables/</filename>, to make sure it is included in it.</para></listitem>
118        </orderedlist>
119
120        <para>By default all unit files whose names start with a prefix generated from the image's file name are copied
121        out. Specifically, the prefix is determined from the image file name with any suffix such as
122        <filename>.raw</filename> removed, truncated at the first occurrence of an underscore character
123        (<literal>_</literal>), if there is one. The underscore logic is supposed to be used to versioning so that the
124        an image file <filename>foobar_47.11.raw</filename> will result in a unit file matching prefix of
125        <filename>foobar</filename>. This prefix is then compared with all unit files names contained in the image in
126        the usual directories, but only unit file names where the prefix is followed by <literal>-</literal>,
127        <literal>.</literal> or <literal>@</literal> are considered. Example: if a portable service image file is named
128        <filename>foobar_47.11.raw</filename> then by default all its unit files with names such as
129        <filename>foobar-quux-waldi.service</filename>, <filename>foobar.service</filename> or
130        <filename>foobar@.service</filename> will be considered. It's possible to override the matching prefix: all
131        strings listed on the command line after the image file name are considered prefixes, overriding the implicit
132        logic where the prefix is derived from the image file name.</para>
133
134        <para>By default, after the unit files are attached the service manager's configuration is reloaded, except
135        when <option>--no-reload</option> is specified (see above). This ensures that the new units made available to
136        the service manager are seen by it.</para>
137
138        <para>If <option>--now</option> and/or <option>--enable</option> are passed, the portable service(s) are
139        immediately started (blocking operation unless <option>--no-block</option> is passed) and/or enabled after
140        attaching the image.</para>
141        </listitem>
142      </varlistentry>
143
144      <varlistentry>
145        <term><command>detach</command> <replaceable>IMAGE</replaceable> [<replaceable>PREFIX…</replaceable>]</term>
146
147        <listitem><para>Detaches a portable service image from the host. This undoes the operations executed by the
148        <command>attach</command> command above, and removes the unit file copies, drop-ins and image symlink
149        again. This command expects an image name or path as parameter. Note that if a path is specified only the last
150        component of it (i.e. the file or directory name itself, not the path to it) is used for finding matching unit
151        files. This is a convenience feature to allow all arguments passed as <command>attach</command> also to
152        <command>detach</command>.</para></listitem>
153
154        <para>If <option>--now</option> and/or <option>--enable</option> are passed, the portable service(s) are
155        immediately stopped (blocking operation) and/or disabled before detaching the image. Prefix(es) are also accepted,
156        to be used in case the unit names do not match the image name as described in the <command>attach</command>.</para>
157      </varlistentry>
158
159      <varlistentry>
160        <term><command>reattach</command> <replaceable>IMAGE</replaceable> [<replaceable>PREFIX…</replaceable>]</term>
161
162        <listitem><para>Detaches an existing portable service image from the host, and immediately attaches it again.
163        This is useful in case the image was replaced. Running units are not stopped during the process. Partial matching,
164        to allow for different versions in the image name, is allowed: only the part before the first <literal>_</literal>
165        character has to match. If the new image doesn't exist, the existing one will not be detached. The parameters
166        follow the same syntax as the <command>attach</command> command.</para></listitem>
167
168        <para>If <option>--now</option> and/or <option>--enable</option> are passed, the portable service(s) are
169        immediately stopped if removed, started and/or enabled if added, or restarted if updated. Prefixes are also
170        accepted, in the same way as described in the <command>attach</command> case.</para>
171      </varlistentry>
172
173      <varlistentry>
174        <term><command>inspect</command> <replaceable>IMAGE</replaceable> [<replaceable>PREFIX…</replaceable>]</term>
175
176        <listitem><para>Extracts various metadata from a portable service image and presents it to the
177        caller. Specifically, the
178        <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> file of the
179        image is retrieved as well as all matching unit files. By default a short summary showing the most relevant
180        metadata in combination with a list of matching unit files is shown (that is the unit files
181        <command>attach</command> would install to the host system). If combined with <option>--cat</option> (see
182        above), the <filename>os-release</filename> data and the units files' contents is displayed unprocessed. This
183        command is useful to determine whether an image qualifies as portable service image, and which unit files are
184        included. This command expects the path to the image as parameter, optionally followed by a list of unit file
185        prefixes to consider, similar to the <command>attach</command> command described above.</para>
186        </listitem>
187      </varlistentry>
188
189      <varlistentry>
190        <term><command>is-attached</command> <replaceable>IMAGE</replaceable></term>
191
192        <listitem><para>Determines whether the specified image is currently attached or not. Unless combined with the
193        <option>--quiet</option> switch this will show a short state identifier for the image. Specifically:</para>
194
195        <table>
196          <title>Image attachment states</title>
197          <tgroup cols='2'>
198            <colspec colname='state'/>
199            <colspec colname='description'/>
200            <thead>
201              <row>
202                <entry>State</entry>
203                <entry>Description</entry>
204              </row>
205            </thead>
206            <tbody>
207              <row>
208                <entry><option>detached</option></entry>
209                <entry>The image is currently not attached.</entry>
210              </row>
211              <row>
212                <entry><option>attached</option></entry>
213                <entry>The image is currently attached, i.e. its unit files have been made available to the host system.</entry>
214              </row>
215              <row>
216                <entry><option>attached-runtime</option></entry>
217                <entry>Like <option>attached</option>, but the unit files have been made available transiently only, i.e. the <command>attach</command> command has been invoked with the <option>--runtime</option> option.</entry>
218              </row>
219              <row>
220                <entry><option>enabled</option></entry>
221                <entry>The image is currently attached, and at least one unit file associated with it has been enabled.</entry>
222              </row>
223              <row>
224                <entry><option>enabled-runtime</option></entry>
225                <entry>Like <option>enabled</option>, but the unit files have been made available transiently only, i.e. the <command>attach</command> command has been invoked with the <option>--runtime</option> option.</entry>
226              </row>
227              <row>
228                <entry><option>running</option></entry>
229                <entry>The image is currently attached, and at least one unit file associated with it is running.</entry>
230              </row>
231              <row>
232                <entry><option>running-runtime</option></entry>
233                <entry>The image is currently attached transiently, and at least one unit file associated with it is running.</entry>
234              </row>
235            </tbody>
236          </tgroup>
237        </table>
238
239        </listitem>
240      </varlistentry>
241
242      <varlistentry>
243        <term><command>read-only</command> <replaceable>IMAGE</replaceable> [<replaceable>BOOL</replaceable>]</term>
244
245        <listitem><para>Marks or (unmarks) a portable service image read-only. Takes an image name, followed by a
246        boolean as arguments. If the boolean is omitted, positive is implied, i.e. the image is marked
247        read-only.</para></listitem>
248      </varlistentry>
249
250      <varlistentry>
251        <term><command>remove</command> <replaceable>IMAGE</replaceable>…</term>
252
253        <listitem><para>Removes one or more portable service images. Note that this command will only remove the
254        specified image path itself — it refers to a symbolic link then the symbolic link is removed and not the
255        image it points to.</para></listitem>
256      </varlistentry>
257
258      <varlistentry>
259        <term><command>set-limit</command> [<replaceable>IMAGE</replaceable>] <replaceable>BYTES</replaceable></term>
260
261        <listitem><para>Sets the maximum size in bytes that a specific portable service image, or all images, may grow
262        up to on disk (disk quota). Takes either one or two parameters. The first, optional parameter refers to a
263        portable service image name. If specified, the size limit of the specified image is changed. If omitted, the
264        overall size limit of the sum of all images stored locally is changed. The final argument specifies the size
265        limit in bytes, possibly suffixed by the usual K, M, G, T units. If the size limit shall be disabled, specify
266        <literal>-</literal> as size.</para>
267
268        <para>Note that per-image size limits are only supported on btrfs file systems. Also, depending on
269        <varname>BindPaths=</varname> settings in the portable service's unit files directories from the host might be
270        visible in the image environment during runtime which are not affected by this setting, as only the image
271        itself is counted against this limit.</para></listitem>
272      </varlistentry>
273
274    </variablelist>
275
276  </refsect1>
277
278  <refsect1>
279    <title>Options</title>
280
281    <para>The following options are understood:</para>
282
283    <variablelist>
284      <varlistentry>
285        <term><option>-q</option></term>
286        <term><option>--quiet</option></term>
287
288        <listitem><para>Suppresses additional informational output while running.</para></listitem>
289      </varlistentry>
290
291      <varlistentry>
292        <term><option>-p</option> <replaceable>PROFILE</replaceable></term>
293        <term><option>--profile=</option><replaceable>PROFILE</replaceable></term>
294
295        <listitem><para>When attaching an image, select the profile to use. By default the <literal>default</literal>
296        profile is used. For details about profiles, see below.</para></listitem>
297      </varlistentry>
298
299      <varlistentry>
300        <term><option>--copy=</option></term>
301
302        <listitem><para>When attaching an image, select whether to prefer copying or symlinking of files installed into
303        the host system. Takes one of <literal>copy</literal> (to prefer copying of files), <literal>symlink</literal>
304        (to prefer creation of symbolic links) or <literal>auto</literal> for an intermediary mode where security
305        profile drop-ins are symlinked while unit files are copied. Note that this option expresses a preference only,
306        in cases where symbolic links cannot be created — for example when the image operated on is a raw disk image,
307        and hence not directly referentiable from the host file system — copying of files is used
308        unconditionally.</para></listitem>
309      </varlistentry>
310
311      <varlistentry>
312        <term><option>--runtime</option></term>
313
314        <listitem><para>When specified the unit and drop-in files are placed in
315        <filename>/run/systemd/system.attached/</filename> instead of
316        <filename>/etc/systemd/system.attached/</filename>. Images attached with this option set hence remain attached
317        only until the next reboot, while they are normally attached persistently.</para></listitem>
318      </varlistentry>
319
320      <varlistentry>
321        <term><option>--no-reload</option></term>
322
323        <listitem><para>Don't reload the service manager after attaching or detaching a portable service
324        image. Normally the service manager is reloaded to ensure it is aware of added or removed unit
325        files.</para></listitem>
326      </varlistentry>
327
328      <varlistentry>
329        <term><option>--cat</option></term>
330
331        <listitem><para>When inspecting portable service images, show the (unprocessed) contents of the metadata files
332        pulled from the image, instead of brief summaries. Specifically, this will show the
333        <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> and unit file
334        contents of the image.</para></listitem>
335      </varlistentry>
336
337      <varlistentry>
338        <term><option>--enable</option></term>
339
340        <listitem><para>Immediately enable/disable the portable service after attaching/detaching.</para></listitem>
341      </varlistentry>
342
343      <varlistentry>
344        <term><option>--now</option></term>
345
346        <listitem><para>Immediately start/stop/restart the portable service after attaching/before
347        detaching/after upgrading.</para></listitem>
348      </varlistentry>
349
350      <varlistentry>
351        <term><option>--no-block</option></term>
352
353        <listitem><para>Don't block waiting for attach --now to complete.</para></listitem>
354      </varlistentry>
355
356      <varlistentry>
357        <term><option>--extension=</option><replaceable>PATH</replaceable></term>
358
359        <listitem><para>Add an additional image <replaceable>PATH</replaceable> as an overlay on
360        top of <replaceable>IMAGE</replaceable> when attaching/detaching. This argument can be specified
361        multiple times, in which case the order in which images are laid down follows the rules specified in
362        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
363        for the <varname>ExtensionImages=</varname> directive and for the
364        <citerefentry><refentrytitle>systemd-sysext</refentrytitle><manvolnum>8</manvolnum></citerefentry> tool.
365        The image(s) must contain an <filename>extension-release</filename> file with metadata that matches
366        what is defined in the <filename>os-release</filename> of <replaceable>IMAGE</replaceable>. See:
367        <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
368        Images can be block images, btrfs subvolumes or directories. For more information on portable
369        services with extensions, see the <literal>Extension Images</literal> paragraph on
370        <ulink url="https://systemd.io/PORTABLE_SERVICES">Portable Services</ulink>.
371        </para>
372
373        <para>Note that the same extensions have to be specified, in the same order, when attaching
374        and detaching.</para></listitem>
375      </varlistentry>
376
377      <xi:include href="user-system-options.xml" xpointer="host" />
378      <xi:include href="user-system-options.xml" xpointer="machine" />
379
380      <xi:include href="standard-options.xml" xpointer="no-pager" />
381      <xi:include href="standard-options.xml" xpointer="no-legend" />
382      <xi:include href="standard-options.xml" xpointer="no-ask-password" />
383      <xi:include href="standard-options.xml" xpointer="help" />
384      <xi:include href="standard-options.xml" xpointer="version" />
385    </variablelist>
386  </refsect1>
387
388  <refsect1>
389    <title>Files and Directories</title>
390
391    <para>Portable service images are preferably stored in <filename>/var/lib/portables/</filename>, but are also
392    searched for in <filename>/etc/portables/</filename>, <filename>/run/systemd/portables/</filename>,
393    <filename>/usr/local/lib/portables/</filename> and <filename>/usr/lib/portables/</filename>. It's recommended not
394    to place image files directly in <filename>/etc/portables/</filename> or
395    <filename>/run/systemd/portables/</filename> (as these are generally not suitable for storing large or non-textual
396    data), but use these directories only for linking images located elsewhere into the image search path.</para>
397
398    <para>When a portable service image is attached, matching unit files are copied onto the host into the
399    <filename>/etc/systemd/system.attached/</filename> and <filename>/run/systemd/system.attached/</filename>
400    directories. When an image is detached, the unit files are removed again from these directories.</para>
401  </refsect1>
402
403  <refsect1>
404    <title>Profiles</title>
405
406    <para>When portable service images are attached a "profile" drop-in is linked in, which may be used to enforce
407    additional security (and other) restrictions locally. Four profile drop-ins are defined by default, and shipped in
408    <filename>/usr/lib/systemd/portable/profile/</filename>. Additional, local profiles may be defined by placing them
409    in <filename>/etc/systemd/portable/profile/</filename>. The default profiles are:</para>
410
411    <table>
412      <title>Profiles</title>
413      <tgroup cols='2'>
414        <colspec colname='state'/>
415        <colspec colname='description'/>
416        <thead>
417          <row>
418            <entry>Name</entry>
419            <entry>Description</entry>
420          </row>
421        </thead>
422        <tbody>
423          <row>
424            <entry><filename>default</filename></entry>
425            <entry>This is the default profile if no other profile name is set via the <option>--profile=</option> (see above). It's fairly restrictive, but should be useful for common, unprivileged system workloads. This includes write access to the logging framework, as well as IPC access to the D-Bus system.</entry>
426          </row>
427          <row>
428            <entry><filename>nonetwork</filename></entry>
429            <entry>Very similar to <filename>default</filename>, but networking is turned off for any services of the portable service image.</entry>
430          </row>
431          <row>
432            <entry><filename>strict</filename></entry>
433            <entry>A profile with very strict settings. This profile excludes IPC (D-Bus) and network access.</entry>
434          </row>
435          <row>
436            <entry><filename>trusted</filename></entry>
437            <entry>A profile with very relaxed settings. In this profile the services run with full privileges.</entry>
438          </row>
439        </tbody>
440      </tgroup>
441    </table>
442
443    <para>For details on these profiles and their effects see their precise definitions,
444    e.g. <filename>/usr/lib/systemd/portable/profile/default/service.conf</filename> and similar.</para>
445  </refsect1>
446
447  <refsect1>
448    <title>Exit status</title>
449
450    <para>On success, 0 is returned, a non-zero failure code otherwise.</para>
451  </refsect1>
452
453  <xi:include href="common-variables.xml" />
454
455  <refsect1>
456    <title>See Also</title>
457    <para>
458      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
459      <citerefentry><refentrytitle>systemd-sysext</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
460      <citerefentry><refentrytitle>org.freedesktop.portable1</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
461      <citerefentry><refentrytitle>systemd-portabled.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
462    </para>
463  </refsect1>
464
465</refentry>
466