X Tutup
Skip to content

Commit ff0771b

Browse files
poetteringyuwata
authored andcommitted
repart: make No-Auto GPT partition flag configurable too
This is useful for provisioning initially empty secondary A/B root file systems. We don't want those to ever be considered for automatic mounting, for example in "systemd-nspawn --image=", hence we should create them with the No-Auto flag turned on. Once a file system image is dropped into the partition the flag may be turned off by the updater tool, so that it is considered from then on. Thew new option for this is called NoAuto. I dislike negated options like this, but this is taken from the naming in the spec, which in turn inherited the name from the same flag for Microsoft Data Partitions. To minimize confusion, let's stick to the name hence.
1 parent 1a27c32 commit ff0771b

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

man/repart.d.xml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -571,33 +571,34 @@
571571
<varlistentry>
572572
<term><varname>Flags=</varname></term>
573573

574-
<listitem><para>Configures the 64bit GPT partition flags to set for the partition when creating
574+
<listitem><para>Configures the 64bit GPT partition flags field to set for the partition when creating
575575
it. This option has no effect if the partition already exists. If not specified the flags values is
576-
set to all zeroes, except if the partition type (as configured with <varname>Type=</varname> above)
577-
refers to a Verity partition, in which case bit 60 is set (i.e. the read-only bit). This bit may also
578-
be configured separately via <varname>ReadOnly=</varname>, see below. Specify the flags value in
579-
hexadecimal (by prefixing it with <literal>0x</literal>), binary (prefix <literal>0b</literal>) or
580-
decimal (no prefix).</para></listitem>
576+
set to all zeroes, except for the three bits that can also be configured via
577+
<varname>NoAuto=</varname>, <varname>ReadOnly=</varname> and <varname>GrowFileSystem=</varname>; see
578+
below for details on the defaults for these three flags. Specify the flags value in hexadecimal (by
579+
prefixing it with <literal>0x</literal>), binary (prefix <literal>0b</literal>) or decimal (no
580+
prefix).</para></listitem>
581581
</varlistentry>
582582

583583
<varlistentry>
584+
<term><varname>NoAuto=</varname></term>
584585
<term><varname>ReadOnly=</varname></term>
585586
<term><varname>GrowFileSystem=</varname></term>
586587

587-
<listitem><para>Configures the Read-Only and Grow-File-System partition flags (bit 60 and 59) of the
588-
partition table entry, as defined by the <ulink
588+
<listitem><para>Configures the No-Auto, Read-Only and Grow-File-System partition flags (bit 63, 60
589+
and 59) of the partition table entry, as defined by the <ulink
589590
url="https://systemd.io/DISCOVERABLE_PARTITIONS">Discoverable Partitions Specification</ulink>. Only
590-
available for partition types supported by the specification. This option is a friendly way to set bit
591-
60 and 59 of the partition flags value without setting any of the other bits, and may be set via
592-
<varname>Flags=</varname> too, see above.</para>
591+
available for partition types supported by the specification. This option is a friendly way to set
592+
bits 63, 60 and 59 of the partition flags value without setting any of the other bits, and may be set
593+
via <varname>Flags=</varname> too, see above.</para>
593594

594-
<para>If <varname>Flags=</varname> is used in conjunction with one or both of
595-
<varname>ReadOnly=</varname>/<varname>GrowFileSystem=</varname> the latter control the value of the
596-
relevant flags, i.e. the high-level settings
597-
<varname>ReadOnly=</varname>/<varname>GrowFileSystem=</varname> override the low-level setting
598-
<varname>Flags=</varname>.</para>
595+
<para>If <varname>Flags=</varname> is used in conjunction with one or more of
596+
<varname>NoAuto=</varname>/<varname>ReadOnly=</varname>/<varname>GrowFileSystem=</varname> the latter
597+
control the value of the relevant flags, i.e. the high-level settings
598+
<varname>NoAuto=</varname>/<varname>ReadOnly=</varname>/<varname>GrowFileSystem=</varname> override
599+
the relevant bits of the low-level setting <varname>Flags=</varname>.</para>
599600

600-
<para>Note that the two flags affect only automatic partition mounting, as implemented by
601+
<para>Note that the three flags affect only automatic partition mounting, as implemented by
601602
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
602603
or the <option>--image=</option> option of various commands (such as
603604
<citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>). It
@@ -611,10 +612,10 @@
611612
precedence in most tools reading these flags, and since growing the file system involves writing to
612613
the partition it is consequently ignored.</para>
613614

