2007-04-05 19:18:42 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 1999-2007 Gentoo Foundation
|
2008-01-11 23:31:10 +08:00
|
|
|
# Copyright 2007-2008 Roy Marples <roy@marples.name>
|
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 23:22:04 +08:00
|
|
|
|
2008-01-04 04:19:32 +08:00
|
|
|
# udev needs these functions still :/
|
2008-01-11 20:13:46 +08:00
|
|
|
try()
|
|
|
|
{
|
2007-12-15 04:09:53 +08:00
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
2008-01-04 04:19:32 +08:00
|
|
|
_rc_get_kv_cache=
|
2008-01-11 20:13:46 +08:00
|
|
|
get_KV()
|
|
|
|
{
|
2008-01-04 04:19:32 +08:00
|
|
|
[ -z "${_rc_get_kv_cache}" ] \
|
|
|
|
&& _rc_get_kv_cache="$(uname -r)"
|
|
|
|
|
|
|
|
echo "$(KV_to_int "${_rc_get_kv_cache}")"
|
|
|
|
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
KV_to_int()
|
|
|
|
{
|
2008-01-04 04:19:32 +08:00
|
|
|
[ -z $1 ] && return 1
|
|
|
|
|
|
|
|
local x=${1%%-*}
|
|
|
|
local KV_MAJOR=${x%%.*}
|
|
|
|
x=${x#*.}
|
|
|
|
local KV_MINOR=${x%%.*}
|
|
|
|
x=${x#*.}
|
|
|
|
local KV_MICRO=${x%%.*}
|
|
|
|
local KV_int=$((${KV_MAJOR} * 65536 + ${KV_MINOR} * 256 + ${KV_MICRO} ))
|
|
|
|
|
|
|
|
# We make version 2.2.0 the minimum version we will handle as
|
|
|
|
# a sanity check ... if its less, we fail ...
|
|
|
|
[ "${KV_int}" -lt 131584 ] && return 1
|
|
|
|
|
|
|
|
echo "${KV_int}"
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
single_user()
|
|
|
|
{
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ "${RC_SYS}" = "VPS" ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
einfo "Halting"
|
|
|
|
halt -f
|
|
|
|
return
|
|
|
|
fi
|
2007-04-17 08:07:09 +08:00
|
|
|
|
2007-04-05 19:18:42 +08:00
|
|
|
sulogin ${CONSOLE}
|
|
|
|
einfo "Unmounting filesystems"
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ -c /dev/null ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
mount -a -o remount,ro 2>/dev/null
|
|
|
|
else
|
|
|
|
mount -a -o remount,ro
|
|
|
|
fi
|
|
|
|
einfo "Rebooting"
|
|
|
|
reboot -f
|
|
|
|
}
|
|
|
|
|
|
|
|
# This basically mounts $svcdir as a ramdisk, but preserving its content
|
|
|
|
# which allows us to run depscan.sh
|
|
|
|
# The tricky part is finding something our kernel supports
|
|
|
|
# tmpfs and ramfs are easy, so force one or the other
|
2008-01-11 20:13:46 +08:00
|
|
|
mount_svcdir()
|
|
|
|
{
|
2007-04-05 19:18:42 +08:00
|
|
|
local fs= fsopts="-o rw,noexec,nodev,nosuid" devdir="none" devtmp="none" x=
|
|
|
|
local svcsize=${svcsize:-1024}
|
|
|
|
|
2007-09-26 18:09:27 +08:00
|
|
|
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
|
2007-04-05 19:18:42 +08:00
|
|
|
fs="tmpfs"
|
|
|
|
fsopts="${fsopts},mode=0755,size=${svcsize}k"
|
2007-09-26 18:09:27 +08:00
|
|
|
elif grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
|
2007-04-05 19:18:42 +08:00
|
|
|
fs="ramfs"
|
2007-04-14 17:27:29 +08:00
|
|
|
# ramfs has no special options
|
2007-04-05 19:18:42 +08:00
|
|
|
elif [ -e /dev/ram0 -a -e /dev/ram1 ] \
|
2007-09-26 18:09:27 +08:00
|
|
|
&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
|
2007-04-05 19:18:42 +08:00
|
|
|
devdir="/dev/ram0"
|
|
|
|
devtmp="/dev/ram1"
|
|
|
|
fs="ext2"
|
2007-09-26 18:09:27 +08:00
|
|
|
for x in ${devdir} ${devtmp}; do
|
2007-12-14 22:19:03 +08:00
|
|
|
dd if=/dev/zero of="${x}" bs=1k count="${rc_svcsize:-1024}"
|
|
|
|
mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${rc_svcsize:-1024}"
|
2007-04-05 19:18:42 +08:00
|
|
|
done
|
|
|
|
else
|
|
|
|
echo
|
2007-11-14 23:22:04 +08:00
|
|
|
eerror "OpenRC requires tmpfs, ramfs or 2 ramdisks + ext2"
|
2007-04-05 19:18:42 +08:00
|
|
|
eerror "compiled into the kernel"
|
|
|
|
echo
|
|
|
|
single_user
|
|
|
|
fi
|
|
|
|
|
|
|
|
local dotmp=false
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ -e "${RC_SVCDIR}"/deptree ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
dotmp=true
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n -t "${fs}" -o rw "${devtmp}" "${RC_LIBDIR}"/tmp
|
2007-08-15 22:49:41 +08:00
|
|
|
cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
|
|
|
|
"${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
2007-09-26 18:09:27 +08:00
|
|
|
|
|
|
|
# If we have no entry in fstab for $svcdir, provide our own
|
|
|
|
if fstabinfo --quiet "${RC_SVCDIR}"; then
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n "${RC_SVCDIR}"
|
2007-09-26 18:09:27 +08:00
|
|
|
else
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}"
|
2007-09-26 18:09:27 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ${dotmp}; then
|
2007-08-15 22:49:41 +08:00
|
|
|
cp -p "${RC_LIBDIR}"/tmp/deptree "${RC_LIBDIR}"/tmp/depconfig \
|
|
|
|
"${RC_LIBDIR}"/tmp/nettree "${RC_SVCDIR}" 2>/dev/null
|
2007-12-14 22:19:03 +08:00
|
|
|
umount -n "${RC_LIBDIR}"/tmp
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
. /etc/init.d/functions.sh
|
|
|
|
. "${RC_LIBDIR}"/sh/rc-functions.sh
|
2007-11-24 06:22:18 +08:00
|
|
|
[ -r /etc/conf.d/rc ] && . /etc/conf.d/rc
|
2007-11-23 20:04:11 +08:00
|
|
|
[ -r /etc/rc.conf ] && . /etc/rc.conf
|
2007-04-05 19:18:42 +08:00
|
|
|
|
2007-11-24 06:22:18 +08:00
|
|
|
# Compat shim for udev
|
|
|
|
rc_coldplug=${rc_coldplug:-${RC_COLDPLUG:-yes}}
|
2007-12-28 01:17:37 +08:00
|
|
|
if yesno "${rc_coldplug}"; then
|
2008-01-23 18:08:43 +08:00
|
|
|
RC_COLDPLUG=yes
|
2007-12-28 01:17:37 +08:00
|
|
|
else
|
2008-01-23 18:08:43 +08:00
|
|
|
RC_COLDPLUG=no
|
2007-12-28 01:17:37 +08:00
|
|
|
fi
|
2007-11-24 06:22:18 +08:00
|
|
|
|
2007-04-05 19:18:42 +08:00
|
|
|
# Set the console loglevel to 1 for a cleaner boot
|
|
|
|
# the logger should anyhow dump the ring-0 buffer at start to the
|
|
|
|
# logs, and that with dmesg can be used to check for problems
|
2007-11-23 20:04:11 +08:00
|
|
|
if [ -n "${dmesg_level}" -a "${RC_SYS}" != "VPS" ]; then
|
|
|
|
dmesg -n "${dmesg_level}"
|
2007-04-26 22:29:15 +08:00
|
|
|
fi
|
2007-04-05 19:18:42 +08:00
|
|
|
|
|
|
|
# By default VServer already has /proc mounted, but OpenVZ does not!
|
2007-05-23 22:12:06 +08:00
|
|
|
# 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
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ -e /proc/uptime ]; then
|
2007-05-23 22:12:06 +08:00
|
|
|
up="$(cat /proc/uptime)"
|
|
|
|
sleep 1
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ "${up}" = "$(cat /proc/uptime)" ]; then
|
2007-05-23 22:12:06 +08:00
|
|
|
eerror "You have cruft in /proc that should be deleted"
|
|
|
|
else
|
|
|
|
einfo "/proc is already mounted, skipping"
|
|
|
|
mountproc=false
|
|
|
|
fi
|
|
|
|
unset up
|
|
|
|
fi
|
|
|
|
|
2007-11-28 23:45:03 +08:00
|
|
|
if ${mountproc}; then
|
2007-04-05 19:18:42 +08:00
|
|
|
procfs="proc"
|
|
|
|
[ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
|
|
|
ebegin "Mounting ${procfs} at /proc"
|
2007-09-26 18:09:27 +08:00
|
|
|
if fstabinfo --quiet /proc; then
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n /proc
|
2007-09-26 18:09:27 +08:00
|
|
|
else
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc
|
2007-09-26 18:09:27 +08:00
|
|
|
fi
|
2007-04-05 19:18:42 +08:00
|
|
|
eend $?
|
|
|
|
fi
|
2007-05-23 22:12:06 +08:00
|
|
|
unset mountproc
|
2007-04-05 19:18:42 +08:00
|
|
|
|
|
|
|
# Read off the kernel commandline to see if there's any special settings
|
|
|
|
# especially check to see if we need to set the CDBOOT environment variable
|
|
|
|
# Note: /proc MUST be mounted
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ -r /sbin/livecd-functions.sh ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
. /sbin/livecd-functions.sh
|
|
|
|
livecd_read_commandline
|
|
|
|
fi
|
|
|
|
|
2008-01-04 04:19:32 +08:00
|
|
|
if [ "${RC_UNAME}" != "GNU/kFreeBSD" -a "${RC_SYS}" != "VPS" ]; then
|
|
|
|
if grep -Eq "[[:space:]]+sysfs$" /proc/filesystems; then
|
|
|
|
if [ -d /sys ]; then
|
|
|
|
if ! mountinfo --quiet /sys; then
|
|
|
|
ebegin "Mounting sysfs at /sys"
|
|
|
|
if fstabinfo --quiet /sys; then
|
|
|
|
mount -n /sys
|
|
|
|
else
|
|
|
|
mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys
|
|
|
|
fi
|
|
|
|
eend $?
|
2007-09-26 18:09:27 +08:00
|
|
|
fi
|
2008-01-04 04:19:32 +08:00
|
|
|
else
|
|
|
|
ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
|
2007-09-18 23:45:15 +08:00
|
|
|
fi
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Try to figure out how the user wants /dev handled
|
|
|
|
# - check $RC_DEVICES from /etc/conf.d/rc
|
|
|
|
# - check boot parameters
|
|
|
|
# - make sure the required binaries exist
|
|
|
|
# - make sure the kernel has support
|
2007-11-23 20:04:11 +08:00
|
|
|
if [ "${rc_devices}" = "static" -o "${RC_SYS}" = "VPS" ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
ebegin "Using existing device nodes in /dev"
|
|
|
|
eend 0
|
2007-09-26 18:09:27 +08:00
|
|
|
elif [ "${RC_UNAME}" = "GNU/kFreeBSD" ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
ebegin "Using kFreeBSD devfs in /dev"
|
|
|
|
eend 0
|
|
|
|
else
|
2007-11-23 20:04:11 +08:00
|
|
|
case ${rc_devices} in
|
2007-04-17 08:07:09 +08:00
|
|
|
devfs) managers="devfs udev mdev";;
|
|
|
|
udev) managers="udev devfs mdev";;
|
|
|
|
mdev) managers="mdev udev devfs";;
|
|
|
|
auto|*) managers="udev devfs mdev";;
|
2007-04-05 19:18:42 +08:00
|
|
|
esac
|
|
|
|
|
2007-09-26 18:09:27 +08:00
|
|
|
for m in ${managers}; do
|
2008-01-31 06:53:40 +08:00
|
|
|
# Check kernel params
|
2007-09-26 18:09:27 +08:00
|
|
|
if get_bootparam "no${m}" || ! has_addon ${m}-start; then
|
2007-04-17 08:07:09 +08:00
|
|
|
continue
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
2007-04-17 08:07:09 +08:00
|
|
|
# Let's see if we can get this puppy rolling
|
|
|
|
start_addon ${m} && break
|
2008-01-31 06:53:40 +08:00
|
|
|
|
|
|
|
# Clean up
|
|
|
|
mountinfo -q /dev && umount -n /dev
|
2007-04-17 08:07:09 +08:00
|
|
|
done
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
|
|
|
|
2007-10-19 14:57:41 +08:00
|
|
|
# Mount required stuff as user may not have then in /etc/fstab
|
2007-10-23 04:24:00 +08:00
|
|
|
for x in "devpts /dev/pts 0755 ,gid=5,mode=0620" "tmpfs /dev/shm 1777 ,nodev"; do
|
2007-10-19 14:57:41 +08:00
|
|
|
set -- ${x}
|
|
|
|
grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue
|
|
|
|
mountinfo -q "$2" && continue
|
|
|
|
|
|
|
|
if [ ! -d "$2" ] && \
|
2007-11-23 20:04:11 +08:00
|
|
|
[ "${m}" = "devfs" -o "${m}" = "udev" ]; then
|
2007-11-28 23:45:03 +08:00
|
|
|
mkdir -m "$3" -p "$2" >/dev/null 2>&1 || \
|
2007-10-19 14:57:41 +08:00
|
|
|
ewarn "Could not create $2!"
|
2007-09-03 11:10:42 +08:00
|
|
|
fi
|
2007-04-05 19:18:42 +08:00
|
|
|
|
2007-10-19 14:57:41 +08:00
|
|
|
if [ -d "$2" ]; then
|
|
|
|
ebegin "Mounting $1 at $2"
|
|
|
|
if fstabinfo --quiet "$2"; then
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n "$2"
|
2007-09-26 18:09:27 +08:00
|
|
|
else
|
2007-12-14 22:19:03 +08:00
|
|
|
mount -n -t "$1" -o noexec,nosuid"$4" none "$2"
|
2007-09-26 18:09:27 +08:00
|
|
|
fi
|
2007-09-03 11:10:42 +08:00
|
|
|
eend $?
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
2007-10-19 14:57:41 +08:00
|
|
|
done
|
2007-04-05 19:18:42 +08:00
|
|
|
|
|
|
|
# If booting off CD, we want to update inittab before setting the runlevel
|
2007-09-26 18:09:27 +08:00
|
|
|
if [ -f /sbin/livecd-functions.sh -a -n "${CDBOOT}" ]; then
|
2007-04-05 19:18:42 +08:00
|
|
|
ebegin "Updating inittab"
|
|
|
|
livecd_fix_inittab
|
|
|
|
eend $?
|
2007-12-14 22:19:03 +08:00
|
|
|
telinit q &>/dev/null
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
. "${RC_LIBDIR}"/sh/init-common-post.sh
|