diff --git a/man/repart.d.xml b/man/repart.d.xml index 4993608670..f2c155e200 100644 --- a/man/repart.d.xml +++ b/man/repart.d.xml @@ -217,6 +217,16 @@ automatically used. + + UUID= + + The UUID to assign to the partition if none is assigned yet. Note that this + setting is not used for matching. It is also not used when a UUID is already set for an existing + partition. It is thus only used when a partition is newly created or when an existing one had a + all-zero UUID set. If not specified a UUID derived from the partition type is automatically + used. + + Priority= diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index 4b1115b6e8..4e1cb3835c 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -295,35 +295,6 @@ int config_parse_capability( return 0; } -int config_parse_id128( - const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - sd_id128_t t, *result = data; - int r; - - assert(filename); - assert(lvalue); - assert(rvalue); - - r = sd_id128_from_string(rvalue, &t); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue); - return 0; - } - - *result = t; - return 0; -} - int config_parse_pivot_root( const char *unit, const char *filename, diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h index 6f2c1141e6..24f98fd7ef 100644 --- a/src/nspawn/nspawn-settings.h +++ b/src/nspawn/nspawn-settings.h @@ -234,7 +234,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Settings*, settings_free); const struct ConfigPerfItem* nspawn_gperf_lookup(const char *key, GPERF_LEN_TYPE length); CONFIG_PARSER_PROTOTYPE(config_parse_capability); -CONFIG_PARSER_PROTOTYPE(config_parse_id128); CONFIG_PARSER_PROTOTYPE(config_parse_expose_port); CONFIG_PARSER_PROTOTYPE(config_parse_volatile_mode); CONFIG_PARSER_PROTOTYPE(config_parse_pivot_root); diff --git a/src/partition/repart.c b/src/partition/repart.c index 46e82eaf90..16cb5e45c4 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -963,6 +963,7 @@ static int partition_read_definition(Partition *p, const char *path) { ConfigTableItem table[] = { { "Partition", "Type", config_parse_type, 0, &p->type_uuid }, { "Partition", "Label", config_parse_label, 0, &p->new_label }, + { "Partition", "UUID", config_parse_id128, 0, &p->new_uuid }, { "Partition", "Priority", config_parse_int32, 0, &p->priority }, { "Partition", "Weight", config_parse_weight, 0, &p->weight }, { "Partition", "PaddingWeight", config_parse_weight, 0, &p->padding_weight }, @@ -2232,13 +2233,12 @@ static int context_acquire_partition_uuids_and_labels(Context *context) { assert(context); LIST_FOREACH(partitions, p, context->partitions) { - assert(sd_id128_is_null(p->new_uuid)); - /* Never touch foreign partitions */ if (PARTITION_IS_FOREIGN(p)) { p->new_uuid = p->current_uuid; if (p->current_label) { + free(p->new_label); p->new_label = strdup(p->current_label); if (!p->new_label) return log_oom(); @@ -2249,20 +2249,21 @@ static int context_acquire_partition_uuids_and_labels(Context *context) { if (!sd_id128_is_null(p->current_uuid)) p->new_uuid = p->current_uuid; /* Never change initialized UUIDs */ - else { + else if (sd_id128_is_null(p->new_uuid)) { + /* Not explicitly set by user! */ r = partition_acquire_uuid(context, p, &p->new_uuid); if (r < 0) return r; } - if (p->new_label) /* Explicitly set by user? */ - continue; - if (!isempty(p->current_label)) { + free(p->new_label); p->new_label = strdup(p->current_label); /* never change initialized labels */ if (!p->new_label) return log_oom(); - } else { + } else if (!p->new_label) { + /* Not explicitly set by user! */ + r = partition_acquire_label(context, p, &p->new_label); if (r < 0) return r; diff --git a/src/partition/test-repart.sh b/src/partition/test-repart.sh index 58fcc797c4..e1ff357929 100755 --- a/src/partition/test-repart.sh +++ b/src/partition/test-repart.sh @@ -68,8 +68,13 @@ EOF cat >$D/definitions/extra.conf <> $D/definitions/home.conf +echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >> $D/definitions/home.conf + $repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2 @@ -85,7 +90,7 @@ $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64" $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2" $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap" -$D/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic" +$D/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label" EOF $repart $D/zzz --size=2G --dry-run=no --seed=$SEED --definitions=$D/definitions @@ -103,5 +108,5 @@ $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64" $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2" $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap" -$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic" +$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label" EOF diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 23cb3b65b6..e685ecbff7 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -23,6 +23,7 @@ #include "path-util.h" #include "process-util.h" #include "rlimit-util.h" +#include "sd-id128.h" #include "signal-util.h" #include "socket-util.h" #include "string-util.h" @@ -648,6 +649,35 @@ int config_parse_bool(const char* unit, return 0; } +int config_parse_id128( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + sd_id128_t t, *result = data; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + + r = sd_id128_from_string(rvalue, &t); + if (r < 0) + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue); + else if (sd_id128_is_null(t)) + log_syntax(unit, LOG_ERR, filename, line, 0, "128bit ID/UUID is all 0, ignoring: %s", rvalue); + + *result = t; + return 0; +} + int config_parse_tristate( const char* unit, const char *filename, diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 59e74590ca..82c692af10 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -122,6 +122,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_iec_size); CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_bool); +CONFIG_PARSER_PROTOTYPE(config_parse_id128); CONFIG_PARSER_PROTOTYPE(config_parse_tristate); CONFIG_PARSER_PROTOTYPE(config_parse_string); CONFIG_PARSER_PROTOTYPE(config_parse_path);