614-
<para><varname>ReadOnly=</varname> defaults to on for Verity partition
615-
types. <varname>GrowFileSystem=</varname> defaults to on for all partition types that support it,
616-
except if the partition is marked read-only (and thus effectively, defaults to off for Verity
617-
partitions).</para></listitem>
615+
<para><varname>NoAuto=</varname> defaults to off. <varname>ReadOnly=</varname> defaults to on for
616+
Verity partition types, and off for all others. <varname>GrowFileSystem=</varname> defaults to on for
617+
all partition types that support it, except if the partition is marked read-only (and thus
618+
effectively, defaults to off for Verity partitions).</para></listitem>
618619
</varlistentry>
619620
</variablelist>
620621
</refsect1>

src/partition/repart.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct Partition {
169169
EncryptMode encrypt;
170170

171171
uint64_t gpt_flags;
172+
int no_auto;
172173
int read_only;
173174
int growfs;
174175

@@ -243,6 +244,7 @@ static Partition *partition_new(void) {
243244
.offset = UINT64_MAX,
244245
.copy_blocks_fd = -1,
245246
.copy_blocks_size = UINT64_MAX,
247+
.no_auto = -1,
246248
.read_only = -1,
247249
.growfs = -1,
248250
};
@@ -1312,6 +1314,7 @@ static int partition_read_definition(Partition *p, const char *path) {
13121314
{ "Partition", "Encrypt", config_parse_encrypt, 0, &p->encrypt },
13131315
{ "Partition", "Flags", config_parse_gpt_flags, 0, &p->gpt_flags },
13141316
{ "Partition", "ReadOnly", config_parse_tristate, 0, &p->read_only },
1317+
{ "Partition", "NoAuto", config_parse_tristate, 0, &p->no_auto },
13151318
{ "Partition", "GrowFileSystem", config_parse_tristate, 0, &p->growfs },
13161319
{}
13171320
};
@@ -3269,6 +3272,17 @@ static uint64_t partition_merge_flags(Partition *p) {
32693272

32703273
f = p->gpt_flags;
32713274

3275+
if (p->no_auto >= 0) {
3276+
if (gpt_partition_type_knows_no_auto(p->type_uuid))
3277+
SET_FLAG(f, GPT_FLAG_NO_AUTO, p->no_auto);
3278+
else {
3279+
char buffer[ID128_UUID_STRING_MAX];
3280+
log_warning("Configured NoAuto=%s for partition type '%s' that doesn't support it, ignoring.",
3281+
yes_no(p->no_auto),
3282+
gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
3283+
}
3284+
}
3285+
32723286
if (p->read_only >= 0) {
32733287
if (gpt_partition_type_knows_read_only(p->type_uuid))
32743288
SET_FLAG(f, GPT_FLAG_READ_ONLY, p->read_only);
@@ -3409,7 +3423,7 @@ static int context_mangle_partitions(Context *context) {
34093423
if (r < 0)
34103424
return log_error_errno(r, "Failed to set partition label: %m");
34113425

3412-
/* Merge the read only + growfs setting with the literal flags, and set them for the partition */
3426+
/* Merge the no auto + read only + growfs setting with the literal flags, and set them for the partition */
34133427
r = set_gpt_flags(q, partition_merge_flags(p));
34143428
if (r < 0)
34153429
return log_error_errno(r, "Failed to set GPT partition flags: %m");

src/shared/gpt.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,17 @@ bool gpt_partition_type_knows_growfs(sd_id128_t id) {
174174
GPT_TMP,
175175
GPT_XBOOTLDR);
176176
}
177+
178+
bool gpt_partition_type_knows_no_auto(sd_id128_t id) {
179+
return gpt_partition_type_is_root(id) ||
180+
gpt_partition_type_is_root_verity(id) ||
181+
gpt_partition_type_is_usr(id) ||
182+
gpt_partition_type_is_usr_verity(id) ||
183+
sd_id128_in_set(id,
184+
GPT_HOME,
185+
GPT_SRV,
186+
GPT_VAR,
187+
GPT_TMP,
188+
GPT_XBOOTLDR,
189+
GPT_SWAP);
190+
}

src/shared/gpt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ bool gpt_partition_type_is_usr_verity(sd_id128_t id);
140140

141141
bool gpt_partition_type_knows_read_only(sd_id128_t id);
142142
bool gpt_partition_type_knows_growfs(sd_id128_t id);
143+
bool gpt_partition_type_knows_no_auto(sd_id128_t id);

0 commit comments

Comments
 (0)
X Tutup