Idunn is an small system aiming to give an early rescue/install environment with ssh support, making life easier when one doesn't have physical access to machine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.8 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: target/idunn/initramfs/init.sh
  6. # Copyright (C) 2008 - 2009 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. export PATH
  16. LOG=/var/log/init.log
  17. # catch some signals
  18. #
  19. shutoff_handler() {
  20. local x=
  21. # just once!
  22. ln -s / /var/run/init.lock 2> /dev/null || return
  23. # stop services
  24. /etc/rc.d/rc.shutdown -u
  25. case "$1" in
  26. USR1) halt -f ;;
  27. USR2) poweroff -f ;;
  28. *) reboot -f ;;
  29. esac
  30. }
  31. for x in USR1 USR2 TERM INT; do
  32. trap "shutoff_handler $x" $x
  33. done
  34. unset x
  35. # start the world
  36. (
  37. /etc/rc.d/rc.sysinit
  38. /etc/rc.d/rc.trymount
  39. ) 2>&1 | tee -a $LOG
  40. # attach a console
  41. ln -s /etc/console /var/service/
  42. while true; do
  43. sleep 1;
  44. if [ -e /var/run/.idunn-resume ]; then
  45. # switch_root requested
  46. . /etc/conf/idunn
  47. echo "switch_root in progress, you will be disconnected now." | wall
  48. # stop services
  49. /etc/rc.d/rc.shutdown 2>&1 | tee -a $LOG
  50. # terminate the rest
  51. /etc/rc.d/rc.switchroot stop 2>&1 | tee -a $LOG
  52. # and proceed
  53. exec switch_root -c /dev/console "$rootfs" "$init" $initopt 2>&1 >> $LOG
  54. errno=$?
  55. # outch! what are we doing here?
  56. if [ ! -s $LOG ]; then
  57. # the world is gone, time to panic
  58. exit $errno
  59. else
  60. cat <<-EOT >> $LOG
  61. switch_root failed returning $errno
  62. EOT
  63. rm -f /var/run/.idunn-resume
  64. /etc/rc.d/rc.switchroot revive 2>&1 | tee -a $LOG
  65. fi
  66. fi
  67. done