mirror of the now-defunct rocklinux.org
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.

97 lines
2.6 KiB

  1. #!/bin/sh
  2. #
  3. # This boot-script boots a system found in a given LVM
  4. # logical volume.
  5. # In case of trouble it passes control to the original init
  6. # thus giving gettys and running /etc/boot.d/*
  7. # It is included in system.tar.bz2. For usage information
  8. # see below.
  9. #
  10. # Plan:
  11. # -read kernel append line by /proc/1/environ and evaluate
  12. # ROOTLV (should point to /dev/vg00/lvroot00 or kind of)
  13. # -mount ROOTLV to /mnt/root (ro)
  14. # -pivot_root to /mnt/root
  15. # -chroot into /mnt/root and exec init
  16. #
  17. # mini-howto of usage:
  18. #
  19. # -build your rescue target (you get system.tar.bz2 and initrd.img)
  20. # -put system.tar.bz2 in /rescue onto your boot-device-fs
  21. # -optional: put overlay.tar.bz2 in /rescue onto your boot-device-fs
  22. # -get a kernel and arm your favorite boot-loader
  23. # -pass stage2init=/sbin/init-lvm-cycle to the kernel
  24. # -pass ROOTLV=/dev/vgXX/lvYYY to the kernel
  25. # -don't forget to pass initrd.img to your boot loader
  26. # -and boot
  27. #
  28. # you can omit ROOTLV parameter to get the rescue system
  29. #
  30. # see contrib/menu.lst-example
  31. #
  32. # Tobias Hintze <th@rocklinux.org> (c) 2004
  33. #
  34. shopt -s execfail
  35. fail() {
  36. echo "$1"
  37. echo
  38. echo "continuing inside rescue-stage2..."
  39. exec /sbin/init
  40. echo "failed to execute /sbin/init."
  41. echo "all that i can give to you is that shell."
  42. echo
  43. exec sh
  44. }
  45. fail_shell() {
  46. echo "$1"
  47. echo
  48. echo "try to fix the problem and terminate this shell."
  49. echo
  50. sh
  51. }
  52. # some init
  53. export PATH=/sbin:/bin:/usr/sbin:/usr/bin
  54. mount -t proc none /proc
  55. mkdir /mnt/boot /mnt/root
  56. mount --move /old_root/mnt_boot /mnt/boot
  57. umount -n /old_root
  58. # read ROOTLV and additional arguments (e.g. runlevel)
  59. ROOTLV=`cat /proc/1/environ | tr '\0' '\n' | grep -i ^rootlv | cut -d= -f2`
  60. [ -z "$ROOTLV" ] && fail "no ROOTLV specified."
  61. INITARGS=""
  62. RUNLEVEL=`cat /proc/1/environ | tr '\0' '\n' | grep -i ^runlevel | cut -d= -f2`
  63. if [ ! -z "$RUNLEVEL" ] ; then
  64. echo "runlevel specified. passing $RUNLEVEL to init."
  65. INITARGS="$RUNLEVEL"
  66. fi
  67. # scan for and activate volume groups
  68. [ -f /etc/conf/lvm2wrap ] && . /etc/conf/lvm2wrap
  69. vgscan && vgchange -ay
  70. [ -e "$ROOTLV" ] || fail "specified ROOTLV does not exist."
  71. # mount new root
  72. mount -o ro $ROOTLV /mnt/root
  73. cd /mnt/root
  74. # move mounts inside new root
  75. [ -d dev ] || fail_shell "dev/ mountpoint does not exist."
  76. mount --move /dev dev
  77. [ -d mnt/boot ] || fail_shell "mnt/boot/ mountpoint does not exist."
  78. mount --move /mnt/boot mnt/boot
  79. [ -d mnt/oldroot ] || fail_shell "mnt/oldroot/ mountpoint does not exist."
  80. umount /proc
  81. # switch to new root and exec init
  82. mknod dev/initctl p
  83. pivot_root . mnt/oldroot
  84. exec chroot . sh -c "umount /mnt/oldroot ; exec /sbin/init $INITARGS" \
  85. <dev/console >dev/console 2>&1
  86. fail "pivot_root failed..."