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.

109 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. /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 tmpfs tmpfs /tmp || echo "Can't mount tmpfs!"
  42. mount -n -t proc proc /proc || echo "Can't mount procfs!"
  43. mount -n -t sysfs sysfs /sys || echo "Can't mount sysfs!"
  44. mount -n -t ramfs ramfs /dev || echo "Can't mount ramfs!"
  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. while read dev mntpoint fstype options fsck1 fsck2 ; do
  52. [ "${mntpoint}" == "/" ] && rootfs=${dev}
  53. [ -n "${rootfs}" ] && break
  54. done < /etc/fstab
  55. fi
  56. echo "loading kernel modules"
  57. . /etc/conf/kernel
  58. # create nodes for devices already in kernel
  59. emit_udev_events
  60. for x in /etc/conf/* ; do
  61. [ "${x}" == "/etc/conf/kernel" ] && continue
  62. echo "Running ${x} ..."
  63. . ${x}
  64. done
  65. if [ ${rootfsmounted} -eq 0 ] ; then
  66. echo "Mounting rootfs (${rootfs}) on /root"
  67. initrd_mount ${rootfs} /root
  68. rootfsmounted=1
  69. fi
  70. [ -z "$real_init" ] && real_init="/sbin/init"
  71. echo "starting $real_init in /root"
  72. echo "parameters passed to $real_init: ${@}"
  73. cd /root
  74. mkdir -p /root/initrd
  75. mount -n --move /tmp /root/tmp
  76. mount -n --move /proc /root/proc
  77. mount -n --move /sys /root/sys
  78. mount -n --move /dev /root/dev
  79. /sbin/pivot_root . initrd
  80. # re-start real-system udevd, so group/permission settings get honored
  81. killall udevd
  82. /sbin/udevd --daemon
  83. # re-emit events so permissions get corrected and rules which need
  84. # additional programs can be applied (like persistent storage, et alas)
  85. emit_udev_events
  86. if [ "${recreateinitrd}" != "0" ] ; then
  87. echo "Recreating initrd"
  88. chroot . /sbin/mkinitrd < /dev/console > /dev/console 2>&1
  89. fi
  90. exec chroot . $real_init "${@}" < /dev/console > /dev/console 2>&1