spacepaste

  1.  
  2. #!/bin/busybox sh
  3. rescue_shell() {
  4. echo "$@"
  5. echo "Something went wrong. Dropping you to a shell."
  6. /bin/busybox --install -s
  7. exec /bin/sh
  8. }
  9. # allow the use of UUIDs or filesystem lables
  10. uuidlabel_root() {
  11. for cmd in $(/bin/cat /proc/cmdline) ; do
  12. case $cmd in
  13. root=*)
  14. type=$(echo $cmd | /bin/cut -d= -f2)
  15. echo "Mounting rootfs"
  16. if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
  17. uuid=$(echo $cmd | /bin/cut -d= -f3)
  18. /bin/mount -o ro $(findfs "$type"="$uuid") /mnt/root
  19. else
  20. /bin/mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root
  21. fi
  22. ;;
  23. esac
  24. done
  25. }
  26. check_filesystem() {
  27. # most of code coming from /etc/init.d/fsck
  28. local fsck_opts= check_extra= RC_UNAME=$(uname -s)
  29. # FIXME : get_bootparam forcefsck
  30. if [ -e /forcefsck ]; then
  31. fsck_opts="$fsck_opts -f"
  32. check_extra="(check forced)"
  33. fi
  34. echo "Checking local filesystem $check_extra : $1"
  35. if [ "$RC_UNAME" = Linux ]; then
  36. fsck_opts="$fsck_opts -C0 -T"
  37. fi
  38. trap : INT QUIT
  39. # using our own fsck, not the builtin one from busybox
  40. /sbin/fsck -p $fsck_opts $1
  41. ret_val=$?
  42. case $ret_val in
  43. 0) return 0;;
  44. 1) echo "Filesystem repaired"; return 0;;
  45. 2|3) if [ "$RC_UNAME" = Linux ]; then
  46. echo "Filesystem repaired, but reboot needed"
  47. reboot -f
  48. else
  49. rescue_shell "Filesystem still have errors; manual fsck required"
  50. fi;;
  51. 4) if [ "$RC_UNAME" = Linux ]; then
  52. rescue_shell "Fileystem errors left uncorrected, aborting"
  53. else
  54. echo "Filesystem repaired, but reboot needed"
  55. reboot
  56. fi;;
  57. 8) echo "Operational error"; return 0;;
  58. 16) echo "Use or Syntax Error"; return 16;;
  59. 32) echo "fsck interrupted";;
  60. 127) echo "Shared Library Error"; sleep 20; return 0;;
  61. *) echo $ret_val; echo "Some random fsck error - continuing anyway"; sleep 20; return 0;;
  62. esac
  63. # rescue_shell can't find tty so its broken
  64. rescue_shell
  65. }
  66. # start for real here
  67. # temporarily mount proc and sys
  68. /bin/mount -t proc none /proc
  69. /bin/mount -t sysfs none /sys
  70. /bin/mount -t devtmpfs none /dev
  71. /bin/mount -t devpts -o rw,nosuid,noexec,relatime,gid=5,mode=620 devpts /dev/pts
  72. # disable kernel messages from popping onto the screen
  73. ###echo 0 > /proc/sys/kernel/printk
  74. # clear the screen
  75. ###clear
  76. # LVM for everything
  77. # lvm runs as whatever its called as
  78. #ln -s /sbin/lvm.static /sbin/vgchange
  79. # start the vg volume group - /home and everything for portage - need not die here
  80. /sbin/vgchange -ay vg || rescue_shell "vgchange failed"
  81. # get here with logical volumes available
  82. # mounting rootfs on /mnt/root
  83. uuidlabel_root || rescue_shell "Error with uuidlabel_root"
  84. # space separated list of mountpoints that ...
  85. # mountpoints="/usr /var"
  86. # ... we want to find in /etc/fstab ...
  87. #ln -s /mnt/root/etc/fstab /etc/fstab
  88. # ... to check filesystems and mount our devices.
  89. #for m in $mountpoints ; do
  90. #echo $m
  91. # check_filesystem $m
  92. # echo "Mounting $m"
  93. # # mount the device and ...
  94. # mount $m || rescue_shell "Error while mounting $m"
  95. # # ... move the tree to its final location
  96. # mount --move $m "/mnt/root"$m || rescue_shell "Error while moving $m"
  97. #done
  98. echo "All done. Switching to real root."
  99. # clean up. The init process will remount proc sys and dev later
  100. /bin/umount /proc
  101. /bin/umount /sys
  102. /bin/umount /dev/pts
  103. /bin/umount /dev
  104. # switch to the real root and execute init
  105. exec /sbin/switch_root /mnt/root /sbin/init
  106.