platform.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. . /lib/functions.sh
  2. REQUIRE_IMAGE_METADATA=1
  3. # copied from x86's platform.sh
  4. platform_check_image() {
  5. local diskdev partdev diff
  6. [ "$#" -gt 1 ] && return 1
  7. export_bootdevice && export_partdevice diskdev 0 || {
  8. echo "Unable to determine upgrade device"
  9. return 1
  10. }
  11. get_partitions "/dev/$diskdev" bootdisk
  12. #extract the boot sector from the image
  13. get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
  14. get_partitions /tmp/image.bs image
  15. #compare tables
  16. diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  17. rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
  18. if [ -n "$diff" ]; then
  19. echo "Partition layout has changed. Full image will be written."
  20. ask_bool 0 "Abort" && exit 1
  21. return 0
  22. fi
  23. return 0;
  24. }
  25. platform_do_upgrade() {
  26. local diskdev partdev diff
  27. export_bootdevice && export_partdevice diskdev 0 || {
  28. echo "Unable to determine upgrade device"
  29. return 1
  30. }
  31. sync
  32. if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
  33. get_partitions "/dev/$diskdev" bootdisk
  34. #extract the boot sector from the image
  35. get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  36. get_partitions /tmp/image.bs image
  37. #compare tables
  38. diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  39. else
  40. diff=1
  41. fi
  42. if [ -n "$diff" ]; then
  43. get_image "$@" | dd of="/dev/$diskdev" bs=2M conv=fsync
  44. # Separate removal and addtion is necessary; otherwise, partition 1
  45. # will be missing if it overlaps with the old partition 2
  46. partx -d - "/dev/$diskdev"
  47. partx -a - "/dev/$diskdev"
  48. return 0
  49. fi
  50. #iterate over each partition from the image and write it to the boot disk
  51. while read part start size; do
  52. if export_partdevice partdev $part; then
  53. echo "Writing image to /dev/$partdev..."
  54. get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
  55. else
  56. echo "Unable to find partition $part device, skipped."
  57. fi
  58. done < /tmp/partmap.image
  59. #copy partition uuid
  60. echo "Writing new UUID to /dev/$diskdev..."
  61. get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  62. }
  63. platform_copy_config() {
  64. local partdev
  65. if export_partdevice partdev 1; then
  66. mkdir -p /boot
  67. [ -f /boot/kernel*.img ] || mount -t vfat -o rw,noatime "/dev/$partdev" /boot
  68. cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"
  69. tar -C / -zxvf "$UPGRADE_BACKUP" boot/cmdline.txt boot/config.txt
  70. sync
  71. umount /boot
  72. fi
  73. }