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 -H, --host=
292 Execute the operation remotely. Specify a hostname, or a username
293 and hostname separated by "@", to connect to. The hostname may
294 optionally be suffixed by a port ssh is listening on, separated by
295 ":", and then a container name, separated by "/", which connects
296 directly to a specific container on the specified host. This will
297 use SSH to talk to the remote machine manager instance. Container
298 names may be enumerated with machinectl -H HOST. Put IPv6 addresses
299 in brackets.
300
301 -M, --machine=
302 Execute operation on a local container. Specify a container name to
303 connect to, optionally prefixed by a user name to connect as and a
304 separating "@" character. If the special string ".host" is used in
305 place of the container name, a connection to the local system is
306 made (which is useful to connect to a specific user's user bus:
307 "--user --machine=lennart@.host"). If the "@" syntax is not used,
308 the connection is made as root user. If the "@" syntax is used
309 either the left hand side or the right hand side may be omitted
310 (but not both) in which case the local user name and ".host" are
311 implied.
312
313 --no-pager
314 Do not pipe output into a pager.
315
316 --no-legend
317 Do not print the legend, i.e. column headers and the footer with
318 hints.
319
320 --no-ask-password
321 Do not query the user for authentication for privileged operations.
322
323 -h, --help
324 Print a short help text and exit.
325
326 --version
327 Print a short version string and exit.
328
330 Portable service images are preferably stored in /var/lib/portables/,
331 but are also searched for in /etc/portables/, /run/systemd/portables/,
332 /usr/local/lib/portables/ and /usr/lib/portables/. It's recommended not
333 to place image files directly in /etc/portables/ or
334 /run/systemd/portables/ (as these are generally not suitable for
335 storing large or non-textual data), but use these directories only for
336 linking images located elsewhere into the image search path.
337
338 When a portable service image is attached, matching unit files are
339 copied onto the host into the /etc/systemd/system.attached/ and
340 /run/systemd/system.attached/ directories. When an image is detached,
341 the unit files are removed again from these directories.
342
344 When portable service images are attached a "profile" drop-in is linked
345 in, which may be used to enforce additional security (and other)
346 restrictions locally. Four profile drop-ins are defined by default, and
347 shipped in /usr/lib/systemd/portable/profile/. Additional, local
348 profiles may be defined by placing them in
349 /etc/systemd/portable/profile/. The default profiles are:
350
351 Table 2. Profiles
352 ┌──────────┬────────────────────────────┐
353 │Name │ Description │
354 ├──────────┼────────────────────────────┤
355 │default │ This is the default │
356 │ │ profile if no other │
357 │ │ profile name is set via │
358 │ │ the --profile= (see │
359 │ │ above). It's fairly │
360 │ │ restrictive, but should be │
361 │ │ useful for common, │
362 │ │ unprivileged system │
363 │ │ workloads. This includes │
364 │ │ write access to the │
365 │ │ logging framework, as well │
366 │ │ as IPC access to the D-Bus │
367 │ │ system. │
368 ├──────────┼────────────────────────────┤
369 │nonetwork │ Very similar to default, │
370 │ │ but networking is turned │
371 │ │ off for any services of │
372 │ │ the portable service │
373 │ │ image. │
374 ├──────────┼────────────────────────────┤
375 │strict │ A profile with very strict │
376 │ │ settings. This profile │
377 │ │ excludes IPC (D-Bus) and │
378 │ │ network access. │
379 ├──────────┼────────────────────────────┤
380 │trusted │ A profile with very │
381 │ │ relaxed settings. In this │
382 │ │ profile the services run │
383 │ │ with full privileges. │
384 └──────────┴────────────────────────────┘
385
386 For details on these profiles and their effects see their precise
387 definitions, e.g.
388 /usr/lib/systemd/portable/profile/default/service.conf and similar.
389
391 On success, 0 is returned, a non-zero failure code otherwise.
392
394 $SYSTEMD_LOG_LEVEL
395 The maximum log level of emitted messages (messages with a higher
396 log level, i.e. less important ones, will be suppressed). Either
397 one of (in order of decreasing importance) emerg, alert, crit, err,
398 warning, notice, info, debug, or an integer in the range 0...7. See
399 syslog(3) for more information.
400
401 $SYSTEMD_LOG_COLOR
402 A boolean. If true, messages written to the tty will be colored
403 according to priority.
404
405 This setting is only useful when messages are written directly to
406 the terminal, because journalctl(1) and other tools that display
407 logs will color messages based on the log level on their own.
408
409 $SYSTEMD_LOG_TIME
410 A boolean. If true, log messages will be prefixed with a timestamp.
411
412 This setting is only useful when messages are written directly to
413 the terminal or a file, because journalctl(1) and other tools that
414 display logs will attach timestamps based on the entry metadata on
415 their own.
416
417 $SYSTEMD_LOG_LOCATION
418 A boolean. If true, messages will be prefixed with a filename and
419 line number in the source code where the message originates.
420
421 Note that the log location is often attached as metadata to journal
422 entries anyway. Including it directly in the message text can
423 nevertheless be convenient when debugging programs.
424
425 $SYSTEMD_LOG_TID
426 A boolean. If true, messages will be prefixed with the current
427 numerical thread ID (TID).
428
429 Note that the this information is attached as metadata to journal
430 entries anyway. Including it directly in the message text can
431 nevertheless be convenient when debugging programs.
432
433 $SYSTEMD_LOG_TARGET
434 The destination for log messages. One of console (log to the
435 attached tty), console-prefixed (log to the attached tty but with
436 prefixes encoding the log level and "facility", see syslog(3), kmsg
437 (log to the kernel circular log buffer), journal (log to the
438 journal), journal-or-kmsg (log to the journal if available, and to
439 kmsg otherwise), auto (determine the appropriate log target
440 automatically, the default), null (disable log output).
441
442 $SYSTEMD_PAGER
443 Pager to use when --no-pager is not given; overrides $PAGER. If
444 neither $SYSTEMD_PAGER nor $PAGER are set, a set of well-known
445 pager implementations are tried in turn, including less(1) and
446 more(1), until one is found. If no pager implementation is
447 discovered no pager is invoked. Setting this environment variable
448 to an empty string or the value "cat" is equivalent to passing
449 --no-pager.
450
451 $SYSTEMD_LESS
452 Override the options passed to less (by default "FRSXMK").
453
454 Users might want to change two options in particular:
455
456 K
457 This option instructs the pager to exit immediately when Ctrl+C
458 is pressed. To allow less to handle Ctrl+C itself to switch
459 back to the pager command prompt, unset this option.
460
461 If the value of $SYSTEMD_LESS does not include "K", and the
462 pager that is invoked is less, Ctrl+C will be ignored by the
463 executable, and needs to be handled by the pager.
464
465 X
466 This option instructs the pager to not send termcap
467 initialization and deinitialization strings to the terminal. It
468 is set by default to allow command output to remain visible in
469 the terminal even after the pager exits. Nevertheless, this
470 prevents some pager functionality from working, in particular
471 paged output cannot be scrolled with the mouse.
472
473 See less(1) for more discussion.
474
475 $SYSTEMD_LESSCHARSET
476 Override the charset passed to less (by default "utf-8", if the
477 invoking terminal is determined to be UTF-8 compatible).
478
479 $SYSTEMD_PAGERSECURE
480 Takes a boolean argument. When true, the "secure" mode of the pager
481 is enabled; if false, disabled. If $SYSTEMD_PAGERSECURE is not set
482 at all, secure mode is enabled if the effective UID is not the same
483 as the owner of the login session, see geteuid(2) and
484 sd_pid_get_owner_uid(3). In secure mode, LESSSECURE=1 will be set
485 when invoking the pager, and the pager shall disable commands that
486 open or create new files or start new subprocesses. When
487 $SYSTEMD_PAGERSECURE is not set at all, pagers which are not known
488 to implement secure mode will not be used. (Currently only less(1)
489 implements secure mode.)
490
491 Note: when commands are invoked with elevated privileges, for
492 example under sudo(8) or pkexec(1), care must be taken to ensure
493 that unintended interactive features are not enabled. "Secure" mode
494 for the pager may be enabled automatically as describe above.
495 Setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited
496 environment allows the user to invoke arbitrary commands. Note that
497 if the $SYSTEMD_PAGER or $PAGER variables are to be honoured,
498 $SYSTEMD_PAGERSECURE must be set too. It might be reasonable to
499 completely disable the pager using --no-pager instead.
500
501 $SYSTEMD_COLORS
502 Takes a boolean argument. When true, systemd and related utilities
503 will use colors in their output, otherwise the output will be
504 monochrome. Additionally, the variable can take one of the
505 following special values: "16", "256" to restrict the use of colors
506 to the base 16 or 256 ANSI colors, respectively. This can be
507 specified to override the automatic decision based on $TERM and
508 what the console is connected to.
509
510 $SYSTEMD_URLIFY
511 The value must be a boolean. Controls whether clickable links
512 should be generated in the output for terminal emulators supporting
513 this. This can be specified to override the decision that systemd
514 makes based on $TERM and other conditions.
515
517 systemd(1), org.freedesktop.portable1(5), systemd-portabled.service(8)
518
519
520
521systemd 248 PORTABLECTL(1)