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 v
"Invalid image type"
15 export_bootdevice
&& export_partdevice diskdev
0 ||
{
16 v
"Unable to determine upgrade device"
20 get_partitions
"/dev/$diskdev" bootdisk
22 v
"Extract boot sector from the image"
23 get_image_dd
"$1" of
=/tmp
/image.bs count
=63 bs
=512b
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 v
"Partition layout has changed. Full image will be written."
34 ask_bool
0 "Abort" && exit 1
39 platform_copy_config
() {
40 local partdev parttype
=ext4
42 if export_partdevice partdev
1; then
43 part_magic_fat
"/dev/$partdev" && parttype
=vfat
44 mount
-t $parttype -o rw
,noatime
"/dev/$partdev" /mnt
45 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
50 platform_do_bootloader_upgrade
() {
51 local bootpart parttable
=msdos
54 if export_partdevice bootpart
1; then
56 mount
-o rw
,noatime
"/dev/$bootpart" /tmp
/boot
57 echo "(hd0) /dev/$diskdev" > /tmp
/device.map
58 part_magic_efi
"/dev/$diskdev" && parttable
=gpt
60 v
"Upgrading bootloader on /dev/$diskdev..."
62 -m "/tmp/device.map" \
63 -d "/tmp/boot/boot/grub" \
64 -r "hd0,${parttable}1" \
66 && touch /tmp
/boot
/boot
/grub
/upgraded
68 case "$(board_name)" in
70 # If the MX100 is booted UEFI AND the SATA HDD exists, we need to change
71 # grub's root= to hd1 for it to boot correctly, otherwise we can keep it hd0.
72 if [ -d /sys
/firmware
/efi
] && [ "$(ls -a /dev/sd[a-z] | wc -w)" -gt 1 ] ; then
73 sed -i "s|hd0,${parttable}1|hd1,${parttable}1|g" /tmp
/boot
/boot
/grub
/grub.cfg
82 platform_do_upgrade
() {
83 local diskdev partdev
diff
85 export_bootdevice
&& export_partdevice diskdev
0 ||
{
86 v
"Unable to determine upgrade device"
92 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
93 get_partitions
"/dev/$diskdev" bootdisk
95 v
"Extract boot sector from the image"
96 get_image_dd
"$1" of
=/tmp
/image.bs count
=63 bs
=512b
98 get_partitions
/tmp
/image.bs image
101 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
106 if [ -n "$diff" ]; then
107 get_image_dd
"$1" of
="/dev/$diskdev" bs
=4096 conv
=fsync
109 # Separate removal and addtion is necessary; otherwise, partition 1
110 # will be missing if it overlaps with the old partition 2
111 partx
-d - "/dev/$diskdev"
112 partx
-a - "/dev/$diskdev"
117 #iterate over each partition from the image and write it to the boot disk
118 while read part start size
; do
119 if export_partdevice partdev
$part; then
120 v
"Writing image to /dev/$partdev..."
121 get_image_dd
"$1" of
="/dev/$partdev" ibs
=512 obs
=1M skip
="$start" count
="$size" conv
=fsync
123 v
"Unable to find partition $part device, skipped."
125 done < /tmp
/partmap.image
127 v
"Writing new UUID to /dev/$diskdev..."
128 get_image_dd
"$1" of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
130 platform_do_bootloader_upgrade
"$diskdev"
132 part_magic_efi
"/dev/$diskdev" ||
return 0
134 if export_partdevice partdev
1; then
135 part_magic_fat
"/dev/$partdev" && parttype
=vfat
136 mount
-t $parttype -o rw
,noatime
"/dev/$partdev" /mnt
137 set -- $
(dd if="/dev/$diskdev" bs
=1 skip
=1168 count
=16 2>/dev
/null |
hexdump -v -e '8/1 "%02x "" "2/1 "%02x""-"6/1 "%02x"')
138 sed -i "s/\(PARTUUID=\)[a-f0-9-]\+/\1$4$3$2$1-$6$5-$8$7-$9/ig" /mnt
/boot
/grub
/grub.cfg