summaryrefslogtreecommitdiffstats
path: root/src/partition
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-10-13 13:26:07 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-11-11 13:48:21 +0100
commit8bbbdfd788222698e2de3726cdc27f50adf4aef2 (patch)
treec5e74efa5b3d7d5000da0dd96d4b6cfe1d10895f /src/partition
parentrepart: Use COPY_HOLES more (diff)
downloadsystemd-8bbbdfd788222698e2de3726cdc27f50adf4aef2.tar.xz
systemd-8bbbdfd788222698e2de3726cdc27f50adf4aef2.zip
repart: Calculate filesystem UUID earlier
Diffstat (limited to 'src/partition')
-rw-r--r--src/partition/repart.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c
index e18a82960f..e2b6ab18e9 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -168,6 +168,7 @@ struct Partition {
sd_id128_t current_uuid, new_uuid;
bool new_uuid_is_set;
char *current_label, *new_label;
+ sd_id128_t fs_uuid;
bool dropped;
bool factory_reset;
@@ -344,7 +345,6 @@ static void partition_foreignize(Partition *p) {
/* Reset several parameters set through definition file to make the partition foreign. */
- p->new_label = mfree(p->new_label);
p->definition_path = mfree(p->definition_path);
p->drop_in_files = strv_free(p->drop_in_files);
@@ -356,8 +356,6 @@ static void partition_foreignize(Partition *p) {
p->make_directories = strv_free(p->make_directories);
p->verity_match_key = mfree(p->verity_match_key);
- p->new_uuid = SD_ID128_NULL;
- p->new_uuid_is_set = false;
p->priority = 0;
p->weight = 1000;
p->padding_weight = 0;
@@ -3509,7 +3507,6 @@ static int context_mkfs(Context *context) {
_cleanup_free_ char *encrypted = NULL, *root = NULL;
_cleanup_close_ int encrypted_dev_fd = -1;
const char *fsdev;
- sd_id128_t fs_uuid;
if (p->dropped)
continue;
@@ -3547,12 +3544,6 @@ static int context_mkfs(Context *context) {
log_info("Formatting future partition %" PRIu64 ".", p->partno);
- /* Calculate the UUID for the file system as HMAC-SHA256 of the string "file-system-uuid",
- * keyed off the partition UUID. */
- r = derive_uuid(p->new_uuid, "file-system-uuid", &fs_uuid);
- if (r < 0)
- return r;
-
/* Ideally, we populate filesystems using our own code after creating the filesystem to
* ensure consistent handling of chattrs, xattrs and other similar things. However, when
* using read-only filesystems such as squashfs, we can't populate after creating the
@@ -3562,7 +3553,7 @@ static int context_mkfs(Context *context) {
if (r < 0)
return r;
- r = make_filesystem(fsdev, p->format, strempty(p->new_label), root ?: tmp_root, fs_uuid, arg_discard);
+ r = make_filesystem(fsdev, p->format, strempty(p->new_label), root ?: tmp_root, p->fs_uuid, arg_discard);
if (r < 0) {
encrypted_dev_fd = safe_close(encrypted_dev_fd);
(void) deactivate_luks(cd, encrypted);
@@ -4062,6 +4053,12 @@ static int context_acquire_partition_uuids_and_labels(Context *context) {
p->new_uuid_is_set = true;
}
+ /* Calculate the UUID for the file system as HMAC-SHA256 of the string "file-system-uuid",
+ * keyed off the partition UUID. */
+ r = derive_uuid(p->new_uuid, "file-system-uuid", &p->fs_uuid);
+ if (r < 0)
+ return r;
+
if (!isempty(p->current_label)) {
/* never change initialized labels */
r = free_and_strdup_warn(&p->new_label, p->current_label);
@@ -5951,6 +5948,11 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return r;
+ /* Make sure each partition has a unique UUID and unique label */
+ r = context_acquire_partition_uuids_and_labels(context);
+ if (r < 0)
+ return r;
+
/* Open all files to copy blocks from now, since we want to take their size into consideration */
r = context_open_copy_block_paths(
context,
@@ -6007,11 +6009,6 @@ static int run(int argc, char *argv[]) {
/* Now calculate where each new partition gets placed */
context_place_partitions(context);
- /* Make sure each partition has a unique UUID and unique label */
- r = context_acquire_partition_uuids_and_labels(context);
- if (r < 0)
- return r;
-
(void) context_dump(context, node, /*late=*/ false);
r = context_write_partition_table(context, node, from_scratch);