summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2021-03-02 13:58:28 -0500
committerAndrew Cady <d@cryptonomic.net>2021-03-02 14:02:04 -0500
commitc259d4d9552b816d770e90fd4b29184eb0cd0fba (patch)
treee250a838eb1a740f0a0813e6383b5f16ab28c403
parent1ddae2640423f6b5e609829454ed7906e56863d3 (diff)
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.
-rwxr-xr-xsrc/partvi33
1 files 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()
174 printf '%s\n' "${1:0:8}-${1:8:4}-${1:12:4}-${1:16:4}-${1:20:12}" 174 printf '%s\n' "${1:0:8}-${1:8:4}-${1:12:4}-${1:16:4}-${1:20:12}"
175} 175}
176 176
177get_partition_size()
178{
179 case "$type" in
180 dm-verity-hashes|dm-verity-data)
181 stat -L -c '%s' "$builddir"/"${f%.conf}"
182 ;;
183 *)
184 require_var allocation
185 case "$allocation" in
186 *K) echo $(( ${allocation%?} * 1024 )) ;;
187 *M) echo $(( ${allocation%?} * 1024 * 1024 )) ;;
188 *G) echo $(( ${allocation%?} * 1024 * 1024 * 1024 )) ;;
189 *) return 1 ;;
190 esac
191 ;;
192 esac
193}
194
177create_ptable_conf() 195create_ptable_conf()
178{ 196{
179 unset partuuid 197 unset partuuid
180 inquire_var partuuid 198 inquire_var partuuid
181 part=$builddir/${f%.conf} 199 devsz=$(get_partition_size) || return
182 devsz=$(stat -L -c '%s' "$part") || return 200
183 [ "$start" -a "$devsz" ] || return 201 [ "$start" -a "$devsz" ] || return
184 202
185 [ "$((devsz % 512))" -eq 0 ] 203 [ "$((devsz % 512))" -eq 0 ]
@@ -275,8 +293,9 @@ cleanup()
275 fi 293 fi
276} 294}
277 295
278copy_data_to_mounted_target_filesystems() 296mount_part()
279{ 297{
298 local source_dev="$1"
280 case "$type" in 299 case "$type" in
281 efi-system-partition|boot|samizdat-keys) ;; 300 efi-system-partition|boot|samizdat-keys) ;;
282 dm-verity-hashes|partition-table|bios-grub) return ;; 301 dm-verity-hashes|partition-table|bios-grub) return ;;
@@ -284,12 +303,15 @@ copy_data_to_mounted_target_filesystems()
284 esac 303 esac
285 304
286 img=${f%.conf} 305 img=${f%.conf}
287 dev=/dev/mapper/${whole#/dev/}p${img#part}
288 mnt=${f%.conf}.mnt 306 mnt=${f%.conf}.mnt
289 307
290 mkdir -p "$mnt" 308 mkdir -p "$mnt"
291 loudly $sudo mount "$dev" "$mnt" 309 loudly $sudo mount "$source_dev" "$mnt"
310}
292 311
312copy_data_to_mounted_target_filesystems()
313{
314 mount_part "/dev/mapper/${whole#/dev/}p${img#part}"
293 case "$type" in 315 case "$type" in
294 boot) 316 boot)
295 BOOT_DIR=$mnt 317 BOOT_DIR=$mnt
@@ -350,7 +372,6 @@ fi
350 372
351 373
352 374
353
354if whole=$(losetup -j "$target" -O NAME --noheadings) 375if whole=$(losetup -j "$target" -O NAME --noheadings)
355then 376then
356 cleanup 377 cleanup