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 export_bootdevice
&& export_partdevice diskdev
0 ||
{
51 echo "Unable to determine upgrade device"
57 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
58 get_partitions
"/dev/$diskdev" bootdisk
60 #extract the boot sector from the image
61 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
63 get_partitions
/tmp
/image.bs image
66 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
71 if [ -n "$diff" ]; then
72 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
74 # Separate removal and addtion is necessary; otherwise, partition 1
75 # will be missing if it overlaps with the old partition 2
76 partx
-d - "/dev/$diskdev"
77 partx
-a - "/dev/$diskdev"
82 #iterate over each partition from the image and write it to the boot disk
83 while read part start size
; do
84 if export_partdevice partdev
$part; then
85 echo "Writing image to /dev/$partdev..."
86 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
88 echo "Unable to find partition $part device, skipped."
90 done < /tmp
/partmap.image
93 echo "Writing new UUID to /dev/$diskdev..."
94 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync