1 REQUIRE_IMAGE_METADATA
=1
5 get_image
"$1" |
dd bs
=1 count
=2 skip
="$pos" 2>/dev
/null |
hexdump -v -n 2 -e '1/1 "%02x"'
8 platform_check_image
() {
9 local diskdev partdev
diff
11 [ "$#" -gt 1 ] && return 1
13 case "$(get_magic_at "$1" 510)" in
16 echo "Failed to verify MBR boot signature."
21 export_bootdevice
&& export_partdevice diskdev
0 ||
{
22 echo "Unable to determine upgrade device"
26 get_partitions
"/dev/$diskdev" bootdisk
28 #extract the boot sector from the image
29 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
2>/dev
/null
31 get_partitions
/tmp
/image.bs image
34 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
36 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
38 if [ -n "$diff" ]; then
39 echo "Partition layout has changed. Full image will be written."
40 ask_bool
0 "Abort" && exit 1
45 platform_copy_config
() {
48 if export_partdevice partdev
1; then
49 mount
-o rw
,noatime
"/dev/$partdev" /mnt
50 cp -af "$CONF_TAR" /mnt
/
55 platform_do_upgrade
() {
56 local diskdev partdev
diff
58 export_bootdevice
&& export_partdevice diskdev
0 ||
{
59 echo "Unable to determine upgrade device"
65 if [ "$SAVE_PARTITIONS" = "1" ]; then
66 get_partitions
"/dev/$diskdev" bootdisk
68 #extract the boot sector from the image
69 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
71 get_partitions
/tmp
/image.bs image
74 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
79 if [ -n "$diff" ]; then
80 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
82 # Separate removal and addtion is necessary; otherwise, partition 1
83 # will be missing if it overlaps with the old partition 2
84 partx
-d - "/dev/$diskdev"
85 partx
-a - "/dev/$diskdev"
91 get_image
"$@" |
dd of
="$diskdev" bs
=512 skip
=1 seek
=1 count
=4097 conv
=fsync
,notrunc
92 #iterate over each partition from the image and write it to the boot disk
93 while read part start size
; do
94 if export_partdevice partdev
$part; then
95 echo "Writing image to /dev/$partdev..."
96 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
98 echo "Unable to find partition $part device, skipped."
100 done < /tmp
/partmap.image
103 echo "Writing new UUID to /dev/$diskdev..."
104 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync