2008-02-28 04:29:32 +08:00
|
|
|
#!@SHELL@
|
2009-05-01 22:11:40 +08:00
|
|
|
# Copyright (c) 1999-2007 Gentoo Foundation
|
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2011-06-30 07:46:31 +08:00
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 23:22:04 +08:00
|
|
|
|
2008-11-03 23:31:01 +08:00
|
|
|
# This basically mounts $RC_SVCDIR as a ramdisk.
|
2007-04-05 19:18:42 +08:00
|
|
|
# The tricky part is finding something our kernel supports
|
2008-02-04 01:21:11 +08:00
|
|
|
# tmpfs and ramfs are easy, so force one or the other.
|
2010-12-04 13:49:34 +08:00
|
|
|
svcdir_restorecon()
|
|
|
|
{
|
|
|
|
local rc=0
|
|
|
|
if [ -x /usr/sbin/selinuxenabled -a -c /selinux/null ] &&
|
|
|
|
selinuxenabled; then
|
|
|
|
restorecon $RC_SVCDIR
|
|
|
|
rc=$?
|
|
|
|
fi
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
mount_svcdir()
|
|
|
|
{
|
2009-11-20 08:03:49 +08:00
|
|
|
# mount from fstab if we can
|
|
|
|
fstabinfo --mount "$RC_SVCDIR" && return 0
|
|
|
|
|
2008-10-10 16:37:21 +08:00
|
|
|
local fs= fsopts="-o rw,noexec,nodev,nosuid"
|
2008-01-31 17:48:58 +08:00
|
|
|
local svcsize=${rc_svcsize:-1024}
|
2007-04-05 19:18:42 +08:00
|
|
|
|
2009-11-20 08:03:49 +08:00
|
|
|
# Some buggy kernels report tmpfs even when not present :(
|
2007-09-26 18:09:27 +08:00
|
|
|
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
|
2010-12-04 13:49:34 +08:00
|
|
|
local tmpfsopts="${fsopts},mode=755,size=${svcsize}k"
|
|
|
|
mount -n -t tmpfs $tmpfsopts rc-svcdir "$RC_SVCDIR"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
svcdir_restorecon
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
fi
|
2009-11-20 08:03:49 +08:00
|
|
|
fi
|
2011-01-17 17:49:07 +08:00
|
|
|
|
2009-11-20 08:03:49 +08:00
|
|
|
if 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
|
2008-11-03 23:31:01 +08:00
|
|
|
elif [ -e /dev/ram0 ] \
|
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"
|
|
|
|
fs="ext2"
|
2009-04-27 05:13:26 +08:00
|
|
|
dd if=/dev/zero of="$devdir" bs=1k count="$svcsize"
|
|
|
|
mkfs -t "$fs" -i 1024 -vm0 "$devdir" "$svcsize"
|
2007-04-05 19:18:42 +08:00
|
|
|
else
|
|
|
|
echo
|
2008-11-03 23:31:01 +08:00
|
|
|
eerror "OpenRC requires tmpfs, ramfs or a ramdisk + ext2"
|
2007-04-05 19:18:42 +08:00
|
|
|
eerror "compiled into the kernel"
|
|
|
|
echo
|
2008-01-31 17:48:58 +08:00
|
|
|
return 1
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|
|
|
|
|
2009-11-20 08:03:49 +08:00
|
|
|
mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR"
|
2010-12-04 13:49:34 +08:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
svcdir_restorecon
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
fi
|
2007-04-05 19:18:42 +08:00
|
|
|
}
|
|
|
|
|
2009-05-24 03:38:12 +08:00
|
|
|
. "$RC_LIBEXECDIR"/sh/functions.sh
|
2007-11-23 20:04:11 +08:00
|
|
|
[ -r /etc/rc.conf ] && . /etc/rc.conf
|
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
|
2011-03-25 07:27:35 +08:00
|
|
|
# /proc actually works or not. We do this by comparing two reads of
|
|
|
|
# /proc/self/environ for which we have set the variable VAR to two
|
|
|
|
# different values. If the comparison comes back equal, we know that
|
|
|
|
# /proc is not working.
|
2007-05-23 22:12:06 +08:00
|
|
|
mountproc=true
|
2011-03-25 07:27:35 +08:00
|
|
|
f=/proc/self/environ
|
2011-01-18 09:26:34 +08:00
|
|
|
if [ -e $f ]; then
|
2011-03-25 07:27:35 +08:00
|
|
|
if [ "$(VAR=a cat $f)" = "$(VAR=b cat $f)" ]; 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
|
|
|
|
fi
|
2011-03-25 07:27:35 +08:00
|
|
|
unset f
|
2007-05-23 22:12:06 +08:00
|
|
|
|
2009-04-27 05:13:26 +08:00
|
|
|
if $mountproc; then
|
2007-04-05 19:18:42 +08:00
|
|
|
procfs="proc"
|
2009-04-27 05:13:26 +08:00
|
|
|
[ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
2008-03-11 21:55:39 +08:00
|
|
|
ebegin "Mounting /proc"
|
2008-03-11 21:39:20 +08:00
|
|
|
if ! fstabinfo --mount /proc; then
|
2009-04-27 05:13:26 +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
|
|
|
|
|
2011-09-12 23:46:51 +08:00
|
|
|
# Mount tmpfs on /run when directory exists.
|
|
|
|
# /run is a new directory for storing volatile runtime data.
|
|
|
|
# Read more about /run at https://lwn.net/Articles/436012
|
|
|
|
if [ -d /run ]; then
|
|
|
|
if mountinfo -q /run; then
|
|
|
|
einfo "/run is already mounted, skipping"
|
|
|
|
else
|
|
|
|
ebegin "Mounting /run"
|
|
|
|
if ! fstabinfo --mount /run; then
|
|
|
|
mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run
|
|
|
|
fi
|
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
checkpath -d -m 0775 -o root:uucp /run/lock
|
|
|
|
elif [ -e /run ]; then
|
|
|
|
einfo "Unable to mount /run since it is not a directory"
|
|
|
|
fi
|
|
|
|
|
2010-02-26 17:34:43 +08:00
|
|
|
# Try to mount xenfs as early as possible, otherwise rc_sys() will always
|
|
|
|
# return RC_SYS_XENU and will think that we are in a domU while it's not.
|
|
|
|
if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
|
|
|
|
ebegin "Mounting xenfs"
|
|
|
|
if ! fstabinfo --mount /proc/xen; then
|
|
|
|
mount -n -t xenfs xenfs /proc/xen -o nosuid,nodev,noexec
|
|
|
|
fi
|
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
|
2009-05-24 03:38:12 +08:00
|
|
|
. "$RC_LIBEXECDIR"/sh/init-common-post.sh
|