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.

115 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. 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. recreateinitrd=0
  47. mount -n -t tmpfs tmpfs /tmp || echo "Can't mount tmpfs!"
  48. mount -n -t proc proc /proc || echo "Can't mount procfs!"
  49. mount -n -t sysfs sysfs /sys || echo "Can't mount sysfs!"
  50. mount -n -t ramfs ramfs /dev || echo "Can't mount ramfs!"
  51. cp -r /lib/udev/devices/* /dev
  52. echo "" > /proc/sys/kernel/hotplug
  53. /sbin/udevd --daemon
  54. if [ -n "${real_root}" ] ; then
  55. rootfs=${real_root}
  56. else
  57. while read dev mntpoint fstype options fsck1 fsck2 ; do
  58. [ "${mntpoint}" == "/" ] && rootfs=${dev}
  59. [ -n "${rootfs}" ] && break
  60. done < /etc/fstab
  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 /tmp /root/tmp
  82. mount -n --move /proc /root/proc
  83. mount -n --move /sys /root/sys
  84. mount -n --move /dev /root/dev
  85. /sbin/pivot_root . initrd
  86. # re-start real-system udevd, so group/permission settings get honored
  87. killall udevd
  88. /sbin/udevd --daemon
  89. # re-emit events so permissions get corrected and rules which need
  90. # additional programs can be applied (like persistent storage, et alas)
  91. emit_udev_events
  92. if [ "${recreateinitrd}" != "0" ] ; then
  93. echo "Recreating initrd"
  94. chroot . /sbin/mkinitrd < /dev/console > /dev/console 2>&1
  95. fi
  96. exec chroot . $real_init "${@}" < /dev/console > /dev/console 2>&1