1 REQUIRE_IMAGE_METADATA
=1
3 platform_check_image
() {
4 local diskdev partdev
diff
6 export_bootdevice
&& export_partdevice diskdev
0 ||
{
7 echo "Unable to determine upgrade device"
11 get_partitions
"/dev/$diskdev" bootdisk
13 #extract the boot sector from the image
14 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
2>/dev
/null
16 get_partitions
/tmp
/image.bs image
19 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
21 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
23 if [ -n "$diff" ]; then
24 echo "Partition layout has changed. Full image will be written."
25 ask_bool
0 "Abort" && exit 1
30 platform_copy_config
() {
33 if export_partdevice partdev
1; then
34 mount
-o rw
,noatime
"/dev/$partdev" /mnt
35 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
40 platform_do_upgrade
() {
41 local diskdev partdev
diff
43 export_bootdevice
&& export_partdevice diskdev
0 ||
{
44 echo "Unable to determine upgrade device"
50 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
51 get_partitions
"/dev/$diskdev" bootdisk
53 #extract the boot sector from the image
54 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
56 get_partitions
/tmp
/image.bs image
59 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
64 if [ -n "$diff" ]; then
65 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
67 # Separate removal and addtion is necessary; otherwise, partition 1
68 # will be missing if it overlaps with the old partition 2
69 partx
-d - "/dev/$diskdev"
70 partx
-a - "/dev/$diskdev"
75 #iterate over each partition from the image and write it to the boot disk
76 while read part start size
; do
77 if export_partdevice partdev
$part; then
78 echo "Writing image to /dev/$partdev..."
79 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
81 echo "Unable to find partition $part device, skipped."
83 done < /tmp
/partmap.image
86 echo "Writing new UUID to /dev/$diskdev..."
87 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync