1
0

platform.sh 2.1 KB

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