Debian Codegraph @

dracut/modules.d/55kiwi-dump/kiwi-dump-image.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 type getarg >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/dracut-lib.shscip-shell source . . `/lib/dracut-lib.sh`.
3 type setup_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-lib.shscip-shell source . . `/lib/kiwi-lib.sh`.
4 type run_dialog >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-dialog-lib.shscip-shell source . . `/lib/kiwi-dialog-lib.sh`.
5 type get_block_device_kbsize >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-partitions-lib.shscip-shell source . . `/lib/kiwi-partitions-lib.sh`.
6 type fetch_file >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-net-lib.shscip-shell source . . `/lib/kiwi-net-lib.sh`.
7
8 #======================================
9 # Functions
10 #--------------------------------------
11 function scan_multipath_devicesscip-shell shell shell-project 0.0.0 scan_multipath_devices(). {
12 # """
13 # starts multipath daemon from multipath module
14 # """
15 systemctl start multipathd
16 }
17
18 function find_disk_entryscip-shell shell shell-project 0.0.0 find_disk_entry(). {
19 # """
20 # lookup disk entry by name and echo the
21 # associated entry parameter (size) when found
22 # """
23 local list_items=$1
24 local search=$2
25 local count=0
26 local found=
27 for entry in ${list_items};do
28 if [scip-shell system . . `[`. -n "${found}" ];then
29 echoscip-shell system . . echo. "${entry}"
30 return
31 fi
32 if [scip-shell system . . `[`. $((count % 2)) -eq 0 ];then
33 if [scip-shell system . . `[`. "${entry}" = "${search}" ];then
34 found=1
35 fi
36 fi
37 count=$((count + 1))
38 done
39 }
40
41 function sort_disk_entriesscip-shell shell shell-project 0.0.0 sort_disk_entries(). {
42 # """
43 # sort the disk entry names
44 # """
45 local list_items=$1
46 local count=0
47 local device_index=0
48 local device_array
49 local list_items_sorted
50 for entry in ${list_items};do
51 if [scip-shell system . . `[`. $((count % 2)) -eq 0 ];then
52 device_array[${device_index}]=${entry}
53 device_index=$((device_index + 1))
54 fi
55 count=$((count + 1))
56 done
57 printfscip-shell system . . printf. '%s\0' "${device_array[@]}" | sortscip-shell system . . sort. -z > list_items_sorted.txt
58 readarray -td '' list_items_sorted < list_items_sorted.txt
59 echoscip-shell system . . echo. "${list_items_sorted[*]}"
60 }
61
62 function get_disk_listscip-shell shell shell-project 0.0.0 get_disk_list(). {
63 declare kiwi_oemdevicefilter=${kiwi_oemdevicefilter}
64 declare kiwi_oemmultipath_scan=${kiwi_oemmultipath_scan}
65 declare kiwi_devicepersistency=${kiwi_devicepersistency}
66 declare kiwi_install_volid=${kiwi_install_volid}
67 declare kiwi_oemunattended=${kiwi_oemunattended}
68 declare kiwi_oemunattended_id=${kiwi_oemunattended_id}
69 declare kiwi_oemramdisksize=${kiwi_oemramdisksize}
70 local disk_id="by-id"
71 local disk_size
72 local disk_device
73 local disk_device_by_id
74 local disk_trans
75 local disk_meta
76 local list_items
77 local list_items_sorted
78 local max_disk
79 local kiwi_oem_maxdisk
80 local blk_opts="-p -n -r --sort NAME -o NAME,SIZE,TYPE,TRAN"
81 local message
82 local blk_opts_plus_label="${blk_opts},LABEL"
83 local kiwi_install_disk_part
84
85 if [scip-shell system . . `[`. -n "${kiwi_devicepersistency}" ];then
86 disk_id=${kiwi_devicepersistency}
87 fi
88 max_disk=0
89 kiwi_install_devicepersistency=$(getarg rd.kiwi.install.devicepersistency=)
90 kiwi_oemmultipath_scan=$(bool "${kiwi_oemmultipath_scan}")
91 kiwi_oem_maxdisk=$(getarg rd.kiwi.oem.maxdisk=)
92 kiwi_oem_installdevice=$(getarg rd.kiwi.oem.installdevice=)
93
94 # Check for smallest disk parameter
95 # - Configure lsblk options based on the selection mode
96 if getargbool 0 rd.kiwi.oem.smallest_disk; then
97 # Sort by SIZE (ascending), include TRAN to identify USBs
98 blk_opts="-p -n -r --sort SIZE -o NAME,SIZE,TYPE,TRAN"
99 blk_opts_plus_label="${blk_opts},LABEL"
100 fi
101
102 if [scip-shell system . . `[`. -n "${kiwi_install_devicepersistency}" ];then
103 disk_id=${kiwi_install_devicepersistency}
104 fi
105 if [scip-shell system . . `[`. -n "${kiwi_oem_maxdisk}" ]; then
106 max_disk=$(binsize_to_bytesize "${kiwi_oem_maxdisk}") || max_disk=0
107 fi
108 if getargbool 0 rd.kiwi.ramdisk; then
109 # target should be a ramdisk on request. Thus actively
110 # load the ramdisk block driver and support custom sizes
111 local rd_size
112 local custom_rd_size
113 local modfile=/etc/modprobe.d/99-brd.confscip-shell filesystem . . `/etc/modprobe.d/99-brd.conf`.
114 custom_rd_size=$(getarg ramdisk_size=)
115 if [scip-shell system . . `[`. -n "${custom_rd_size}" ];then
116 rd_size="${custom_rd_size}"
117 elif [scip-shell system . . `[`. -n "${kiwi_oemramdisksize}" ];then
118 rd_size="${kiwi_oemramdisksize}"
119 fi
120 mkdirscip-shell system . . mkdir. -p /etc/modprobe.dscip-shell filesystem . . `/etc/modprobe.d`.
121 if [scip-shell system . . `[`. -n "${rd_size}" ];then
122 echoscip-shell system . . echo. "options brd rd_size=${rd_size}" > ${modfile}
123 fi
124 modprobe brd
125 udev_pending
126 # target should be a ramdisk on request. Thus instruct
127 # lsblk to list only ramdisk devices (Major=1)
128 blk_opts="-I 1 ${blk_opts}"
129 elif [scip-shell system . . `[`. "${kiwi_oemmultipath_scan}" = "true" ];then
130 scan_multipath_devicesscip-shell shell shell-project 0.0.0 scan_multipath_devices().
131 fi
132 kiwi_install_disk_part=$(
133 eval lsblk "${blk_opts_plus_label}" | \
134 tr -s ' ' ":" | \
135 grep ":${kiwi_install_volid}$" | \
136 cut -f1 -d:
137 )
138 for disk_meta in $(
139 eval lsblk "${blk_opts}" | grepscip-shell system . . grep. -E "disk|raid" | trscip-shell system . . tr. ' ' ":"
140 );do
141 disk_device="$(echoscip-shell system . . echo. "${disk_meta}" | cutscip-shell system . . cut. -f1 -d:)"
142 if [[ "${kiwi_install_disk_part}" == "${disk_device}"* ]]; then
143 # ignore install source device
144 continue
145 fi
146 disk_mpath_child=$(
147 eval lsblk "${blk_opts}" "${disk_device}" | grepscip-shell system . . grep. mpath | \
148 tr ' ' ":"
149 )
150 if [[ -n "${disk_mpath_child}" ]];then
151 # use mpath device instead of parent device for multipath
152 disk_device="$(echoscip-shell system . . echo. "${disk_mpath_child}" | cutscip-shell system . . cut. -f1 -d:)"
153 fi
154
155 # Filter USBs if smallest disk is requested
156 disk_trans=$(echoscip-shell system . . echo. "${disk_meta}" | cutscip-shell system . . cut. -f4 -d:)
157 if getargbool 0 rd.kiwi.oem.smallest_disk; then
158 if [[ "${disk_trans}" == "usb" ]]; then
159 continue
160 fi
161 fi
162
163 disk_size=$(echoscip-shell system . . echo. "${disk_meta}" | cutscip-shell system . . cut. -f2 -d:)
164 if [scip-shell system . . `[`. "${max_disk}" -gt 0 ]; then
165 local disk_size_bytes
166 disk_size_bytes=$(binsize_to_bytesize "${disk_size}") || \
167 disk_size_bytes=0
168 if [scip-shell system . . `[`. "${disk_size_bytes}" -gt "${max_disk}" ]; then
169 message="${disk_device} filtered out by"
170 message="${message} rd.kiwi.oem.maxdisk=${kiwi_oem_maxdisk}"
171 message="${message} (disk size is: ${disk_size})"
172 info "${message}" >&2
173 continue
174 fi
175 fi
176 disk_device_by_id=$(
177 get_persistent_device_from_unix_node "${disk_device}" "${disk_id}"
178 )
179 if [scip-shell system . . `[`. -n "${disk_device_by_id}" ];then
180 disk_device=${disk_device_by_id}
181 fi
182 # check for static filter rules
183 if [[ ${disk_device} =~ ^/dev/fd ]];then
184 # ignore floppy disk devices
185 continue
186 fi
187 # check for custom filter rule
188 if [scip-shell system . . `[`. -n "${kiwi_oemdevicefilter}" ];then
189 if [[ ${disk_device} =~ ${kiwi_oemdevicefilter} ]];then
190 message="${disk_device} filtered out by rule:"
191 message="${message} ${kiwi_oemdevicefilter}"
192 info "${message}" >&2
193 continue
194 fi
195 fi
196 if [[ "${list_items}" == *"${disk_device}"* ]];then
197 # device already in the list, can happen in multipath systems
198 continue
199 fi
200 list_items="${list_items} ${disk_device} ${disk_size}"
201 done
202 if [scip-shell system . . `[`. -n "${kiwi_oem_installdevice}" ];then
203 # install device overwritten by cmdline.
204 local device=${kiwi_oem_installdevice}
205 local device_meta
206 local device_size
207 if [scip-shell system . . `[`. ! -e "${device}" ];then
208 local no_dev="Given device ${device} does not exist"
209 report_and_quit "${no_dev}"
210 fi
211 if [scip-shell system . . `[`. ! -b "${device}" ];then
212 local no_block_dev="Given device ${device} is not a block special"
213 report_and_quit "${no_block_dev}"
214 fi
215 device_meta=$(
216 eval lsblk "${blk_opts}" "${device}" |\
217 grep -E "disk|raid|mpath" | tr ' ' ":"
218 )
219 device_size=$(echoscip-shell system . . echo. "${device_meta}" | cutscip-shell system . . cut. -f2 -d:)
220 list_items="${device} ${device_size}"
221 fi
222 if [scip-shell system . . `[`. -z "${list_items}" ];then
223 local no_device_text="No device(s) for installation found"
224 report_and_quit "${no_device_text}"
225 fi
226
227 # Conditional Sorting
228 if getargbool 0 rd.kiwi.oem.smallest_disk; then
229 # If looking for smallest disk, preserve the lsblk size-sort order
230 echoscip-shell system . . echo. "${list_items}"
231 else
232 # Default behavior:
233 # apply final alphabetical sorting for the used disk_device names
234 list_items_sorted=$(sort_disk_entriesscip-shell shell shell-project 0.0.0 sort_disk_entries(). "${list_items}")
235 for entry in ${list_items_sorted[*]}; do
236 echoscip-shell system . . echo. -n "${entry} $(find_disk_entryscip-shell shell shell-project 0.0.0 find_disk_entry(). "${list_items}" "${entry}") "
237 done
238 echoscip-shell system . . echo.
239 fi
240 }
241
242
243 function validate_disk_selectionscip-shell shell shell-project 0.0.0 validate_disk_selection(). {
244 local selected=$1
245 local disk_list
246 local entry
247 local count=0
248 disk_list=$(get_disk_listscip-shell shell shell-project 0.0.0 get_disk_list().)
249 for entry in ${disk_list};do
250 if [scip-shell system . . `[`. $((count % 2)) -eq 0 ];then
251 if [scip-shell system . . `[`. ! "${entry}" = "${selected}" ];then
252 # check system_identifier for the not selected disk
253 # if one of them matches the system_identifier because
254 # that would produce a global system inconsistency
255 if disk_matches_system_identifier "${entry}";then
256 report_and_quit "Disk ${entry} has the same partition UUID"
257 fi
258 fi
259 fi
260 count=$((count + 1))
261 done
262 }
263
264 function get_selected_diskscip-shell shell shell-project 0.0.0 get_selected_disk(). {
265 declare kiwi_oemunattended=${kiwi_oemunattended}
266 declare kiwi_oemunattended_id=${kiwi_oemunattended_id}
267 local disk_list
268 local device_array
269 kiwi_oemunattended=$(bool "${kiwi_oemunattended}")
270 disk_list=$(get_disk_listscip-shell shell shell-project 0.0.0 get_disk_list().)
271 if [scip-shell system . . `[`. -n "${disk_list}" ];then
272 local count=0
273 local device_index=0
274 for entry in ${disk_list};do
275 if [scip-shell system . . `[`. $((count % 2)) -eq 0 ];then
276 device_array[${device_index}]=${entry}
277 device_index=$((device_index + 1))
278 fi
279 count=$((count + 1))
280 done
281 if [scip-shell system . . `[`. "${device_index}" -eq 1 ];then
282 # one single disk device found, use it
283 echoscip-shell system . . echo. "${device_array[0]}"
284 elif [scip-shell system . . `[`. "${kiwi_oemunattended}" = "true" ];then
285 if [scip-shell system . . `[`. -z "${kiwi_oemunattended_id}" ];then
286 # unattended mode requested but no target specifier,
287 # thus use first device from list
288 echoscip-shell system . . echo. "${device_array[0]}"
289 else
290 # unattended mode requested with target specifier
291 # use this device if present
292 local device
293 for device in "${device_array[@]}"; do
294 if [[ ${device} =~ ${kiwi_oemunattended_id} ]];then
295 echoscip-shell system . . echo. "${device}"
296 return
297 fi
298 done
299 fi
300 else
301 # manually select from storage list
302 if ! run_dialog \
303 --menu "\"Select Installation Disk\"" 20 75 15 "${disk_list}"
304 then
305 report_and_quit "System installation canceled"
306 fi
307 get_dialog_result
308 fi
309 fi
310 }
311
312 function export_image_metadatascip-shell shell shell-project 0.0.0 export_image_metadata(). {
313 local image_source_files=$1
314 export checksum
315 export blocks
316 export blocksize
317 export zblocks
318 export zblocksize
319 local meta_file
320 meta_file="$(echoscip-shell system . . echo. "${image_source_files}" | cutscip-shell system . . cut. -f2 -d\|)"
321 if ! read -r checksum blocks blocksize zblocks zblocksize < "${meta_file}"
322 then
323 report_and_quit "Reading ${meta_file} failed"
324 fi
325 echoscip-shell system . . echo. "Image checksum: ${checksum}"
326 echoscip-shell system . . echo. "Image blocks: ${blocks} / blocksize: ${blocksize}"
327 if [scip-shell system . . `[`. -n "${zblocks}" ];then
328 echoscip-shell system . . echo. "Image compressed blocks: ${zblocks} / blocksize: ${zblocksize}"
329 fi
330 }
331
332 function check_image_fits_targetscip-shell shell shell-project 0.0.0 check_image_fits_target(). {
333 local image_target=$1
334 local need_mbytes
335 local have_mbytes
336 need_mbytes=$((blocks * blocksize / 1048576))
337 have_mbytes=$(($(get_block_device_kbsize "${image_target}") / 1024))
338 echoscip-shell system . . echo. "Have size: ${image_target} -> ${have_mbytes} MB"
339 echoscip-shell system . . echo. "Need size: ${image_source} -> ${need_mbytes} MB"
340 if [scip-shell system . . `[`. ${need_mbytes} -gt ${have_mbytes} ];then
341 report_and_quit "Not enough space available for this image"
342 fi
343 }
344
345 function dump_imagescip-shell shell shell-project 0.0.0 dump_image(). {
346 declare kiwi_oemsilentinstall=${kiwi_oemsilentinstall}
347 declare kiwi_oemunattended=${kiwi_oemunattended}
348 local image_source_files=$1
349 local image_target=$2
350 local image_from_remote=$3
351 local image_source
352 local image_basename
353 kiwi_oemsilentinstall=$(bool "${kiwi_oemsilentinstall}")
354 kiwi_oemunattended=$(bool "${kiwi_oemunattended}")
355 image_source="$(echoscip-shell system . . echo. "${image_source_files}" | cutscip-shell system . . cut. -f1 -d\|)"
356 image_basename=$(basenamescip-shell system . . basename. "${image_source}")
357 local progress=/dev/install_progressscip-shell filesystem . . `/dev/install_progress`.
358 local load_text="Loading ${image_basename}..."
359 local title_text="Installation..."
360 local dump
361 local parttable
362 local count_32k
363 local image_size
364 local count=0
365 local block_size=32k
366
367 # can we dump this
368 check_image_fits_targetscip-shell shell shell-project 0.0.0 check_image_fits_target(). "${image_target}"
369
370 # select dump method
371 if [scip-shell system . . `[`. -n "${image_from_remote}" ];then
372 dump=dump_remote_image
373 else
374 dump=dump_local_image
375 fi
376
377 # setup blocks and blocksize to retain last
378 if getargbool 0 rd.kiwi.install.retain_last; then
379 if [scip-shell system . . `[`. -n "${image_from_remote}" ];then
380 image_size=$((blocks * blocksize))
381 parttable=$(
382 fetch_remote_partition_table "${image_source}" "${image_size}"
383 )
384 else
385 parttable=$(
386 fetch_local_partition_table "${image_source}"
387 )
388 fi
389 if compatible_to_retainscip-shell shell shell-project 0.0.0 compatible_to_retain(). "${parttable}" "${image_target}"; then
390 count=$(get_disk_offset_retain_last_partition "${parttable}")
391 fi
392 if [scip-shell system . . `[`. "${count}" -gt 0 ];then
393 block_size=$(get_sector_size_from_table_dump "${parttable}")
394 count_32k=$(
395 optimize_count_for_32k_blocksize "${block_size}" "${count}"
396 )
397 if [scip-shell system . . `[`. ! "${count}" = "${count_32k}" ];then
398 count="${count_32k}"
399 block_size=32k
400 fi
401 fi
402 fi
403
404 # last chance to stop us
405 if [scip-shell system . . `[`. "${kiwi_oemunattended}" = "false" ];then
406 local ack_dump_text="Destroying ALL data on ${image_target}, continue ?"
407 if ! run_dialog --yesno "\"${ack_dump_text}\"" 7 80; then
408 local install_cancel_text="System installation canceled"
409 report_and_quit "${install_cancel_text}"
410 fi
411 fi
412
413 # deploy
414 echoscip-shell system . . echo. "${load_text} [${image_target}]..."
415 if command -v pv &>/dev/nullscip-shell filesystem . . `/dev/null`. && [scip-shell system . . `[`. "${kiwi_oemsilentinstall}" = "false" ]
416 then
417 # dump with dialog based progress information
418 setup_progress_fifo ${progress}
419 eval \
420 "${dump}" \
421 "${image_source}" \
422 "${image_target}" \
423 "${count}" \
424 "${block_size}" \
425 "${progress}" \
426 &
427 run_progress_dialog "${load_text}" "${title_text}"
428 else
429 # dump with silently blocked console
430 if ! eval \
431 "${dump}" \
432 "${image_source}" \
433 "${image_target}" \
434 "${count}" \
435 "${block_size}"
436 then
437 report_and_quit "Failed to install image"
438 fi
439 fi
440 }
441
442 function fetch_local_partition_tablescip-shell shell shell-project 0.0.0 fetch_local_partition_table(). {
443 local image_source=$1
444 local parttable=/tmp/parttablescip-shell filesystem . . `/tmp/parttable`.
445 sfdisk -d "${image_source}" > "${parttable}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
446 echoscip-shell system . . echo. "${parttable}"
447 }
448
449 function fetch_remote_partition_tablescip-shell shell shell-project 0.0.0 fetch_remote_partition_table(). {
450 local image_source=$1
451 local image_size=$2
452 local parttable=/tmp/parttablescip-shell filesystem . . `/tmp/parttable`.
453 ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=/tmp/tablescip-shell filesystem . . `/tmp/table`. bs=1 count=0 seek="${image_size}" &>/dev/nullscip-shell filesystem . . `/dev/null`.
454 fetch_file "${image_source}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | ddscip-shell system . . dd. of=/tmp/tablescip-shell filesystem . . `/tmp/table`. bs=512 count=1 conv=notrunc &>/dev/nullscip-shell filesystem . . `/dev/null`.
455 sfdisk -d /tmp/tablescip-shell filesystem . . `/tmp/table`. > "${parttable}" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
456 echoscip-shell system . . echo. "${parttable}"
457 }
458
459 function get_sector_size_from_table_dumpscip-shell shell shell-project 0.0.0 get_sector_size_from_table_dump(). {
460 local parttable=$1
461 sector_size=$(grepscip-shell system . . grep. sector-size: "${parttable}" | cutscip-shell system . . cut. -f2 -d:)
462 echoscip-shell system . . echo. "${sector_size}"
463 }
464
465 function compatible_to_retainscip-shell shell shell-project 0.0.0 compatible_to_retain(). {
466 local parttable=$1
467 local image_target=$2
468 local source_start
469 local target_start
470 source_start=$(
471 tailscip-shell system . . tail. -n 1 "${parttable}" | cutscip-shell system . . cut. -f2 -d= | cutscip-shell system . . cut. -f1 -d,
472 )
473 target_start=$(
474 sfdisk -d "${image_target}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |\
475 tail -n 1 | cut -f2 -d= | cut -f1 -d,
476 )
477 if [scip-shell system . . `[`. -z "${source_start}" ] || [scip-shell system . . `[`. -z "${target_start}" ];then
478 # no partition information for either source or target
479 # broken or net new deployment on empty disk
480 touchscip-shell system . . touch. /tmp/retain_not_applicablescip-shell filesystem . . `/tmp/retain_not_applicable`.
481 return 1
482 fi
483 if [scip-shell system . . `[`. ! "${source_start}" = "${target_start}" ];then
484 report_and_quit "Cannot retain partition, start address mismatch"
485 fi
486 return 0
487 }
488
489 function get_disk_offset_retain_last_partitionscip-shell shell shell-project 0.0.0 get_disk_offset_retain_last_partition(). {
490 local parttable=$1
491 local next_to_last
492 local start
493 local size
494 local offset
495 next_to_last=$(tailscip-shell system . . tail. -n 2 "${parttable}" | headscip-shell system . . head. -n 1)
496 if [scip-shell system . . `[`. -n "${next_to_last}" ];then
497 start=$(echoscip-shell system . . echo. "${next_to_last}" | cutscip-shell system . . cut. -f2 -d= | cutscip-shell system . . cut. -f1 -d,)
498 size=$(echoscip-shell system . . echo. "${next_to_last}" | cutscip-shell system . . cut. -f3 -d= | cutscip-shell system . . cut. -f1 -d,)
499 offset=$((start + size))
500 echoscip-shell system . . echo. "${offset}"
501 else
502 echoscip-shell system . . echo. 0
503 fi
504 }
505
506 function optimize_count_for_32k_blocksizescip-shell shell shell-project 0.0.0 optimize_count_for_32k_blocksize(). {
507 local block_size=$1
508 local count=$2
509 local dump_bytes
510 dump_bytes=$((block_size * count))
511 if [scip-shell system . . `[`. $((dump_bytes % 32768)) -eq 0 ];then
512 # dump_bytes is a multiple of 32k, use it for better I/O performance
513 count=$((dump_bytes / 32768))
514 fi
515 echoscip-shell system . . echo. "${count}"
516 }
517
518 function dump_local_imagescip-shell shell shell-project 0.0.0 dump_local_image(). {
519 local image_source=$1
520 local image_target=$2
521 local count=$3
522 local block_size=$4
523 local progress=$5
524 if [scip-shell system . . `[`. "${count}" -gt 0 ];then
525 count="count=${count}"
526 else
527 unset count
528 fi
529 # shellcheck disable=SC2086
530 if [scip-shell system . . `[`. -e "${progress}" ];then
531 (
532 pv -n "${image_source}" |\
533 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/nullscip-shell filesystem . . `/dev/null`.
534 ) 2>"${progress}"
535 else
536 ddscip-shell system . . dd. \
537 if="${image_source}" bs="${block_size}" ${count} \
538 of="${image_target}" &>/dev/nullscip-shell filesystem . . `/dev/null`.
539 fi
540 }
541
542 function dump_remote_imagescip-shell shell shell-project 0.0.0 dump_remote_image(). {
543 local image_source=$1
544 local image_target=$2
545 local count=$3
546 local block_size=$4
547 local progress=$5
548 local image_size
549 image_size=$((blocks * blocksize))
550 if [scip-shell system . . `[`. "${count}" -gt 0 ];then
551 count="count=${count}"
552 else
553 unset count
554 fi
555 # shellcheck disable=SC2086
556 if [scip-shell system . . `[`. -e "${progress}" ];then
557 (
558 fetch_file "${image_source}" "${image_size}" |\
559 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/nullscip-shell filesystem . . `/dev/null`.
560 ) 2>"${progress}"
561 else
562 fetch_file "${image_source}" |\
563 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/nullscip-shell filesystem . . `/dev/null`.
564 fi
565 }
566
567 function check_image_integrityscip-shell shell shell-project 0.0.0 check_image_integrity(). {
568 declare kiwi_oemskipverify=${kiwi_oemskipverify}
569 declare kiwi_oemsilentverify=${kiwi_oemsilentverify}
570 local image_target=$1
571 local progress=/dev/install_verify_progressscip-shell filesystem . . `/dev/install_verify_progress`.
572 local verify_text="Verifying ${image_target}"
573 local title_text="Installation..."
574 local verify_result
575 local shasum
576 local sha_extension
577 kiwi_oemskipverify=$(bool "${kiwi_oemskipverify}")
578 kiwi_oemsilentverify=$(bool "${kiwi_oemsilentverify}")
579 shasum=$(shasum_tool)
580 sha_extension=$(shasum_extension)
581 verify_result=/dumped_image."${sha_extension}"
582 if [scip-shell system . . `[`. "${kiwi_oemskipverify}" = "true" ];then
583 # no verification wanted
584 return
585 fi
586 if getargbool 0 rd.kiwi.install.retain_last; then
587 if [scip-shell system . . `[`. ! -e /tmp/retain_not_applicablescip-shell filesystem . . `/tmp/retain_not_applicable`. ];then
588 # no verification possible as only a portion of
589 # the image got deployed intentionally
590 return
591 fi
592 fi
593 if command -v pv &>/dev/nullscip-shell filesystem . . `/dev/null`. && [scip-shell system . . `[`. "${kiwi_oemsilentverify}" = "false" ]
594 then
595 # verify with dialog based progress information
596 setup_progress_fifo ${progress}
597 (
598 pv --size $((blocks * blocksize)) --stop-at-size \
599 -n "${image_target}" | "${shasum}" - > "${verify_result}"
600 ) 2>${progress} &
601 run_progress_dialog "${verify_text}" "${title_text}"
602 else
603 # verify with silently blocked console
604 hscip-shell system . . head.eadscip-shell system . . head. --bytes=$((blocks * blocksize)) "${image_target}" |\
605 "${shasum}" - > "${verify_result}"
606 fi
607 local checksum_dumped_image
608 local checksum_fileref
609 read -r checksum_dumped_image checksum_fileref < "${verify_result}"
610 echoscip-shell system . . echo. "Dumped Image checksum: ${checksum_dumped_image}/${checksum_fileref}"
611 if [scip-shell system . . `[`. "${checksum}" != "${checksum_dumped_image}" ];then
612 report_and_quit "Image checksum test failed"
613 fi
614 }
615
616 function get_local_image_source_filesscip-shell shell shell-project 0.0.0 get_local_image_source_files(). {
617 declare root=${root}
618 local iso_device="${root#install:}"
619 local iso_mount_point=/run/installscip-shell filesystem . . `/run/install`.
620 local image_mount_point=/run/imagescip-shell filesystem . . `/run/image`.
621 local sha_extension
622 local image_source
623 local image_sha
624 sha_extension=$(shasum_extension)
625 mkdirscip-shell system . . mkdir. -m 0755 -p "${iso_mount_point}"
626 if ! mountscip-shell system . . mount. -n "${iso_device}" "${iso_mount_point}"; then
627 report_and_quit "Failed to mount install ISO device"
628 fi
629 mkdirscip-shell system . . mkdir. -m 0755 -p "${image_mount_point}"
630 if ! mountscip-shell system . . mount. -n "${iso_mount_point}"/*.squashfs ${image_mount_point};then
631 report_and_quit "Failed to mount install image squashfs filesystem"
632 fi
633 image_source="$(echoscip-shell system . . echo. "${image_mount_point}"/*.raw)"
634 image_sha="$(echoscip-shell system . . echo. "${image_mount_point}"/*."${sha_extension}")"
635 echoscip-shell system . . echo. "${image_source}|${image_sha}"
636 }
637
638 function get_remote_image_source_filesscip-shell shell shell-project 0.0.0 get_remote_image_source_files(). {
639 local image_uri
640 local sha_extension
641 local image_sha
642 local install_dir=/run/installscip-shell filesystem . . `/run/install`.
643 local metadata_dir="${install_dir}/boot/remote/loader"
644
645 sha_extension=$(shasum_extension)
646
647 local image_sha="${install_dir}/image.${sha_extension}"
648
649 mkdirscip-shell system . . mkdir. -p "${metadata_dir}"
650
651 image_uri=$(getarg rd.kiwi.install.image=)
652 # make sure the protocol type is tftp for metadata files. There is no need for
653 # complex protocol types on small files and for standard PXE boot operations
654 # only tftp can be guaranteed
655 image_sha_uri=$(
656 echoscip-shell system . . echo. "${image_uri}" | awkscip-shell system . . awk. '{ gsub("\\.xz",".'"${sha_extension}"'", $1); gsub("dolly:","tftp:", $1); print $1 }'
657 )
658 image_initrd_uri=$(
659 echoscip-shell system . . echo. "${image_uri}" | awkscip-shell system . . awk. '{ gsub("\\.xz",".initrd", $1); gsub("dolly:","tftp:", $1); print $1 }'
660 )
661 image_kernel_uri=$(
662 echoscip-shell system . . echo. "${image_uri}" | awkscip-shell system . . awk. '{ gsub("\\.xz",".kernel", $1); gsub("dolly:","tftp:", $1); print $1 }'
663 )
664 image_config_uri=$(
665 echoscip-shell system . . echo. "${image_uri}" | \
666 awk '{ gsub("\\.xz",".config.bootoptions", $1); gsub("dolly:","tftp:", $1); print $1 }'
667 )
668
669 # if we can not access image_sha_uri, maybe network setup
670 # by dracut did fail, so collect some additional info
671 if ! fetch_file "${image_sha_uri}" > "${image_sha}";then
672 {
673 echoscip-shell system . . echo. "--- ip a ---"; ip a
674 echoscip-shell system . . echo. "--- ip r ---"; ip r
675 } >> /tmp/fetch.infoscip-shell filesystem . . `/tmp/fetch.info`. 2>&1
676 show_log_and_quit \
677 "Failed to fetch ${image_sha_uri}" /tmp/fetch.infoscip-shell filesystem . . `/tmp/fetch.info`.
678 fi
679
680 if ! getargbool 0 rd.kiwi.ramdisk; then
681 if ! fetch_file "${image_kernel_uri}" > "${metadata_dir}/linux";then
682 show_log_and_quit \
683 "Failed to fetch ${image_kernel_uri}" /tmp/fetch.infoscip-shell filesystem . . `/tmp/fetch.info`.
684 fi
685
686 if ! fetch_file "${image_initrd_uri}" > "${install_dir}/initrd.system_image"
687 then
688 show_log_and_quit \
689 "Failed to fetch ${image_initrd_uri}" /tmp/fetch.infoscip-shell filesystem . . `/tmp/fetch.info`.
690 fi
691 fi
692
693 if ! fetch_file "${image_config_uri}" > "/config.bootoptionsscip-shell filesystem . . `/config.bootoptions`."
694 then
695 show_log_and_quit \
696 "Failed to fetch ${image_config_uri}" /tmp/fetch.infoscip-shell filesystem . . `/tmp/fetch.info`.
697 fi
698
699 echoscip-shell system . . echo. "${image_uri}|${image_sha}"
700 }
701
702 #======================================
703 # Perform image dump/install operations
704 #--------------------------------------
705 setup_debug
706
707 lib_initialize
708
709 udev_pending
710
711 image_target=$(get_selected_diskscip-shell shell shell-project 0.0.0 get_selected_disk().)
712
713 if getargbool 0 rd.kiwi.oem.disk.consistency; then
714 validate_disk_selectionscip-shell shell shell-project 0.0.0 validate_disk_selection(). "${image_target}"
715 fi
716
717 if getargbool 0 rd.kiwi.install.pxe; then
718 image_source_files=$(get_remote_image_source_filesscip-shell shell shell-project 0.0.0 get_remote_image_source_files().)
719 else
720 image_source_files=$(get_local_image_source_filesscip-shell shell shell-project 0.0.0 get_local_image_source_files().)
721 fi
722
723 export_image_metadatascip-shell shell shell-project 0.0.0 export_image_metadata(). "${image_source_files}"
724
725 if getargbool 0 rd.kiwi.install.pxe; then
726 dump_imagescip-shell shell shell-project 0.0.0 dump_image(). "${image_source_files}" "${image_target}" "remote_image"
727 else
728 dump_imagescip-shell shell shell-project 0.0.0 dump_image(). "${image_source_files}" "${image_target}"
729 fi
730
731 check_image_integrityscip-shell shell shell-project 0.0.0 check_image_integrity(). "${image_target}"