1 RAMFS_COPY_BIN
='grub-bios-setup'
3 platform_check_image
() {
4 local diskdev partdev
diff
5 [ "$#" -gt 1 ] && return 1
7 case "$(get_magic_word "$1")" in
10 echo "Invalid image type"
15 export_bootdevice
&& export_partdevice diskdev
0 ||
{
16 echo "Unable to determine upgrade device"
20 get_partitions
"/dev/$diskdev" bootdisk
22 #extract the boot sector from the image
23 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
2>/dev
/null
25 get_partitions
/tmp
/image.bs image
28 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
30 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
32 if [ -n "$diff" ]; then
33 echo "Partition layout has changed. Full image will be written."
34 ask_bool
0 "Abort" && exit 1
39 platform_copy_config
() {
42 if export_partdevice partdev
1; then
43 mount
-t ext4
-o rw
,noatime
"/dev/$partdev" /mnt
44 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
49 platform_do_bootloader_upgrade
() {
53 if export_partdevice bootpart
1; then
55 mount
-o rw
,noatime
"/dev/$bootpart" /tmp
/boot
56 echo "(hd0) /dev/$diskdev" > /tmp
/device.map
58 echo "Upgrading bootloader on /dev/$diskdev..."
60 -m "/tmp/device.map" \
61 -d "/tmp/boot/boot/grub" \
69 platform_do_upgrade
() {
70 local diskdev partdev
diff
72 export_bootdevice
&& export_partdevice diskdev
0 ||
{
73 echo "Unable to determine upgrade device"
79 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
80 get_partitions
"/dev/$diskdev" bootdisk
82 #extract the boot sector from the image
83 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
85 get_partitions
/tmp
/image.bs image
88 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
93 if [ -n "$diff" ]; then
94 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
96 # Separate removal and addtion is necessary; otherwise, partition 1
97 # will be missing if it overlaps with the old partition 2
98 partx
-d - "/dev/$diskdev"
99 partx
-a - "/dev/$diskdev"
104 #iterate over each partition from the image and write it to the boot disk
105 while read part start size
; do
106 if export_partdevice partdev
$part; then
107 echo "Writing image to /dev/$partdev..."
108 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
110 echo "Unable to find partition $part device, skipped."
112 done < /tmp
/partmap.image
115 echo "Writing new UUID to /dev/$diskdev..."
116 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
118 platform_do_bootloader_upgrade
"$diskdev"