openrc/sh/init.sh.Linux.in
Roy Marples d6da8e8c48 sysinit is now a real runlevel that handles things like udev, dmesg and
mounting various bits in /dev and /sys.
init.sh JUST mounts /lib/rc/init.d (and /proc for Linux systems)
To make development of this easier we now return an empty RC_STRINGLIST
instead of a NULL for empty things.

If you don't have a udev init script installed, don't reboot your box OR
roll back to an older OpenRC version.
2008-10-10 08:37:21 +00:00

90 lines
2.7 KiB
Plaintext

#!@SHELL@
# Copyright 1999-2007 Gentoo Foundation
# Copyright 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
# This basically mounts $RC_SVCDIR as a ramdisk, but preserving its content
# which allows us to store service state and generate dependencies if needed.
# The tricky part is finding something our kernel supports
# tmpfs and ramfs are easy, so force one or the other.
mount_svcdir()
{
local fs= fsopts="-o rw,noexec,nodev,nosuid"
local devdir="rc-svcdir" devtmp="none" x=
local svcsize=${rc_svcsize:-1024}
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
fs="tmpfs"
fsopts="${fsopts},mode=0755,size=${svcsize}k"
elif grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
fs="ramfs"
# ramfs has no special options
elif [ -e /dev/ram0 -a -e /dev/ram1 ] \
&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
devdir="/dev/ram0"
devtmp="/dev/ram1"
fs="ext2"
for x in ${devdir} ${devtmp}; do
dd if=/dev/zero of="${x}" bs=1k count="${svcsize}"
mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${svcsize}"
done
else
echo
eerror "OpenRC requires tmpfs, ramfs or 2 ramdisks + ext2"
eerror "compiled into the kernel"
echo
return 1
fi
local dotmp=false
if [ -e "${RC_SVCDIR}"/deptree ]; then
dotmp=true
mount -n -t "${fs}" -o rw "${devtmp}" "${RC_LIBDIR}"/tmp
cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
"${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
fi
# If we have no entry in fstab for $RC_SVCDIR, provide our own
if ! fstabinfo --mount "${RC_SVCDIR}"; then
mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}"
fi
if ${dotmp}; then
cp -p "${RC_LIBDIR}"/tmp/deptree "${RC_LIBDIR}"/tmp/depconfig \
"${RC_LIBDIR}"/tmp/nettree "${RC_SVCDIR}" 2>/dev/null
umount -n "${RC_LIBDIR}"/tmp
fi
}
. /etc/init.d/functions.sh
[ -r /etc/rc.conf ] && . /etc/rc.conf
# By default VServer already has /proc mounted, but OpenVZ does not!
# However, some of our users have an old proc image in /proc
# NFC how they managed that, but the end result means we have to test if
# /proc actually works or not. We to this by comparing uptime to one a second
# ago
mountproc=true
if [ -e /proc/uptime ]; then
up="$(cat /proc/uptime)"
sleep 1
if [ "${up}" = "$(cat /proc/uptime)" ]; then
eerror "You have cruft in /proc that should be deleted"
else
einfo "/proc is already mounted, skipping"
mountproc=false
fi
fi
if ${mountproc}; then
procfs="proc"
[ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
ebegin "Mounting /proc"
if ! fstabinfo --mount /proc; then
mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc
fi
eend $?
fi
. "${RC_LIBDIR}"/sh/init-common-post.sh