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.

118 lines
2.7 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. /sbin/depmod -ae
  45. cp -r /lib/udev/devices/* /dev
  46. echo "" > /proc/sys/kernel/hotplug
  47. /sbin/udevd --daemon
  48. if [ -n "${real_root}" ] ; then
  49. rootfs=${real_root}
  50. else
  51. if [ -f /etc/fstab ] ; then
  52. while read dev mntpoint fstype options fsck1 fsck2 ; do
  53. [ "${mntpoint}" == "/" ] && rootfs=${dev}
  54. [ -n "${rootfs}" ] && break
  55. done < /etc/fstab
  56. else
  57. echo " ** /etc/fstab is missing and no real_root= option was given!"
  58. echo " ** dumping you into an emergency shell"
  59. exec /bin/bash
  60. return 1;
  61. fi
  62. fi
  63. echo "loading kernel modules"
  64. if [ -f /etc/conf/kernel ]; then
  65. . /etc/conf/kernel
  66. fi
  67. # create nodes for devices already in kernel
  68. emit_udev_events
  69. for x in /etc/conf/* ; do
  70. [ "${x}" == "/etc/conf/kernel" ] && continue
  71. echo "Running ${x} ..."
  72. . ${x}
  73. done
  74. if [ ${rootfsmounted} -eq 0 ] ; then
  75. echo "Mounting rootfs (${rootfs}) on /root"
  76. initrd_mount ${rootfs} /root
  77. rootfsmounted=1
  78. fi
  79. [ -z "$real_init" ] && real_init="/sbin/init"
  80. echo "starting $real_init in /root"
  81. echo "parameters passed to $real_init: ${@}"
  82. cd /root
  83. mkdir -p /root/initrd
  84. mount -n --move /proc /root/proc
  85. mount -n --move /sys /root/sys
  86. mount -n --move /dev /root/dev
  87. /sbin/pivot_root . initrd
  88. # re-start real-system udevd, so group/permission settings get honored
  89. killall udevd
  90. /sbin/udevd --daemon
  91. # re-emit events so permissions get corrected and rules which need
  92. # additional programs can be applied (like persistent storage, et alas)
  93. emit_udev_events
  94. if [ "${recreateinitrd}" != "0" ] ; then
  95. echo "Recreating initrd"
  96. chroot . /sbin/mkinitrd < /dev/console > /dev/console 2>&1
  97. fi
  98. exec chroot . $real_init "${@}" < /dev/console > /dev/console 2>&1