Skip to content

Commit 74a54ba

Browse files
committed
dissect: enable growfs by default, but make it configurable
This adds a new --growfs=yes|no switch to systemd-dissect, defaulting to on.
1 parent 81939d9 commit 74a54ba

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

man/systemd-dissect.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@
194194
<option>--fsck=no</option>.</para></listitem>
195195
</varlistentry>
196196

197+
<varlistentry>
198+
<term><option>--growfs=no</option></term>
199+
200+
<listitem><para>Turn off automatic growing of accessed file systems to their partition size, if
201+
marked for that in the GPT partition table. By default when an image is accessed for writing (by
202+
<option>--mount</option> or <option>--copy-to</option>) the file systems contained in the OS image
203+
are automatically grown to their partition sizes, if bit 59 in the GPT partition flags is set for
204+
partition types that are defined by the <ulink
205+
url="https://systemd.io/DISCOVERABLE_PARTITIONS">Discoverable Partitions Specification</ulink>. This
206+
behavior may be switched off using <option>--growfs=no</option>. File systems are grown automatically
207+
on access if all of the following conditions are met:</para>
208+
<orderedlist>
209+
<listitem><para>The file system is mounted writable</para></listitem>
210+
<listitem><para>The file system currently is smaller than the partition it is contained in (and thus can be grown)</para></listitem>
211+
<listitem><para>The image contains a GPT partition table</para></listitem>
212+
<listitem><para>The file system is stored on a partition defined by the Discoverable Partitions Specification</para></listitem>
213+
<listitem><para>Bit 59 of the GPT partition flags for this partition is set, as per specification</para></listitem>
214+
<listitem><para>The <option>--growfs=no</option> option is not passed.</para></listitem>
215+
</orderedlist>
216+
</listitem>
217+
</varlistentry>
218+
197219
<varlistentry>
198220
<term><option>--mkdir</option></term>
199221

src/dissect/dissect.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static DissectImageFlags arg_flags =
4949
DISSECT_IMAGE_DISCARD_ON_LOOP |
5050
DISSECT_IMAGE_RELAX_VAR_CHECK |
5151
DISSECT_IMAGE_FSCK |
52-
DISSECT_IMAGE_USR_NO_ROOT;
52+
DISSECT_IMAGE_USR_NO_ROOT |
53+
DISSECT_IMAGE_GROWFS;
5354
static VeritySettings arg_verity_settings = VERITY_SETTINGS_DEFAULT;
5455
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
5556
static PagerFlags arg_pager_flags = 0;
@@ -75,6 +76,7 @@ static int help(void) {
7576
" --no-legend Do not show the headers and footers\n"
7677
" -r --read-only Mount read-only\n"
7778
" --fsck=BOOL Run fsck before mounting\n"
79+
" --growfs=BOOL Grow file system to partition size, if marked\n"
7880
" --mkdir Make mount directory before mounting, if missing\n"
7981
" --discard=MODE Choose 'discard' mode (disabled, loop, all, crypto)\n"
8082
" --root-hash=HASH Specify root hash for verity\n"
@@ -112,6 +114,7 @@ static int parse_argv(int argc, char *argv[]) {
112114
ARG_NO_LEGEND,
113115
ARG_DISCARD,
114116
ARG_FSCK,
117+
ARG_GROWFS,
115118
ARG_ROOT_HASH,
116119
ARG_ROOT_HASH_SIG,
117120
ARG_VERITY_DATA,
@@ -128,6 +131,7 @@ static int parse_argv(int argc, char *argv[]) {
128131
{ "read-only", no_argument, NULL, 'r' },
129132
{ "discard", required_argument, NULL, ARG_DISCARD },
130133
{ "fsck", required_argument, NULL, ARG_FSCK },
134+
{ "growfs", required_argument, NULL, ARG_GROWFS },
131135
{ "root-hash", required_argument, NULL, ARG_ROOT_HASH },
132136
{ "root-hash-sig", required_argument, NULL, ARG_ROOT_HASH_SIG },
133137
{ "verity-data", required_argument, NULL, ARG_VERITY_DATA },
@@ -264,6 +268,14 @@ static int parse_argv(int argc, char *argv[]) {
264268
SET_FLAG(arg_flags, DISSECT_IMAGE_FSCK, r);
265269
break;
266270

271+
case ARG_GROWFS:
272+
r = parse_boolean(optarg);
273+
if (r < 0)
274+
return log_error_errno(r, "Failed to parse --growfs= parameter: %s", optarg);
275+
276+
SET_FLAG(arg_flags, DISSECT_IMAGE_GROWFS, r);
277+
break;
278+
267279
case ARG_JSON:
268280
r = parse_json_argument(optarg, &arg_json_format_flags);
269281
if (r <= 0)

0 commit comments

Comments
 (0)