1 platform_check_image() {
2 [ "$#" -gt 1 ] && return 1
4 case "$(get_magic_word "$1")" in
7 echo "Invalid image type"
13 platform_copy_config() {
16 if export_partdevice partdev 1; then
17 mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
18 cp -af "$CONF_TAR" /mnt/
23 platform_do_upgrade() {
24 local diskdev partdev ibs diff
26 if export_bootdevice && export_partdevice diskdev 0; then
28 if [ "$SAVE_PARTITIONS" = "1" ]; then
29 get_partitions "/dev/$diskdev" bootdisk
32 if [ -f "/sys/block/$diskdev/queue/physical_block_size" ]; then
33 ibs="$(cat "/sys/block/$diskdev/queue/physical_block_size")"
38 #extract the boot sector from the image
39 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
41 get_partitions /tmp/image.bs image
44 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
45 if [ -n "$diff" ]; then
46 echo "Partition layout is changed. Full image will be written."
47 ask_bool 0 "Abort" && exit
49 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
53 #iterate over each partition from the image and write it to the boot disk
54 while read part start size; do
55 if export_partdevice partdev $part; then
56 echo "Writing image to /dev/$partdev..."
57 get_image "$@" | dd of="/dev/$partdev" ibs="$ibs" obs=1M skip="$start" count="$size" conv=fsync
59 echo "Unable to find partition $part device, skipped."
61 done < /tmp/partmap.image
64 echo "Writing new UUID to /dev/$diskdev..."
65 get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
67 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync