1 REQUIRE_IMAGE_METADATA
=1
3 platform_check_image
() {
4 local diskdev partdev
diff
6 [ "$#" -gt 1 ] && return 1
8 export_bootdevice
&& export_partdevice diskdev
0 ||
{
9 echo "Unable to determine upgrade device"
13 get_partitions
"/dev/$diskdev" bootdisk
15 #extract the boot sector from the image
16 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
2>/dev
/null
18 get_partitions
/tmp
/image.bs image
21 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
23 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
25 if [ -n "$diff" ]; then
26 echo "Partition layout has changed. Full image will be written."
27 ask_bool
0 "Abort" && exit 1
32 platform_copy_config
() {
35 if export_partdevice partdev
1; then
36 mount
-o rw
,noatime
"/dev/$partdev" /mnt
37 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
42 platform_do_upgrade
() {
43 local diskdev partdev
diff
45 export_bootdevice
&& export_partdevice diskdev
0 ||
{
46 echo "Unable to determine upgrade device"
52 if [ "$UPGRADE_OPT_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)"
66 if [ -n "$diff" ]; then
67 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
69 # Separate removal and addtion is necessary; otherwise, partition 1
70 # will be missing if it overlaps with the old partition 2
71 partx
-d - "/dev/$diskdev"
72 partx
-a - "/dev/$diskdev"
78 get_image
"$@" |
dd of
="$diskdev" bs
=512 skip
=1 seek
=1 count
=4097 conv
=fsync
,notrunc
79 #iterate over each partition from the image and write it to the boot disk
80 while read part start size
; do
81 if export_partdevice partdev
$part; then
82 echo "Writing image to /dev/$partdev..."
83 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
85 echo "Unable to find partition $part device, skipped."
87 done < /tmp
/partmap.image
90 echo "Writing new UUID to /dev/$diskdev..."
91 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync