Debian Codegraph @

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

raw
1 #!/bin/bash
2 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
3 type setup_debug >/dev/null 2>&1 || . /lib/kiwi-lib.sh
4 type run_dialog >/dev/null 2>&1 || . /lib/kiwi-dialog-lib.sh
5 type get_block_device_kbsize >/dev/null 2>&1 || . /lib/kiwi-partitions-lib.sh
6 type fetch_file >/dev/null 2>&1 || . /lib/kiwi-net-lib.sh
7
8 #======================================
9 # Functions
10 #--------------------------------------
11 function scan_multipath_devices {
12 # """
13 # starts multipath daemon from multipath module
14 # """
15 systemctl start multipathd
16 }
17
18 function 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 [ -n "${found}" ];then
29 echo "${entry}"
30 return
31 fi
32 if [ $((count % 2)) -eq 0 ];then
33 if [ "${entry}" = "${search}" ];then
34 found=1
35 fi
36 fi
37 count=$((count + 1))
38 done
39 }
40
41 function 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 [ $((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 printf '%s\0' "${device_array[@]}" | sort -z > list_items_sorted.txt
58 readarray -td '' list_items_sorted < list_items_sorted.txt
59 echo "${list_items_sorted[*]}"
60 }
61
62 function 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 [ -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 [ -n "${kiwi_install_devicepersistency}" ];then
103 disk_id=${kiwi_install_devicepersistency}
104 fi
105 if [ -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.conf
114 custom_rd_size=$(getarg ramdisk_size=)
115 if [ -n "${custom_rd_size}" ];then
116 rd_size="${custom_rd_size}"
117 elif [ -n "${kiwi_oemramdisksize}" ];then
118 rd_size="${kiwi_oemramdisksize}"
119 fi
120 mkdir -p /etc/modprobe.d
121 if [ -n "${rd_size}" ];then
122 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 [ "${kiwi_oemmultipath_scan}" = "true" ];then
130 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}" | grep -E "disk|raid" | tr ' ' ":"
140 );do
141 disk_device="$(echo "${disk_meta}" | 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}" | 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="$(echo "${disk_mpath_child}" | cut -f1 -d:)"
153 fi
154
155 # Filter USBs if smallest disk is requested
156 disk_trans=$(echo "${disk_meta}" | 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=$(echo "${disk_meta}" | cut -f2 -d:)
164 if [ "${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 [ "${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 [ -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 [ -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 [ -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 [ ! -e "${device}" ];then
208 local no_dev="Given device ${device} does not exist"
209 report_and_quit "${no_dev}"
210 fi
211 if [ ! -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=$(echo "${device_meta}" | cut -f2 -d:)
220 list_items="${device} ${device_size}"
221 fi
222 if [ -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 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_entries "${list_items}")
235 for entry in ${list_items_sorted[*]}; do
236 echo -n "${entry} $(find_disk_entry "${list_items}" "${entry}") "
237 done
238 echo
239 fi
240 }
241
242
243 function validate_disk_selection {
244 local selected=$1
245 local disk_list
246 local entry
247 local count=0
248 disk_list=$(get_disk_list)
249 for entry in ${disk_list};do
250 if [ $((count % 2)) -eq 0 ];then
251 if [ ! "${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_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_list)
271 if [ -n "${disk_list}" ];then
272 local count=0
273 local device_index=0
274 for entry in ${disk_list};do
275 if [ $((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 [ "${device_index}" -eq 1 ];then
282 # one single disk device found, use it
283 echo "${device_array[0]}"
284 elif [ "${kiwi_oemunattended}" = "true" ];then
285 if [ -z "${kiwi_oemunattended_id}" ];then
286 # unattended mode requested but no target specifier,
287 # thus use first device from list
288 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 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_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="$(echo "${image_source_files}" | 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 echo "Image checksum: ${checksum}"
326 echo "Image blocks: ${blocks} / blocksize: ${blocksize}"
327 if [ -n "${zblocks}" ];then
328 echo "Image compressed blocks: ${zblocks} / blocksize: ${zblocksize}"
329 fi
330 }
331
332 function 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 echo "Have size: ${image_target} -> ${have_mbytes} MB"
339 echo "Need size: ${image_source} -> ${need_mbytes} MB"
340 if [ ${need_mbytes} -gt ${have_mbytes} ];then
341 report_and_quit "Not enough space available for this image"
342 fi
343 }
344
345 function check_image_matches_target_blocksize {
346 declare kiwi_target_blocksize=${kiwi_target_blocksize}
347 local image_blocksize=${kiwi_target_blocksize}
348 local target_node
349 local target_blocksize
350 local message
351 target_node="${1}"
352 if [ -L "${target_node}" ];then
353 target_node="$(readlink "${target_node}")"
354 fi
355 target_node=$(basename "${target_node}")
356 target_blocksize="/sys/block/${target_node}/queue/physical_block_size"
357 mountpoint -q /sys || mount -t sysfs sysfs /sys
358 if [ -n "${image_blocksize}" ] && [ -e "${target_blocksize}" ];then
359 read -r target_blocksize < "${target_blocksize}"
360 if [ ! "${target_blocksize}" = "${image_blocksize}" ];then
361 message="Target blocksize(${target_blocksize}b) doesn't match"
362 message="${message} image blocksize(${image_blocksize}b)"
363 report_and_quit "${message}"
364 fi
365 fi
366 }
367
368 function dump_image {
369 declare kiwi_oemsilentinstall=${kiwi_oemsilentinstall}
370 declare kiwi_oemunattended=${kiwi_oemunattended}
371 local image_source_files=$1
372 local image_target=$2
373 local image_from_remote=$3
374 local image_source
375 local image_basename
376 kiwi_oemsilentinstall=$(bool "${kiwi_oemsilentinstall}")
377 kiwi_oemunattended=$(bool "${kiwi_oemunattended}")
378 image_source="$(echo "${image_source_files}" | cut -f1 -d\|)"
379 image_basename=$(basename "${image_source}")
380 local progress=/dev/install_progress
381 local load_text="Loading ${image_basename}..."
382 local title_text="Installation..."
383 local dump
384 local parttable
385 local count_32k
386 local image_size
387 local count=0
388 local block_size=32k
389
390 # can we dump this
391 check_image_fits_target "${image_target}"
392 check_image_matches_target_blocksize "${image_target}"
393
394 # select dump method
395 if [ -n "${image_from_remote}" ];then
396 dump=dump_remote_image
397 else
398 dump=dump_local_image
399 fi
400
401 # setup blocks and blocksize to retain last
402 if getargbool 0 rd.kiwi.install.retain_last; then
403 if [ -n "${image_from_remote}" ];then
404 image_size=$((blocks * blocksize))
405 parttable=$(
406 fetch_remote_partition_table "${image_source}" "${image_size}"
407 )
408 else
409 parttable=$(
410 fetch_local_partition_table "${image_source}"
411 )
412 fi
413 if compatible_to_retain "${parttable}" "${image_target}"; then
414 count=$(get_disk_offset_retain_last_partition "${parttable}")
415 fi
416 if [ "${count}" -gt 0 ];then
417 block_size=$(get_sector_size_from_table_dump "${parttable}")
418 count_32k=$(
419 optimize_count_for_32k_blocksize "${block_size}" "${count}"
420 )
421 if [ ! "${count}" = "${count_32k}" ];then
422 count="${count_32k}"
423 block_size=32k
424 fi
425 fi
426 fi
427
428 # last chance to stop us
429 if [ "${kiwi_oemunattended}" = "false" ];then
430 local ack_dump_text="Destroying ALL data on ${image_target}, continue ?"
431 if ! run_dialog --yesno "\"${ack_dump_text}\"" 7 80; then
432 local install_cancel_text="System installation canceled"
433 report_and_quit "${install_cancel_text}"
434 fi
435 fi
436
437 # deploy
438 echo "${load_text} [${image_target}]..."
439 if command -v pv &>/dev/null && [ "${kiwi_oemsilentinstall}" = "false" ]
440 then
441 # dump with dialog based progress information
442 setup_progress_fifo ${progress}
443 eval \
444 "${dump}" \
445 "${image_source}" \
446 "${image_target}" \
447 "${count}" \
448 "${block_size}" \
449 "${progress}" \
450 &
451 run_progress_dialog "${load_text}" "${title_text}"
452 else
453 # dump with silently blocked console
454 if ! eval \
455 "${dump}" \
456 "${image_source}" \
457 "${image_target}" \
458 "${count}" \
459 "${block_size}"
460 then
461 report_and_quit "Failed to install image"
462 fi
463 fi
464 }
465
466 function fetch_local_partition_table {
467 local image_source=$1
468 local parttable=/tmp/parttable
469 sfdisk -d "${image_source}" > "${parttable}" 2>/dev/null
470 echo "${parttable}"
471 }
472
473 function fetch_remote_partition_table {
474 local image_source=$1
475 local image_size=$2
476 local parttable=/tmp/parttable
477 dd if=/dev/zero of=/tmp/table bs=1 count=0 seek="${image_size}" &>/dev/null
478 fetch_file "${image_source}" 2>/dev/null | dd of=/tmp/table bs=512 count=1 conv=notrunc &>/dev/null
479 sfdisk -d /tmp/table > "${parttable}" 2>/dev/null
480 echo "${parttable}"
481 }
482
483 function get_sector_size_from_table_dump {
484 local parttable=$1
485 sector_size=$(grep sector-size: "${parttable}" | cut -f2 -d:)
486 echo "${sector_size}"
487 }
488
489 function compatible_to_retain {
490 local parttable=$1
491 local image_target=$2
492 local source_start
493 local target_start
494 source_start=$(
495 tail -n 1 "${parttable}" | cut -f2 -d= | cut -f1 -d,
496 )
497 target_start=$(
498 sfdisk -d "${image_target}" 2>/dev/null |\
499 tail -n 1 | cut -f2 -d= | cut -f1 -d,
500 )
501 if [ -z "${source_start}" ] || [ -z "${target_start}" ];then
502 # no partition information for either source or target
503 # broken or net new deployment on empty disk
504 touch /tmp/retain_not_applicable
505 return 1
506 fi
507 if [ ! "${source_start}" = "${target_start}" ];then
508 report_and_quit "Cannot retain partition, start address mismatch"
509 fi
510 return 0
511 }
512
513 function get_disk_offset_retain_last_partition {
514 local parttable=$1
515 local next_to_last
516 local start
517 local size
518 local offset
519 next_to_last=$(tail -n 2 "${parttable}" | head -n 1)
520 if [ -n "${next_to_last}" ];then
521 start=$(echo "${next_to_last}" | cut -f2 -d= | cut -f1 -d,)
522 size=$(echo "${next_to_last}" | cut -f3 -d= | cut -f1 -d,)
523 offset=$((start + size))
524 echo "${offset}"
525 else
526 echo 0
527 fi
528 }
529
530 function optimize_count_for_32k_blocksize {
531 local block_size=$1
532 local count=$2
533 local dump_bytes
534 dump_bytes=$((block_size * count))
535 if [ $((dump_bytes % 32768)) -eq 0 ];then
536 # dump_bytes is a multiple of 32k, use it for better I/O performance
537 count=$((dump_bytes / 32768))
538 fi
539 echo "${count}"
540 }
541
542 function dump_local_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 if [ "${count}" -gt 0 ];then
549 count="count=${count}"
550 else
551 unset count
552 fi
553 # shellcheck disable=SC2086
554 if [ -e "${progress}" ];then
555 (
556 pv -n "${image_source}" |\
557 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/null
558 ) 2>"${progress}"
559 else
560 dd \
561 if="${image_source}" bs="${block_size}" ${count} \
562 of="${image_target}" &>/dev/null
563 fi
564 }
565
566 function dump_remote_image {
567 local image_source=$1
568 local image_target=$2
569 local count=$3
570 local block_size=$4
571 local progress=$5
572 local image_size
573 image_size=$((blocks * blocksize))
574 if [ "${count}" -gt 0 ];then
575 count="count=${count}"
576 else
577 unset count
578 fi
579 # shellcheck disable=SC2086
580 if [ -e "${progress}" ];then
581 (
582 fetch_file "${image_source}" "${image_size}" |\
583 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/null
584 ) 2>"${progress}"
585 else
586 fetch_file "${image_source}" |\
587 dd bs="${block_size}" ${count} of="${image_target}" &>/dev/null
588 fi
589 }
590
591 function check_image_integrity {
592 declare kiwi_oemskipverify=${kiwi_oemskipverify}
593 declare kiwi_oemsilentverify=${kiwi_oemsilentverify}
594 local image_target=$1
595 local progress=/dev/install_verify_progress
596 local verify_text="Verifying ${image_target}"
597 local title_text="Installation..."
598 local verify_result
599 local shasum
600 local sha_extension
601 kiwi_oemskipverify=$(bool "${kiwi_oemskipverify}")
602 kiwi_oemsilentverify=$(bool "${kiwi_oemsilentverify}")
603 shasum=$(shasum_tool)
604 sha_extension=$(shasum_extension)
605 verify_result=/dumped_image."${sha_extension}"
606 if [ "${kiwi_oemskipverify}" = "true" ];then
607 # no verification wanted
608 return
609 fi
610 if getargbool 0 rd.kiwi.install.retain_last; then
611 if [ ! -e /tmp/retain_not_applicable ];then
612 # no verification possible as only a portion of
613 # the image got deployed intentionally
614 return
615 fi
616 fi
617 if command -v pv &>/dev/null && [ "${kiwi_oemsilentverify}" = "false" ]
618 then
619 # verify with dialog based progress information
620 setup_progress_fifo ${progress}
621 (
622 pv --size $((blocks * blocksize)) --stop-at-size \
623 -n "${image_target}" | "${shasum}" - > "${verify_result}"
624 ) 2>${progress} &
625 run_progress_dialog "${verify_text}" "${title_text}"
626 else
627 # verify with silently blocked console
628 head --bytes=$((blocks * blocksize)) "${image_target}" |\
629 "${shasum}" - > "${verify_result}"
630 fi
631 local checksum_dumped_image
632 local checksum_fileref
633 read -r checksum_dumped_image checksum_fileref < "${verify_result}"
634 echo "Dumped Image checksum: ${checksum_dumped_image}/${checksum_fileref}"
635 if [ "${checksum}" != "${checksum_dumped_image}" ];then
636 report_and_quit "Image checksum test failed"
637 fi
638 }
639
640 function get_local_image_source_files {
641 declare root=${root}
642 local iso_device="${root#install:}"
643 local iso_mount_point=/run/install
644 local image_mount_point=/run/image
645 local sha_extension
646 local image_source
647 local image_sha
648 sha_extension=$(shasum_extension)
649 mkdir -m 0755 -p "${iso_mount_point}"
650 if ! mount -n "${iso_device}" "${iso_mount_point}"; then
651 report_and_quit "Failed to mount install ISO device"
652 fi
653 mkdir -m 0755 -p "${image_mount_point}"
654 if ! mount -n "${iso_mount_point}"/*.squashfs ${image_mount_point};then
655 report_and_quit "Failed to mount install image squashfs filesystem"
656 fi
657 image_source="$(echo "${image_mount_point}"/*.raw)"
658 image_sha="$(echo "${image_mount_point}"/*."${sha_extension}")"
659 echo "${image_source}|${image_sha}"
660 }
661
662 function get_remote_image_source_files {
663 local image_uri
664 local sha_extension
665 local image_sha
666 local install_dir=/run/install
667 local metadata_dir="${install_dir}/boot/remote/loader"
668
669 sha_extension=$(shasum_extension)
670
671 local image_sha="${install_dir}/image.${sha_extension}"
672
673 mkdir -p "${metadata_dir}"
674
675 image_uri=$(getarg rd.kiwi.install.image=)
676 # make sure the protocol type is tftp for metadata files. There is no need for
677 # complex protocol types on small files and for standard PXE boot operations
678 # only tftp can be guaranteed
679 image_sha_uri=$(
680 echo "${image_uri}" | awk '{ gsub("\\.xz",".'"${sha_extension}"'", $1); gsub("dolly:","tftp:", $1); print $1 }'
681 )
682 image_initrd_uri=$(
683 echo "${image_uri}" | awk '{ gsub("\\.xz",".initrd", $1); gsub("dolly:","tftp:", $1); print $1 }'
684 )
685 image_kernel_uri=$(
686 echo "${image_uri}" | awk '{ gsub("\\.xz",".kernel", $1); gsub("dolly:","tftp:", $1); print $1 }'
687 )
688 image_config_uri=$(
689 echo "${image_uri}" | \
690 awk '{ gsub("\\.xz",".config.bootoptions", $1); gsub("dolly:","tftp:", $1); print $1 }'
691 )
692
693 # if we can not access image_sha_uri, maybe network setup
694 # by dracut did fail, so collect some additional info
695 if ! fetch_file "${image_sha_uri}" > "${image_sha}";then
696 {
697 echo "--- ip a ---"; ip a
698 echo "--- ip r ---"; ip r
699 } >> /tmp/fetch.info 2>&1
700 show_log_and_quit \
701 "Failed to fetch ${image_sha_uri}" /tmp/fetch.info
702 fi
703
704 if ! getargbool 0 rd.kiwi.ramdisk; then
705 if ! fetch_file "${image_kernel_uri}" > "${metadata_dir}/linux";then
706 show_log_and_quit \
707 "Failed to fetch ${image_kernel_uri}" /tmp/fetch.info
708 fi
709
710 if ! fetch_file "${image_initrd_uri}" > "${install_dir}/initrd.system_image"
711 then
712 show_log_and_quit \
713 "Failed to fetch ${image_initrd_uri}" /tmp/fetch.info
714 fi
715 fi
716
717 if ! fetch_file "${image_config_uri}" > "/config.bootoptions"
718 then
719 show_log_and_quit \
720 "Failed to fetch ${image_config_uri}" /tmp/fetch.info
721 fi
722
723 echo "${image_uri}|${image_sha}"
724 }
725
726 #======================================
727 # Perform image dump/install operations
728 #--------------------------------------
729 setup_debug
730
731 lib_initialize
732
733 udev_pending
734
735 image_target=$(get_selected_disk)
736
737 if getargbool 0 rd.kiwi.oem.disk.consistency; then
738 validate_disk_selection "${image_target}"
739 fi
740
741 if getargbool 0 rd.kiwi.install.pxe; then
742 image_source_files=$(get_remote_image_source_files)
743 else
744 image_source_files=$(get_local_image_source_files)
745 fi
746
747 export_image_metadata "${image_source_files}"
748
749 if getargbool 0 rd.kiwi.install.pxe; then
750 dump_image "${image_source_files}" "${image_target}" "remote_image"
751 else
752 dump_image "${image_source_files}" "${image_target}"
753 fi
754
755 check_image_integrity "${image_target}"