1 platform_check_image() {
2 local diskdev partdev diff
3 [ "$#" -gt 1 ] && return 1
5 case "$(get_magic_word "$1")" in
8 echo "Invalid image type"
13 export_bootdevice && export_partdevice diskdev 0 || {
14 echo "Unable to determine upgrade device"
18 get_partitions "/dev/$diskdev" bootdisk
20 #extract the boot sector from the image
21 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
23 get_partitions /tmp/image.bs image
26 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
28 rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
30 if [ -n "$diff" ]; then
31 echo "Partition layout has changed. Full image will be written."
32 ask_bool 0 "Abort" && exit 1
37 platform_copy_config() {
40 if export_partdevice partdev 1; then
41 mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
42 cp -af "$CONF_TAR" /mnt/
47 platform_do_upgrade() {
48 local diskdev partdev diff
50 if export_bootdevice && export_partdevice diskdev 0; then
52 if [ "$SAVE_PARTITIONS" = "1" ]; then
53 get_partitions "/dev/$diskdev" bootdisk
55 #extract the boot sector from the image
56 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
58 get_partitions /tmp/image.bs image
61 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
62 if [ -n "$diff" ]; then
63 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
67 #iterate over each partition from the image and write it to the boot disk
68 while read part start size; do
69 if export_partdevice partdev $part; then
70 echo "Writing image to /dev/$partdev..."
71 get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
73 echo "Unable to find partition $part device, skipped."
75 done < /tmp/partmap.image
78 echo "Writing new UUID to /dev/$diskdev..."
79 get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
81 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync