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.

110 lines
2.5 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. while read uevent; do
  35. echo 1 > $uevent
  36. done < <( find /sys -name uevent )
  37. udevwait=0
  38. while [ -d /dev/.udev/queue -a $udevwait -lt 300 ] ; do
  39. sleep 1
  40. (( udevwait++ ))
  41. done
  42. } # }}}
  43. PATH="/sbin:/usr/sbin:/bin/:/usr/bin"
  44. rootfs=""
  45. rootfsmounted=0
  46. mount -n -t tmpfs tmpfs /tmp || echo "Can't mount tmpfs!"
  47. mount -n -t proc proc /proc || echo "Can't mount procfs!"
  48. mount -n -t sysfs sysfs /sys || echo "Can't mount sysfs!"
  49. mount -n -t ramfs ramfs /dev || echo "Can't mount ramfs!"
  50. cp -r /lib/udev/devices/* /dev
  51. echo "" > /proc/sys/kernel/hotplug
  52. /sbin/udevd --daemon
  53. if [ -n "${real_root}" ] ; then
  54. rootfs=${real_root}
  55. else
  56. while read dev mntpoint fstype options fsck1 fsck2 ; do
  57. [ "${mntpoint}" == "/" ] && rootfs=${dev}
  58. [ -n "${rootfs}" ] && break
  59. done < /etc/fstab
  60. fi
  61. echo "loading kernel modules"
  62. . /etc/conf/kernel
  63. # create nodes for devices already in kernel
  64. emit_udev_events
  65. for x in /etc/conf/* ; do
  66. [ "${x}" == "/etc/conf/kernel" ] && continue
  67. echo "Running ${x} ..."
  68. . ${x}
  69. done
  70. if [ ${rootfsmounted} -eq 0 ] ; then
  71. echo "Mounting rootfs (${rootfs}) on /root"
  72. initrd_mount ${rootfs} /root
  73. rootfsmounted=1
  74. fi
  75. [ -z "$real_init" ] && real_init="/sbin/init"
  76. echo "starting $real_init in /root"
  77. echo "parameters passed to $real_init: ${@}"
  78. cd /root
  79. mkdir -p /root/initrd
  80. mount -n --move /tmp /root/tmp
  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. exec chroot . $real_init "${@}" < /dev/console > /dev/console 2>&1