]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-dissect.xml
Merge pull request #26695 from poettering/dissect-mount-helper
[thirdparty/systemd.git] / man / systemd-dissect.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="systemd-dissect" conditional='HAVE_BLKID'
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>systemd-dissect</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>systemd-dissect</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>systemd-dissect</refname>
21 <refname>mount.ddi</refname>
22 <refpurpose>Dissect Discoverable Disk Images (DDIs)</refpurpose>
23 </refnamediv>
24
25 <refsynopsisdiv>
26 <cmdsynopsis>
27 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="plain"><replaceable>IMAGE</replaceable></arg></command>
28 </cmdsynopsis>
29 <cmdsynopsis>
30 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--mount</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg> <arg choice="plain"><replaceable>PATH</replaceable></arg></command>
31 </cmdsynopsis>
32 <cmdsynopsis>
33 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--umount</option> <arg choice="plain"><replaceable>PATH</replaceable></arg></command>
34 </cmdsynopsis>
35 <cmdsynopsis>
36 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--list</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg></command>
37 </cmdsynopsis>
38 <cmdsynopsis>
39 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--mtree</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg></command>
40 </cmdsynopsis>
41 <cmdsynopsis>
42 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--with</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg> <arg choice="opt" rep="repeat"><replaceable>COMMAND</replaceable></arg></command>
43 </cmdsynopsis>
44 <cmdsynopsis>
45 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--copy-from</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg> <arg choice="plain"><replaceable>PATH</replaceable></arg> <arg choice="opt"><replaceable>TARGET</replaceable></arg></command>
46 </cmdsynopsis>
47 <cmdsynopsis>
48 <command>systemd-dissect <arg choice="opt" rep="repeat">OPTIONS</arg> <option>--copy-to</option> <arg choice="plain"><replaceable>IMAGE</replaceable></arg> <arg choice="opt"><replaceable>SOURCE</replaceable></arg> <arg choice="plain"><replaceable>PATH</replaceable></arg></command>
49 </cmdsynopsis>
50 </refsynopsisdiv>
51
52 <refsect1>
53 <title>Description</title>
54
55 <para><command>systemd-dissect</command> is a tool for introspecting and interacting with file system OS
56 disk images, specifically Discoverable Disk Images (DDIs). It supports four different operations:</para>
57
58 <orderedlist>
59 <listitem><para>Show general OS image information, including the image's
60 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> data,
61 machine ID, partition information and more.</para></listitem>
62
63 <listitem><para>Mount an OS image to a local directory. In this mode it will dissect the OS image and
64 mount the included partitions according to their designation onto a directory and possibly
65 sub-directories.</para></listitem>
66
67 <listitem><para>Unmount an OS image from a local directory. In this mode it will recursively unmount
68 the mounted partitions and remove the underlying loop device, including all the partition sub-devices.
69 </para></listitem>
70
71 <listitem><para>Copy files and directories in and out of an OS image.</para></listitem>
72 </orderedlist>
73
74 <para>The tool may operate on three types of OS images:</para>
75
76 <orderedlist>
77 <listitem><para>OS disk images containing a GPT partition table envelope, with partitions marked
78 according to the <ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable Partitions
79 Specification</ulink>.</para></listitem>
80
81 <listitem><para>OS disk images containing just a plain file-system without an enveloping partition
82 table. (This file system is assumed to be the root file system of the OS.)</para></listitem>
83
84 <listitem><para>OS disk images containing a GPT or MBR partition table, with a single
85 partition only. (This partition is assumed to contain the root file system of the OS.)</para></listitem>
86 </orderedlist>
87
88 <para>OS images may use any kind of Linux-supported file systems. In addition they may make use of LUKS
89 disk encryption, and contain Verity integrity information. Note that qualifying OS images may be booted
90 with <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
91 <option>--image=</option> switch, and be used as root file system for system service using the
92 <varname>RootImage=</varname> unit file setting, see
93 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
94
95 <para>Note that the partition table shown when invoked without command switch (as listed below) does not
96 necessarily show all partitions included in the image, but just the partitions that are understood and
97 considered part of an OS disk image. Specifically, partitions of unknown types are ignored, as well as
98 duplicate partitions (i.e. more than one per partition type), as are root and <filename>/usr/</filename>
99 partitions of architectures not compatible with the local system. In other words: this tool will display
100 what it operates with when mounting the image. To display the complete list of partitions use a tool such
101 as <citerefentry
102 project='man-pages'><refentrytitle>fdisk</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
103
104 <para>The <command>systemd-dissect</command> command may be invoked as <command>mount.ddi</command> in
105 which case it implements the <citerefentry
106 project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> "external
107 helper" interface. This ensures disk images compatible with <command>systemd-dissect</command> can be
108 mounted directly by <command>mount</command> and <citerefentry
109 project='man-pages'><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>. For
110 details see below.</para>
111 </refsect1>
112
113 <refsect1>
114 <title>Commands</title>
115
116 <para>If neither of the command switches listed below are passed the specified disk image is opened and
117 general information about the image and the contained partitions and their use is shown.</para>
118
119 <variablelist>
120 <varlistentry>
121 <term><option>--mount</option></term>
122 <term><option>-m</option></term>
123
124 <listitem><para>Mount the specified OS image to the specified directory. This will dissect the image,
125 determine the OS root file system — as well as possibly other partitions — and mount them to the
126 specified directory. If the OS image contains multiple partitions marked with the <ulink
127 url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable Partitions Specification</ulink>
128 multiple nested mounts are established. This command expects two arguments: a path to an image file
129 and a path to a directory where to mount the image.</para>
130
131 <para>To unmount an OS image mounted like this use the <option>--umount</option> operation.</para>
132
133 <para>When the OS image contains LUKS encrypted or Verity integrity protected file systems
134 appropriate volumes are automatically set up and marked for automatic disassembly when the image is
135 unmounted.</para>
136
137 <para>The OS image may either be specified as path to an OS image stored in a regular file or may
138 refer to block device node (in the latter case the block device must be the "whole" device, i.e. not
139 a partition device). (The other supported commands described here support this, too.)</para>
140
141 <para>All mounted file systems are checked with the appropriate <citerefentry
142 project='man-pages'><refentrytitle>fsck</refentrytitle><manvolnum>8</manvolnum></citerefentry>
143 implementation in automatic fixing mode, unless explicitly turned off (<option>--fsck=no</option>) or
144 read-only operation is requested (<option>--read-only</option>).</para>
145
146 <para>Note that this functionality is also available in <citerefentry
147 project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> via a
148 command such as <command>mount -t ddi myimage.raw targetdir/</command>, as well as in <citerefentry
149 project='man-pages'><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>. For
150 details, see below.</para></listitem>
151 </varlistentry>
152
153 <varlistentry>
154 <term><option>-M</option></term>
155
156 <listitem><para>This is a shortcut for <option>--mount --mkdir</option>.</para></listitem>
157 </varlistentry>
158
159 <varlistentry>
160 <term><option>--umount</option></term>
161 <term><option>-u</option></term>
162
163 <listitem><para>Unmount an OS image from the specified directory. This command expects one argument:
164 a directory where an OS image was mounted.</para>
165
166 <para>All mounted partitions will be recursively unmounted, and the underlying loop device will be
167 removed, along with all it's partition sub-devices.</para></listitem>
168 </varlistentry>
169
170 <varlistentry>
171 <term><option>-U</option></term>
172
173 <listitem><para>This is a shortcut for <option>--umount --rmdir</option>.</para></listitem>
174 </varlistentry>
175
176 <varlistentry>
177 <term><option>--list</option></term>
178 <term><option>-l</option></term>
179
180 <listitem><para>Prints the paths of all the files and directories in the specified OS image to
181 standard output.</para></listitem>
182 </varlistentry>
183
184 <varlistentry>
185 <term><option>--mtree</option></term>
186 <term><option>-l</option></term>
187
188 <listitem><para>Generates a BSD <citerefentry
189 project='die-net'><refentrytitle>mtree</refentrytitle><manvolnum>8</manvolnum></citerefentry>
190 compatible file manifest of the specified disk image. This is useful for comparing disk image
191 contents in detail, including inode information and other metadata. While the generated manifest will
192 contain detailed inode information, it currently excludes extended attributes, file system
193 capabilities, MAC labels, <citerefentry
194 project='man-pages'><refentrytitle>chattr</refentrytitle><manvolnum>1</manvolnum></citerefentry> file
195 flags, btrfs subvolume information, and various other file metadata. File content information is
196 shown via a SHA256 digest. Additional fields might be added in future. Note that inode information
197 such as link counts, inode numbers and timestamps is excluded from the output on purpose, as it
198 typically complicates reproducibility.</para></listitem>
199 </varlistentry>
200
201 <varlistentry>
202 <term><option>--with</option></term>
203
204 <listitem><para>Runs the specified command with the specified OS image mounted. This will mount the
205 image to a temporary directory, switch the current working directory to it, and invoke the specified
206 command line as child process. Once the process ends it will unmount the image again, and remove the
207 temporary directory. If no command is specified a shell is invoked. The image is mounted writable,
208 use <option>--read-only</option> to switch to read-only operation. The invoked process will have the
209 <varname>$SYSTEMD_DISSECT_ROOT</varname> environment variable set, containing the absolute path name
210 of the temporary mount point, i.e. the same directory that is set as the current working
211 directory.</para></listitem>
212 </varlistentry>
213
214 <varlistentry>
215 <term><option>--copy-from</option></term>
216 <term><option>-x</option></term>
217
218 <listitem><para>Copies a file or directory from the specified OS image into the specified location on
219 the host file system. Expects three arguments: a path to an image file, a source path (relative to
220 the image's root directory) and a destination path (relative to the current working directory, or an
221 absolute path, both outside of the image). If the destination path is omitted or specified as dash
222 (<literal>-</literal>), the specified file is written to standard output. If the source path in the
223 image file system refers to a regular file it is copied to the destination path. In this case access
224 mode, extended attributes and timestamps are copied as well, but file ownership is not. If the source
225 path in the image refers to a directory, it is copied to the destination path, recursively with all
226 containing files and directories. In this case the file ownership is copied too.</para></listitem>
227 </varlistentry>
228
229 <varlistentry>
230 <term><option>--copy-to</option></term>
231 <term><option>-a</option></term>
232
233 <listitem><para>Copies a file or directory from the specified location in the host file system into
234 the specified OS image. Expects three arguments: a path to an image file, a source path (relative to
235 the current working directory, or an absolute path, both outside of the image) and a destination path
236 (relative to the image's root directory). If the source path is omitted or specified as dash
237 (<literal>-</literal>), the data to write is read from standard input. If the source path in the host
238 file system refers to a regular file, it is copied to the destination path. In this case access mode,
239 extended attributes and timestamps are copied as well, but file ownership is not. If the source path
240 in the host file system refers to a directory it is copied to the destination path, recursively with
241 all containing files and directories. In this case the file ownership is copied
242 too.</para>
243
244 <para>As with <option>--mount</option> file system checks are implicitly run before the copy
245 operation begins.</para></listitem>
246 </varlistentry>
247
248 <varlistentry>
249 <term><option>--discover</option></term>
250
251 <listitem><para>Show a list of DDIs in well-known directories. This will show machine, portable
252 service and system extension disk images in the usual directories
253 <filename>/usr/lib/machines/</filename>, <filename>/usr/lib/portables/</filename>,
254 <filename>/usr/lib/extensions/</filename>, <filename>/var/lib/machines/</filename>,
255 <filename>/var/lib/portables/</filename>, <filename>/var/lib/extensions/</filename> and so
256 on.</para></listitem>
257 </varlistentry>
258
259 <xi:include href="standard-options.xml" xpointer="help" />
260 <xi:include href="standard-options.xml" xpointer="version" />
261 </variablelist>
262
263 </refsect1>
264
265 <refsect1>
266 <title>Options</title>
267
268 <para>The following options are understood:</para>
269
270 <variablelist>
271 <varlistentry>
272 <term><option>--read-only</option></term>
273 <term><option>-r</option></term>
274
275 <listitem><para>Operate in read-only mode. By default <option>--mount</option> will establish
276 writable mount points. If this option is specified they are established in read-only mode
277 instead.</para></listitem>
278 </varlistentry>
279
280 <varlistentry>
281 <term><option>--fsck=no</option></term>
282
283 <listitem><para>Turn off automatic file system checking. By default when an image is accessed for
284 writing (by <option>--mount</option> or <option>--copy-to</option>) the file systems contained in the
285 OS image are automatically checked using the appropriate <citerefentry
286 project='man-pages'><refentrytitle>fsck</refentrytitle><manvolnum>8</manvolnum></citerefentry>
287 command, in automatic fixing mode. This behavior may be switched off using
288 <option>--fsck=no</option>.</para></listitem>
289 </varlistentry>
290
291 <varlistentry>
292 <term><option>--growfs=no</option></term>
293
294 <listitem><para>Turn off automatic growing of accessed file systems to their partition size, if
295 marked for that in the GPT partition table. By default when an image is accessed for writing (by
296 <option>--mount</option> or <option>--copy-to</option>) the file systems contained in the OS image
297 are automatically grown to their partition sizes, if bit 59 in the GPT partition flags is set for
298 partition types that are defined by the <ulink
299 url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable Partitions Specification</ulink>. This
300 behavior may be switched off using <option>--growfs=no</option>. File systems are grown automatically
301 on access if all of the following conditions are met:</para>
302 <orderedlist>
303 <listitem><para>The file system is mounted writable</para></listitem>
304 <listitem><para>The file system currently is smaller than the partition it is contained in (and thus can be grown)</para></listitem>
305 <listitem><para>The image contains a GPT partition table</para></listitem>
306 <listitem><para>The file system is stored on a partition defined by the Discoverable Partitions Specification</para></listitem>
307 <listitem><para>Bit 59 of the GPT partition flags for this partition is set, as per specification</para></listitem>
308 <listitem><para>The <option>--growfs=no</option> option is not passed.</para></listitem>
309 </orderedlist>
310 </listitem>
311 </varlistentry>
312
313 <varlistentry>
314 <term><option>--mkdir</option></term>
315
316 <listitem><para>If combined with <option>--mount</option> the directory to mount the OS image to is
317 created if it is missing. Note that the directory is not automatically removed when the disk image is
318 unmounted again.</para></listitem>
319 </varlistentry>
320
321 <varlistentry>
322 <term><option>--rmdir</option></term>
323
324 <listitem><para>If combined with <option>--umount</option> the specified directory where the OS image
325 is mounted is removed after unmounting the OS image.</para></listitem>
326 </varlistentry>
327
328 <varlistentry>
329 <term><option>--discard=</option></term>
330
331 <listitem><para>Takes one of <literal>disabled</literal>, <literal>loop</literal>,
332 <literal>all</literal>, <literal>crypto</literal>. If <literal>disabled</literal> the image is
333 accessed with empty block discarding turned off. If <literal>loop</literal> discarding is enabled if
334 operating on a regular file. If <literal>crypt</literal> discarding is enabled even on encrypted file
335 systems. If <literal>all</literal> discarding is unconditionally enabled.</para></listitem>
336 </varlistentry>
337
338 <varlistentry>
339 <term><option>--in-memory</option></term>
340
341 <listitem><para>If specified an in-memory copy of the specified disk image is used. This may be used
342 to operate with write-access on a (possibly read-only) image, without actually modifying the original
343 file. This may also be used in order to operate on a disk image without keeping the originating file
344 system busy, in order to allow it to be unmounted.</para></listitem>
345 </varlistentry>
346
347 <varlistentry>
348 <term><option>--root-hash=</option></term>
349 <term><option>--root-hash-sig=</option></term>
350 <term><option>--verity-data=</option></term>
351
352 <listitem><para>Configure various aspects of Verity data integrity for the OS image. Option
353 <option>--root-hash=</option> specifies a hex-encoded top-level Verity hash to use for setting up the
354 Verity integrity protection. Option <option>--root-hash-sig=</option> specifies the path to a file
355 containing a PKCS#7 signature for the hash. This signature is passed to the kernel during activation,
356 which will match it against signature keys available in the kernel keyring. Option
357 <option>--verity-data=</option> specifies a path to a file with the Verity data to use for the OS
358 image, in case it is stored in a detached file. It is recommended to embed the Verity data directly
359 in the image, using the Verity mechanisms in the <ulink
360 url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable Partitions Specification</ulink>.
361 </para></listitem>
362 </varlistentry>
363
364 <xi:include href="standard-options.xml" xpointer="no-pager" />
365 <xi:include href="standard-options.xml" xpointer="no-legend" />
366 <xi:include href="standard-options.xml" xpointer="json" />
367 </variablelist>
368 </refsect1>
369
370 <refsect1>
371 <title>Exit status</title>
372
373 <para>On success, 0 is returned, a non-zero failure code otherwise. If the <option>--with</option>
374 command is used the exit status of the invoked command is propagated.</para>
375 </refsect1>
376
377 <refsect1>
378 <title>Invocation as <command>/sbin/mount.ddi</command></title>
379
380 <para>The <command>systemd-dissect</command> executable may be symlinked to
381 <filename>/sbin/mount.ddi</filename>. If invoked through that it implements <citerefentry
382 project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>'s
383 "external helper" interface for the (pseudo) file system type <literal>ddi</literal>. This means
384 conformant disk images may be mounted directly via</para>
385
386 <programlisting># mount -t ddi myimage.raw targetdir/</programlisting>
387
388 <para>in a fashion mostly equivalent to:</para>
389
390 <programlisting># systemd-dissect --mount myimage.raw targetdir/</programlisting>
391
392 <para>Note that since a single DDI may contain multiple file systems it should later be unmounted with
393 <command>umount -R targetdir/</command>, for recursive operation.</para>
394
395 <para>This functionality is particularly useful to mount DDIs automatically at boot via simple
396 <filename>/etc/fstab</filename> entries. For example:</para>
397
398 <programlisting>/path/to/myimage.raw /images/myimage/ ddi defaults 0 0</programlisting>
399
400 <para>When invoked this way the mount options <literal>ro</literal>, <literal>rw</literal>,
401 <literal>discard</literal>, <literal>nodiscard</literal> map to the corresponding options listed above
402 (i.e. <option>--read-only</option>, <option>--discard=all</option>,
403 <option>--discard=disabled</option>). Mount options are <emphasis>not</emphasis> generically passed on to
404 the file systems inside the images.</para>
405 </refsect1>
406
407 <refsect1>
408 <title>Examples</title>
409
410 <example>
411 <title>Generate a tarball from an OS disk image</title>
412
413 <programlisting># systemd-dissect --with foo.raw tar cz . >foo.tar.gz</programlisting>
414 </example>
415 </refsect1>
416
417 <refsect1>
418 <title>See Also</title>
419 <para>
420 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
421 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
422 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
423 <ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable Partitions Specification</ulink>,
424 <citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
425 <citerefentry project='man-pages'><refentrytitle>umount</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
426 <citerefentry project='man-pages'><refentrytitle>fdisk</refentrytitle><manvolnum>8</manvolnum></citerefentry>
427 </para>
428 </refsect1>
429
430 </refentry>