1 platform_export_bootpart
() {
2 local cmdline uuid disk
4 if read cmdline
< /proc
/cmdline
; then
7 disk
="${cmdline##*block2mtd=}"
11 disk
="${cmdline##*root=}"
17 PARTUUID
=[a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
]-02)
18 uuid
="${disk#PARTUUID=}"
20 for disk
in /dev
/[hsv
]d
[a-z
] /dev
/xvd
[a-z
]; do
21 set -- $
(dd if=$disk bs
=1 skip
=440 count
=4 2>/dev
/null |
hexdump -v -e '4/1 "%02x "')
22 if [ "$4$3$2$1" = "$uuid" ]; then
23 export BOOTPART
="${disk}1"
29 export BOOTPART
="${disk%[0-9]}1"
38 platform_check_image
() {
39 [ "$#" -gt 1 ] && return 1
41 case "$(get_magic_word "$1")" in
44 echo "Invalid image type"
50 platform_copy_config
() {
51 if [ -b "$BOOTPART" ]; then
52 mount
-t ext4
-o rw
,noatime
"$BOOTPART" /mnt
53 cp -af "$CONF_TAR" /mnt
/
58 get_partitions
() { # <device> <filename>
62 if [ -b "$disk" -o -f "$disk" ]; then
63 echo "Reading partition table from $filename..."
65 local magic
="$(hexdump -v -n 2 -s 0x1FE -e '1/2 "0x
%04X
"' "$disk")"
66 if [ "$magic" != 0xAA55 ]; then
67 echo "Invalid partition table on $disk"
71 rm -f "/tmp/partmap.$filename"
74 for part
in 1 2 3 4; do
75 set -- $
(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk")
77 local type="$(($1 % 256))"
81 [ $type -gt 0 ] ||
continue
83 printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename"
88 platform_do_upgrade
() {
89 platform_export_bootpart
90 disk
="${BOOTPART%[0-9]}"
92 if [ -b "$disk" ]; then
94 if [ "$SAVE_PARTITIONS" = "1" ]; then
95 get_partitions
"$disk" bootdisk
99 if [ -f "/sys/block/${disk##*/}/queue/physical_block_size" ]; then
100 ibs
="$(cat "/sys
/block
/${disk##*/}/queue
/physical_block_size
")"
105 #extract the boot sector from the image
106 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
108 get_partitions
/tmp
/image.bs image
111 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
112 if [ -n "$diff" ]; then
113 echo "Partition layout is changed. Full image will be written."
114 ask_bool
0 "Abort" && exit
116 get_image
"$@" |
dd of
="$disk" bs
=4096 conv
=fsync
120 #iterate over each partition from the image and write it to the boot disk
121 while read part start size
; do
122 echo "Writing image to $disk$part..."
123 get_image
"$@" |
dd of
="$disk$part" ibs
="$ibs" obs
=1M skip
="$start" count
="$size" conv
=fsync
124 done < /tmp
/partmap.image
127 echo "Writing new UUID to $disk$part..."
128 get_image
"$@" |
dd of
="$disk" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
130 get_image
"$@" |
dd of
="$disk" bs
=4096 conv
=fsync