1PORTABLECTL(1) portablectl PORTABLECTL(1)
2
3
4
6 portablectl - Attach, detach or inspect portable service images
7
9 portablectl [OPTIONS...] {COMMAND} [NAME...]
10
12 portablectl may be used to attach, detach or inspect portable service
13 images. It's primarily a command interfacing with systemd-
14 portabled.service(8).
15
16 Portable service images contain an OS file system tree along with
17 systemd(1) unit file information. A service image may be "attached" to
18 the local system. If attached, a set of unit files are copied from the
19 image to the host, and extended with RootDirectory= or RootImage=
20 assignments (in case of service units) pointing to the image file or
21 directory, ensuring the services will run within the file system
22 context of the image.
23
24 Portable service images are an efficient way to bundle multiple related
25 services and other units together, and transfer them as a whole between
26 systems. When these images are attached the local system the contained
27 units may run in most ways like regular system-provided units, either
28 with full privileges or inside strict sandboxing, depending on the
29 selected configuration.
30
31 Specifically portable service images may be of the following kind:
32
33 • Directory trees containing an OS, including the top-level
34 directories /usr/, /etc/, and so on.
35
36 • btrfs subvolumes containing OS trees, similar to normal directory
37 trees.
38
39 • Binary "raw" disk images containing MBR or GPT partition tables and
40 Linux file system partitions. (These must be regular files, with
41 the .raw suffix.)
42
44 The following commands are understood:
45
46 list
47 List available portable service images. This will list all portable
48 service images discovered in the portable image search paths (see
49 below), along with brief metadata and state information. Note that
50 many of the commands below may both operate on images inside and
51 outside of the search paths. This command is hence mostly a
52 convenience option, the commands are generally not restricted to
53 what this list shows.
54
55 attach IMAGE [PREFIX...]
56 Attach a portable service image to the host system. Expects a file
57 system path to a portable service image file or directory as first
58 argument. If the specified path contains no slash character ("/")
59 it is understood as image filename that is searched for in the
60 portable service image search paths (see below). To reference a
61 file in the current working directory prefix the filename with "./"
62 to avoid this search path logic.
63
64 When a portable service is attached four operations are executed:
65
66 1. All unit files of types .service, .socket, .target, .timer and
67 .path which match the indicated unit file name prefix are
68 copied from the image to the host's
69 /etc/systemd/system.attached/ directory (or
70 /run/systemd/system.attached/ — depending whether --runtime is
71 specified, see above), which is included in the built-in unit
72 search path of the system service manager.
73
74 2. For unit files of type .service a drop-in is added to these
75 copies that adds RootDirectory= or RootImage= settings (see
76 systemd.unit(5) for details), that ensures these services are
77 run within the file system of the originating portable service
78 image.
79
80 3. A second drop-in is created: the "profile" drop-in, that may
81 contain additional security settings (and other settings). A
82 number of profiles are available by default but administrators
83 may define their own ones. See below.
84
85 4. If the portable service image file is not already in the search
86 path (see below), a symbolic link to it is created in
87 /etc/portables/ or /run/portables/, to make sure it is included
88 in it.
89
90 By default all unit files whose names start with a prefix generated
91 from the image's file name are copied out. Specifically, the prefix
92 is determined from the image file name with any suffix such as .raw
93 removed, truncated at the first occurrence of an underscore
94 character ("_"), if there is one. The underscore logic is supposed
95 to be used to versioning so that the an image file foobar_47.11.raw
96 will result in a unit file matching prefix of foobar. This prefix
97 is then compared with all unit files names contained in the image
98 in the usual directories, but only unit file names where the prefix
99 is followed by "-", "." or "@" are considered. Example: if a
100 portable service image file is named foobar_47.11.raw then by
101 default all its unit files with names such as
102 foobar-quux-waldi.service, foobar.service or foobar@.service will
103 be considered. It's possible to override the matching prefix: all
104 strings listed on the command line after the image file name are
105 considered prefixes, overriding the implicit logic where the prefix
106 is derived from the image file name.
107
108 By default, after the unit files are attached the service manager's
109 configuration is reloaded, except when --no-reload is specified
110 (see above). This ensures that the new units made available to the
111 service manager are seen by it.
112
113 If --now and/or --enable are passed, the portable service(s) are
114 immediately started (blocking operation unless --no-block is
115 passed) and/or enabled after attaching the image.
116
117 detach IMAGE [PREFIX...]
118 Detaches a portable service image from the host. This undoes the
119 operations executed by the attach command above, and removes the
120 unit file copies, drop-ins and image symlink again. This command
121 expects an image name or path as parameter. Note that if a path is
122 specified only the last component of it (i.e. the file or directory
123 name itself, not the path to it) is used for finding matching unit
124 files. This is a convenience feature to allow all arguments passed
125 as attach also to detach.
126
127 If --now and/or --enable are passed, the portable service(s) are
128 immediately stopped (blocking operation) and/or disabled before
129 detaching the image. Prefix(es) are also accepted, to be used in
130 case the unit names do not match the image name as described in the
131 attach.
132
133 reattach IMAGE [PREFIX...]
134 Detaches an existing portable service image from the host, and
135 immediately attaches it again. This is useful in case the image was
136 replaced. Running units are not stopped during the process. Partial
137 matching, to allow for different versions in the image name, is
138 allowed: only the part before the first "_" character has to match.
139 If the new image doesn't exist, the existing one will not be
140 detached. The parameters follow the same syntax as the attach
141 command.
142
143 If --now and/or --enable are passed, the portable service(s) are
144 immediately stopped if removed, started and/or enabled if added, or
145 restarted if updated. Prefixes are also accepted, in the same way
146 as described in the attach case.
147
148 inspect IMAGE [PREFIX...]
149 Extracts various metadata from a portable service image and
150 presents it to the caller. Specifically, the os-release(5) file of
151 the image is retrieved as well as all matching unit files. By
152 default a short summary showing the most relevant metadata in
153 combination with a list of matching unit files is shown (that is
154 the unit files attach would install to the host system). If
155 combined with --cat (see above), the os-release data and the units
156 files' contents is displayed unprocessed. This command is useful to
157 determine whether an image qualifies as portable service image, and
158 which unit files are included. This command expects the path to the
159 image as parameter, optionally followed by a list of unit file
160 prefixes to consider, similar to the attach command described
161 above.
162
163 is-attached IMAGE
164 Determines whether the specified image is currently attached or
165 not. Unless combined with the --quiet switch this will show a short
166 state identifier for the image. Specifically:
167
168 Table 1. Image attachment states
169 ┌─────────────────┬────────────────────────────┐
170 │State │ Description │
171 ├─────────────────┼────────────────────────────┤
172 │detached │ The image is currently not │
173 │ │ attached. │
174 ├─────────────────┼────────────────────────────┤
175 │attached │ The image is currently │
176 │ │ attached, i.e. its unit │
177 │ │ files have been made │
178 │ │ available to the host │
179 │ │ system. │
180 ├─────────────────┼────────────────────────────┤
181 │attached-runtime │ Like attached, but the │
182 │ │ unit files have been made │
183 │ │ available transiently │
184 │ │ only, i.e. the attach │
185 │ │ command has been invoked │
186 │ │ with the --runtime option. │
187 ├─────────────────┼────────────────────────────┤
188 │enabled │ The image is currently │
189 │ │ attached, and at least one │
190 │ │ unit file associated with │
191 │ │ it has been enabled. │
192 ├─────────────────┼────────────────────────────┤
193 │enabled-runtime │ Like enabled, but the unit │
194 │ │ files have been made │
195 │ │ available transiently │
196 │ │ only, i.e. the attach │
197 │ │ command has been invoked │
198 │ │ with the --runtime option. │
199 ├─────────────────┼────────────────────────────┤
200 │running │ The image is currently │
201 │ │ attached, and at least one │
202 │ │ unit file associated with │
203 │ │ it is running. │
204 ├─────────────────┼────────────────────────────┤
205 │running-runtime │ The image is currently │
206 │ │ attached transiently, and │
207 │ │ at least one unit file │
208 │ │ associated with it is │
209 │ │ running. │
210 └─────────────────┴────────────────────────────┘
211
212 read-only IMAGE [BOOL]
213 Marks or (unmarks) a portable service image read-only. Takes an
214 image name, followed by a boolean as arguments. If the boolean is
215 omitted, positive is implied, i.e. the image is marked read-only.
216
217 remove IMAGE...
218 Removes one or more portable service images. Note that this command
219 will only remove the specified image path itself — it refers to a
220 symbolic link then the symbolic link is removed and not the image
221 it points to.
222
223 set-limit [IMAGE] BYTES
224 Sets the maximum size in bytes that a specific portable service
225 image, or all images, may grow up to on disk (disk quota). Takes
226 either one or two parameters. The first, optional parameter refers
227 to a portable service image name. If specified, the size limit of
228 the specified image is changed. If omitted, the overall size limit
229 of the sum of all images stored locally is changed. The final
230 argument specifies the size limit in bytes, possibly suffixed by
231 the usual K, M, G, T units. If the size limit shall be disabled,
232 specify "-" as size.
233
234 Note that per-image size limits are only supported on btrfs file
235 systems. Also, depending on BindPaths= settings in the portable
236 service's unit files directories from the host might be visible in
237 the image environment during runtime which are not affected by this
238 setting, as only the image itself is counted against this limit.
239
241 The following options are understood:
242
243 -q, --quiet
244 Suppresses additional informational output while running.
245
246 -p PROFILE, --profile=PROFILE
247 When attaching an image, select the profile to use. By default the
248 "default" profile is used. For details about profiles, see below.
249
250 --copy=
251 When attaching an image, select whether to prefer copying or
252 symlinking of files installed into the host system. Takes one of
253 "copy" (to prefer copying of files), "symlink" (to prefer creation
254 of symbolic links) or "auto" for an intermediary mode where
255 security profile drop-ins are symlinked while unit files are
256 copied. Note that this option expresses a preference only, in cases
257 where symbolic links cannot be created — for example when the image
258 operated on is a raw disk image, and hence not directly
259 referentiable from the host file system — copying of files is used
260 unconditionally.
261
262 --runtime
263 When specified the unit and drop-in files are placed in
264 /run/systemd/system.attached/ instead of
265 /etc/systemd/system.attached/. Images attached with this option set
266 hence remain attached only until the next reboot, while they are
267 normally attached persistently.
268
269 --no-reload
270 Don't reload the service manager after attaching or detaching a
271 portable service image. Normally the service manager is reloaded to
272 ensure it is aware of added or removed unit files.
273
274 --cat
275 When inspecting portable service images, show the (unprocessed)
276 contents of the metadata files pulled from the image, instead of
277 brief summaries. Specifically, this will show the os-release(5) and
278 unit file contents of the image.
279
280 --enable
281 Immediately enable/disable the portable service after
282 attaching/detaching.
283
284 --now
285 Immediately start/stop/restart the portable service after
286 attaching/before detaching/after upgrading.
287
288 --no-block
289 Don't block waiting for attach --now to complete.
290
291 --extension=PATH
292 Add an additional image PATH as an overlay on top of IMAGE when
293 attaching/detaching. This argument can be specified multiple times,
294 in which case the order in which images are laid down follows the
295 rules specified in systemd.exec(5) for the ExtensionImages=
296 directive.
297
298 Note that the same extensions have to be specified, in the same
299 order, when attaching and detaching.
300
301 -H, --host=
302 Execute the operation remotely. Specify a hostname, or a username
303 and hostname separated by "@", to connect to. The hostname may
304 optionally be suffixed by a port ssh is listening on, separated by
305 ":", and then a container name, separated by "/", which connects
306 directly to a specific container on the specified host. This will
307 use SSH to talk to the remote machine manager instance. Container
308 names may be enumerated with machinectl -H HOST. Put IPv6 addresses
309 in brackets.
310
311 -M, --machine=
312 Execute operation on a local container. Specify a container name to
313 connect to, optionally prefixed by a user name to connect as and a
314 separating "@" character. If the special string ".host" is used in
315 place of the container name, a connection to the local system is
316 made (which is useful to connect to a specific user's user bus:
317 "--user --machine=lennart@.host"). If the "@" syntax is not used,
318 the connection is made as root user. If the "@" syntax is used
319 either the left hand side or the right hand side may be omitted
320 (but not both) in which case the local user name and ".host" are
321 implied.
322
323 --no-pager
324 Do not pipe output into a pager.
325
326 --no-legend
327 Do not print the legend, i.e. column headers and the footer with
328 hints.
329
330 --no-ask-password
331 Do not query the user for authentication for privileged operations.
332
333 -h, --help
334 Print a short help text and exit.
335
336 --version
337 Print a short version string and exit.
338
340 Portable service images are preferably stored in /var/lib/portables/,
341 but are also searched for in /etc/portables/, /run/systemd/portables/,
342 /usr/local/lib/portables/ and /usr/lib/portables/. It's recommended not
343 to place image files directly in /etc/portables/ or
344 /run/systemd/portables/ (as these are generally not suitable for
345 storing large or non-textual data), but use these directories only for
346 linking images located elsewhere into the image search path.
347
348 When a portable service image is attached, matching unit files are
349 copied onto the host into the /etc/systemd/system.attached/ and
350 /run/systemd/system.attached/ directories. When an image is detached,
351 the unit files are removed again from these directories.
352
354 When portable service images are attached a "profile" drop-in is linked
355 in, which may be used to enforce additional security (and other)
356 restrictions locally. Four profile drop-ins are defined by default, and
357 shipped in /usr/lib/systemd/portable/profile/. Additional, local
358 profiles may be defined by placing them in
359 /etc/systemd/portable/profile/. The default profiles are:
360
361 Table 2. Profiles
362 ┌──────────┬────────────────────────────┐
363 │Name │ Description │
364 ├──────────┼────────────────────────────┤
365 │default │ This is the default │
366 │ │ profile if no other │
367 │ │ profile name is set via │
368 │ │ the --profile= (see │
369 │ │ above). It's fairly │
370 │ │ restrictive, but should be │
371 │ │ useful for common, │
372 │ │ unprivileged system │
373 │ │ workloads. This includes │
374 │ │ write access to the │
375 │ │ logging framework, as well │
376 │ │ as IPC access to the D-Bus │
377 │ │ system. │
378 ├──────────┼────────────────────────────┤
379 │nonetwork │ Very similar to default, │
380 │ │ but networking is turned │
381 │ │ off for any services of │
382 │ │ the portable service │
383 │ │ image. │
384 ├──────────┼────────────────────────────┤
385 │strict │ A profile with very strict │
386 │ │ settings. This profile │
387 │ │ excludes IPC (D-Bus) and │
388 │ │ network access. │
389 ├──────────┼────────────────────────────┤
390 │trusted │ A profile with very │
391 │ │ relaxed settings. In this │
392 │ │ profile the services run │
393 │ │ with full privileges. │
394 └──────────┴────────────────────────────┘
395
396 For details on these profiles and their effects see their precise
397 definitions, e.g.
398 /usr/lib/systemd/portable/profile/default/service.conf and similar.
399
401 On success, 0 is returned, a non-zero failure code otherwise.
402
404 $SYSTEMD_LOG_LEVEL
405 The maximum log level of emitted messages (messages with a higher
406 log level, i.e. less important ones, will be suppressed). Either
407 one of (in order of decreasing importance) emerg, alert, crit, err,
408 warning, notice, info, debug, or an integer in the range 0...7. See
409 syslog(3) for more information.
410
411 $SYSTEMD_LOG_COLOR
412 A boolean. If true, messages written to the tty will be colored
413 according to priority.
414
415 This setting is only useful when messages are written directly to
416 the terminal, because journalctl(1) and other tools that display
417 logs will color messages based on the log level on their own.
418
419 $SYSTEMD_LOG_TIME
420 A boolean. If true, console log messages will be prefixed with a
421 timestamp.
422
423 This setting is only useful when messages are written directly to
424 the terminal or a file, because journalctl(1) and other tools that
425 display logs will attach timestamps based on the entry metadata on
426 their own.
427
428 $SYSTEMD_LOG_LOCATION
429 A boolean. If true, messages will be prefixed with a filename and
430 line number in the source code where the message originates.
431
432 Note that the log location is often attached as metadata to journal
433 entries anyway. Including it directly in the message text can
434 nevertheless be convenient when debugging programs.
435
436 $SYSTEMD_LOG_TID
437 A boolean. If true, messages will be prefixed with the current
438 numerical thread ID (TID).
439
440 Note that the this information is attached as metadata to journal
441 entries anyway. Including it directly in the message text can
442 nevertheless be convenient when debugging programs.
443
444 $SYSTEMD_LOG_TARGET
445 The destination for log messages. One of console (log to the
446 attached tty), console-prefixed (log to the attached tty but with
447 prefixes encoding the log level and "facility", see syslog(3), kmsg
448 (log to the kernel circular log buffer), journal (log to the
449 journal), journal-or-kmsg (log to the journal if available, and to
450 kmsg otherwise), auto (determine the appropriate log target
451 automatically, the default), null (disable log output).
452
453 $SYSTEMD_PAGER
454 Pager to use when --no-pager is not given; overrides $PAGER. If
455 neither $SYSTEMD_PAGER nor $PAGER are set, a set of well-known
456 pager implementations are tried in turn, including less(1) and
457 more(1), until one is found. If no pager implementation is
458 discovered no pager is invoked. Setting this environment variable
459 to an empty string or the value "cat" is equivalent to passing
460 --no-pager.
461
462 $SYSTEMD_LESS
463 Override the options passed to less (by default "FRSXMK").
464
465 Users might want to change two options in particular:
466
467 K
468 This option instructs the pager to exit immediately when Ctrl+C
469 is pressed. To allow less to handle Ctrl+C itself to switch
470 back to the pager command prompt, unset this option.
471
472 If the value of $SYSTEMD_LESS does not include "K", and the
473 pager that is invoked is less, Ctrl+C will be ignored by the
474 executable, and needs to be handled by the pager.
475
476 X
477 This option instructs the pager to not send termcap
478 initialization and deinitialization strings to the terminal. It
479 is set by default to allow command output to remain visible in
480 the terminal even after the pager exits. Nevertheless, this
481 prevents some pager functionality from working, in particular
482 paged output cannot be scrolled with the mouse.
483
484 See less(1) for more discussion.
485
486 $SYSTEMD_LESSCHARSET
487 Override the charset passed to less (by default "utf-8", if the
488 invoking terminal is determined to be UTF-8 compatible).
489
490 $SYSTEMD_PAGERSECURE
491 Takes a boolean argument. When true, the "secure" mode of the pager
492 is enabled; if false, disabled. If $SYSTEMD_PAGERSECURE is not set
493 at all, secure mode is enabled if the effective UID is not the same
494 as the owner of the login session, see geteuid(2) and
495 sd_pid_get_owner_uid(3). In secure mode, LESSSECURE=1 will be set
496 when invoking the pager, and the pager shall disable commands that
497 open or create new files or start new subprocesses. When
498 $SYSTEMD_PAGERSECURE is not set at all, pagers which are not known
499 to implement secure mode will not be used. (Currently only less(1)
500 implements secure mode.)
501
502 Note: when commands are invoked with elevated privileges, for
503 example under sudo(8) or pkexec(1), care must be taken to ensure
504 that unintended interactive features are not enabled. "Secure" mode
505 for the pager may be enabled automatically as describe above.
506 Setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited
507 environment allows the user to invoke arbitrary commands. Note that
508 if the $SYSTEMD_PAGER or $PAGER variables are to be honoured,
509 $SYSTEMD_PAGERSECURE must be set too. It might be reasonable to
510 completely disable the pager using --no-pager instead.
511
512 $SYSTEMD_COLORS
513 Takes a boolean argument. When true, systemd and related utilities
514 will use colors in their output, otherwise the output will be
515 monochrome. Additionally, the variable can take one of the
516 following special values: "16", "256" to restrict the use of colors
517 to the base 16 or 256 ANSI colors, respectively. This can be
518 specified to override the automatic decision based on $TERM and
519 what the console is connected to.
520
521 $SYSTEMD_URLIFY
522 The value must be a boolean. Controls whether clickable links
523 should be generated in the output for terminal emulators supporting
524 this. This can be specified to override the decision that systemd
525 makes based on $TERM and other conditions.
526
528 systemd(1), org.freedesktop.portable1(5), systemd-portabled.service(8)
529
530
531
532systemd 249 PORTABLECTL(1)