kreboot 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. KERNEL="/mnt/boot/kernel"
  3. KEXEC_ARG=" -l --atags "
  4. PART_A=2
  5. PART_B=3
  6. load_kernel(){
  7. # get the Bootargs and replace the current Partition with
  8. # the one in $1 e.g. replace /dev/mmcblk0p2 with /dev/mmcblk0p3
  9. BOOT_ARGS="$(cat /proc/cmdline | sed s#$CURRENT_PART#$1#g)"
  10. # echo "kexec $KEXEC_ARG --append=\"$BOOT_ARGS\" $KERNEL"
  11. # set -x
  12. # Load the new kernel, unmount the partition and exec the new kernel
  13. kexec -l --atags --append=\""$BOOT_ARGS"\" $KERNEL
  14. umount /mnt
  15. kexec -e
  16. }
  17. # just to be sure
  18. umount /mnt 2> /dev/null
  19. # get the partiton of the current kernel
  20. PART="/dev/$(readlink /dev/root)"
  21. # extract the partition number
  22. C_M_PART_NUM=$(readlink /dev/root | grep -o -e '[[:digit:]]*$')
  23. #$(readlink /dev/root | grep -o '.$')
  24. #Cut off the Partition Number
  25. C_M_PART=$(readlink /dev/root | sed "s/$C_M_PART_NUM\$//")
  26. CURRENT_PART="/dev/${C_M_PART}${C_M_PART_NUM}"
  27. case $C_M_PART_NUM in
  28. "$PART_A")
  29. DEVICE="/dev/${C_M_PART}${PART_B}"
  30. mount -r $DEVICE /mnt
  31. load_kernel $DEVICE
  32. ;;
  33. "$PART_B")
  34. DEVICE="/dev/${C_M_PART}${PART_A}"
  35. mount -r $DEVICE /mnt
  36. load_kernel $DEVICE
  37. ;;
  38. *)
  39. echo "FAILURE"
  40. ;;
  41. esac