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.

114 lines
2.6 KiB

  1. #!/bin/bash
  2. initrd_mount() { # {{{
  3. dev=${1}
  4. mntpoint=${2}
  5. if [ ! -e ${dev} ] ; then
  6. echo " ** ${dev} could not be found!"
  7. echo " ** dumping you into an emergency shell"
  8. exec /bin/bash
  9. return 1;
  10. fi
  11. /sbin/fsck -C -a ${dev}
  12. fsckrc=${?}
  13. if [ ${fsckrc} -eq 8 ] ; then
  14. return 1
  15. fi
  16. if [ $(( ${fsckrc} & ~3 )) != 0 ] ; then
  17. echo " **"
  18. echo " ** Filesystem ${dev} || error=${?} failed (returncode=${fsckrc})."
  19. echo " ** Please repair the broken disk(s) manually."
  20. echo " **"
  21. exec /bin/bash
  22. elif [ $(( ${fsckrc} & 2 )) != 0 ] ; then
  23. echo " **"
  24. echo " ** fsck has requested the system to be rebooted."
  25. echo " ** Running a shell."
  26. echo " **"
  27. echo
  28. exec /bin/bash
  29. fi
  30. mount -n ${dev} ${mntpoint}
  31. return ${?}
  32. } # }}}
  33. emit_udev_events() { # {{{
  34. /sbin/udevtrigger
  35. /sbin/udevsettle
  36. } # }}}
  37. PATH="/sbin:/usr/sbin:/bin/:/usr/bin"
  38. rootfs=""
  39. rootfsmounted=0
  40. recreateinitrd=0
  41. mount -n -t proc proc /proc || echo "Can't mount procfs!"
  42. mount -n -t sysfs sysfs /sys || echo "Can't mount sysfs!"
  43. mount -n -t ramfs ramfs /dev || echo "Can't mount ramfs!"
  44. cp -r /lib/udev/devices/* /dev
  45. echo "" > /proc/sys/kernel/hotplug
  46. /sbin/udevd --daemon
  47. if [ -n "${real_root}" ] ; then
  48. rootfs=${real_root}
  49. else
  50. if [ -f /etc/fstab ] ; then
  51. while read dev mntpoint fstype options fsck1 fsck2 ; do
  52. [ "${mntpoint}" == "/" ] && rootfs=${dev}
  53. [ -n "${rootfs}" ] && break
  54. done < /etc/fstab
  55. else
  56. echo " ** /etc/fstab is missing and no real_root= option was given!"
  57. echo " ** dumping you into an emergency shell"
  58. exec /bin/bash
  59. return 1;
  60. fi
  61. fi
  62. echo "loading kernel modules"
  63. . /etc/conf/kernel
  64. # create nodes for devices already in kernel
  65. emit_udev_events
  66. for x in /etc/conf/* ; do
  67. [ "${x}" == "/etc/conf/kernel" ] && continue
  68. echo "Running ${x} ..."
  69. . ${x}
  70. done
  71. if [ ${rootfsmounted} -eq 0 ] ; then
  72. echo "Mounting rootfs (${rootfs}) on /root"
  73. initrd_mount ${rootfs} /root
  74. rootfsmounted=1
  75. fi
  76. [ -z "$real_init" ] && real_init="/sbin/init"
  77. echo "starting $real_init in /root"
  78. echo "parameters passed to $real_init: ${@}"
  79. cd /root
  80. mkdir -p /root/initrd
  81. mount -n --move /proc /root/proc
  82. mount -n --move /sys /root/sys
  83. mount -n --move /dev /root/dev
  84. /sbin/pivot_root . initrd
  85. # re-start real-system udevd, so group/permission settings get honored
  86. killall udevd
  87. /sbin/udevd --daemon
  88. # re-emit events so permissions get corrected and rules which need
  89. # additional programs can be applied (like persistent storage, et alas)
  90. emit_udev_events
  91. if [ "${recreateinitrd}" != "0" ] ; then
  92. echo "Recreating initrd"
  93. chroot . /sbin/mkinitrd < /dev/console > /dev/console 2>&1
  94. fi
  95. exec chroot . $real_init "${@}" < /dev/console > /dev/console 2>&1