diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-04 23:49:17 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-23 10:02:56 +0100 |
commit | 31ea1bfec1e56fd2697839f0471609528b809f89 (patch) | |
tree | 769dd0095cc19d674615a8c51142bc3d1bfd4c76 | |
parent | 716bc20034bb54a0c1b1dd5125929d900026670b (diff) | |
download | systemd-31ea1bfec1e56fd2697839f0471609528b809f89.tar.gz |
homework: correct initial minimal fs size calculations by LUKS2/GPT overhead
So far we assumed we ignore the LUKS2/GPT header overhead when
determining what the lower bound for images sizes is. Let's correct
this.
-rw-r--r-- | src/home/homework-luks.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 0beee8ecfd..7bd4ff6c8d 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -63,6 +63,10 @@ _x > UINT64_MAX - 4095U ? UINT64_MAX : (_x + 4095U) & ~UINT64_C(4095); \ }) +/* How much larger will the image on disk be than the fs inside it, i.e. the space we pay for the GPT and + * LUKS2 envelope. (As measured on cryptsetup 2.4.1) */ +#define GPT_LUKS2_OVERHEAD UINT64_C(18874368) + static int resize_image_loop(UserRecord *h, HomeSetup *setup, uint64_t old_image_size, uint64_t new_image_size, uint64_t *ret_image_size); int run_mark_dirty(int fd, bool b) { @@ -1782,6 +1786,8 @@ static int make_partition_table( assert(first_lba <= UINT64_MAX/512); start = DISK_SIZE_ROUND_UP(first_lba * 512); /* Round up to multiple of 4K */ + log_debug("Starting partition at offset %" PRIu64, start); + if (start == UINT64_MAX) return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Overflow while rounding up start LBA."); @@ -1950,6 +1956,10 @@ static int calculate_initial_image_size(UserRecord *h, int image_fd, const char } lower_boundary = minimal_size_by_fs_name(fstype); + if (lower_boundary != UINT64_MAX) { + assert(GPT_LUKS2_OVERHEAD < UINT64_MAX - lower_boundary); + lower_boundary += GPT_LUKS2_OVERHEAD; + } if (lower_boundary == UINT64_MAX || lower_boundary < USER_DISK_SIZE_MIN) lower_boundary = USER_DISK_SIZE_MIN; @@ -2123,7 +2133,7 @@ int home_create_luks( else host_size = DISK_SIZE_ROUND_DOWN(h->disk_size); - if (!supported_fs_size(fstype, host_size)) + if (!supported_fs_size(fstype, LESS_BY(host_size, GPT_LUKS2_OVERHEAD))) return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Selected file system size too small for %s.", fstype); @@ -2350,6 +2360,8 @@ int home_create_luks( print_size_summary(host_size, encrypted_size, &sfs); + log_debug("GPT + LUKS2 overhead is %" PRIu64 " (expected %" PRIu64 ")", host_size - encrypted_size, GPT_LUKS2_OVERHEAD); + *ret_home = TAKE_PTR(new_home); return 0; } |