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 $(cat /proc/cmdline) ; do
  12. case $cmd in
  13. root=*)
  14. type=$(echo $cmd | cut -d= -f2)
  15. echo "Mounting rootfs"
  16. if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
  17. uuid=$(echo $cmd | cut -d= -f3)
  18. mount -o ro $(findfs "$type"="$uuid") /mnt/root
  19. else
  20. 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. mount -t proc none /proc
  69. mount -t sysfs none /sys
  70. mount -t devtmpfs none /dev
  71. # disable kernel messages from popping onto the screen
  72. ###echo 0 > /proc/sys/kernel/printk
  73. # clear the screen
  74. ###clear
  75. # /boot
  76. /sbin/mdadm --assemble /dev/md0 --uuid=bc38405f:83693026:825019f1:97c4f6e3
  77. # old d678d02e-28ab-84e0-c44c-77eb7ee19756
  78. # new UUID : bc38405f:83693026:825019f1:97c4f6e3 (local to host NeddySeagoon_Static)
  79. # don't care if /boot fails to assemble
  80. # / the host LVM
  81. /sbin/mdadm --assemble /dev/md1 --uuid=62120388:98bfb6f0:b65341f6:6b93d69f || rescue_shell
  82. # old ad5fe0cb-775d-38b4-7169-e221fc96089f
  83. # new Array UUID : 62120388:98bfb6f0:b65341f6:6b93d69f
  84. # if root won't assemble, we are stuck
  85. # the KVM LVM
  86. /sbin/mdadm --assemble /dev/md2 --uuid=75d75d6a:9947df3c:5e50eaf5:5f8d22b7
  87. #old 52be4797:edab2349:eb21497e:52035eaa
  88. # new Array UUID : 75d75d6a:9947df3c:5e50eaf5:5f8d22b7
  89. # and if the LVM space won't assemble there is no /usr or /var so we are really in a mess
  90. # TODO could auto cope with degraded raid operation
  91. # the media RAID
  92. /sbin/mdadm --assemble /dev/md3 --uuid=5e9cefa1:b8bce388:d442afdb:7e9f15bf
  93. # old 52be4797:edab2349:eb21497e:52035eaa
  94. # new Array UUID : 5e9cefa1:b8bce388:d442afdb:7e9f15bf
  95. # lvm runs as whatever its called as
  96. ln -s /sbin/lvm /sbin/vgchange
  97. # start the volume groups - we only have host and vm volume groups
  98. /sbin/vgchange -ay host || rescue_shell
  99. # we don't get any KVMs if vm doesnt start but its not fatal to booting the host
  100. /sbin/vgchange -ay guests
  101. # if host failed we have no /usr or /var
  102. # get here with raid sets assembled and logical volumes available
  103. # mounting rootfs on /mnt/root
  104. uuidlabel_root || rescue_shell "Error with uuidlabel_root"
  105. # space separated list of mountpoints that ...
  106. mountpoints="/usr /var"
  107. # ... we want to find in /etc/fstab ...
  108. ln -s /mnt/root/etc/fstab /etc/fstab
  109. # ... to check filesystems and mount our devices.
  110. for m in $mountpoints ; do
  111. #echo $m
  112. check_filesystem $m
  113. echo "Mounting $m"
  114. # mount the device and ...
  115. mount $m || rescue_shell "Error while mounting $m"
  116. # ... move the tree to its final location
  117. mount --move $m "/mnt/root"$m || rescue_shell "Error while moving $m"
  118. done
  119. echo "All done. Switching to real root."
  120. # clean up. The init process will remount proc sys and dev later
  121. umount /proc
  122. umount /sys
  123. umount /dev
  124. # switch to the real root and execute init
  125. exec switch_root /mnt/root /sbin/init
  126.