From c259d4d9552b816d770e90fd4b29184eb0cd0fba Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 2 Mar 2021 13:58:28 -0500 Subject: partvi: do not rely on part image file to get size When partvi writes directly to a boot medium, it shouldn't copy part files, because these involve copying the unused parts of the filesystems. Instead, it should create a new filesystem on the target and copy files into it. This change moves in that direction. --- src/partvi | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/partvi b/src/partvi index 2a32851..b718dba 100755 --- a/src/partvi +++ b/src/partvi @@ -174,12 +174,30 @@ format_guid() printf '%s\n' "${1:0:8}-${1:8:4}-${1:12:4}-${1:16:4}-${1:20:12}" } +get_partition_size() +{ + case "$type" in + dm-verity-hashes|dm-verity-data) + stat -L -c '%s' "$builddir"/"${f%.conf}" + ;; + *) + require_var allocation + case "$allocation" in + *K) echo $(( ${allocation%?} * 1024 )) ;; + *M) echo $(( ${allocation%?} * 1024 * 1024 )) ;; + *G) echo $(( ${allocation%?} * 1024 * 1024 * 1024 )) ;; + *) return 1 ;; + esac + ;; + esac +} + create_ptable_conf() { unset partuuid inquire_var partuuid - part=$builddir/${f%.conf} - devsz=$(stat -L -c '%s' "$part") || return + devsz=$(get_partition_size) || return + [ "$start" -a "$devsz" ] || return [ "$((devsz % 512))" -eq 0 ] @@ -275,8 +293,9 @@ cleanup() fi } -copy_data_to_mounted_target_filesystems() +mount_part() { + local source_dev="$1" case "$type" in efi-system-partition|boot|samizdat-keys) ;; dm-verity-hashes|partition-table|bios-grub) return ;; @@ -284,12 +303,15 @@ copy_data_to_mounted_target_filesystems() esac img=${f%.conf} - dev=/dev/mapper/${whole#/dev/}p${img#part} mnt=${f%.conf}.mnt mkdir -p "$mnt" - loudly $sudo mount "$dev" "$mnt" + loudly $sudo mount "$source_dev" "$mnt" +} +copy_data_to_mounted_target_filesystems() +{ + mount_part "/dev/mapper/${whole#/dev/}p${img#part}" case "$type" in boot) BOOT_DIR=$mnt @@ -350,7 +372,6 @@ fi - if whole=$(losetup -j "$target" -O NAME --noheadings) then cleanup -- cgit v1.2.3