2008-02-28 01:59:32 +05:30
|
|
|
#!@SHELL@
|
2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 1999-2007 Gentoo Foundation
|
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-11-03 21:01:01 +05:30
|
|
|
# This basically mounts $RC_SVCDIR as a ramdisk.
|
2007-04-05 16:48:42 +05:30
|
|
|
# The tricky part is finding something our kernel supports
|
2008-02-03 22:51:11 +05:30
|
|
|
# tmpfs and ramfs are easy, so force one or the other.
|
2010-12-04 11:19:34 +05:30
|
|
|
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 17:43:46 +05:30
|
|
|
mount_svcdir()
|
|
|
|
{
|
2009-11-20 05:33:49 +05:30
|
|
|
# mount from fstab if we can
|
|
|
|
fstabinfo --mount "$RC_SVCDIR" && return 0
|
|
|
|
|
2008-10-10 14:07:21 +05:30
|
|
|
local fs= fsopts="-o rw,noexec,nodev,nosuid"
|
2008-01-31 15:18:58 +05:30
|
|
|
local svcsize=${rc_svcsize:-1024}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2009-11-20 05:33:49 +05:30
|
|
|
# Some buggy kernels report tmpfs even when not present :(
|
2007-09-26 15:39:27 +05:30
|
|
|
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
|
2010-12-04 11:19:34 +05:30
|
|
|
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 05:33:49 +05:30
|
|
|
fi
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2009-11-20 05:33:49 +05:30
|
|
|
if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
|
2007-04-05 16:48:42 +05:30
|
|
|
fs="ramfs"
|
2007-04-14 14:57:29 +05:30
|
|
|
# ramfs has no special options
|
2008-11-03 21:01:01 +05:30
|
|
|
elif [ -e /dev/ram0 ] \
|
2007-09-26 15:39:27 +05:30
|
|
|
&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
|
2007-04-05 16:48:42 +05:30
|
|
|
devdir="/dev/ram0"
|
|
|
|
fs="ext2"
|
2009-04-27 02:43:26 +05:30
|
|
|
dd if=/dev/zero of="$devdir" bs=1k count="$svcsize"
|
|
|
|
mkfs -t "$fs" -i 1024 -vm0 "$devdir" "$svcsize"
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
|
|
|
echo
|
2008-11-03 21:01:01 +05:30
|
|
|
eerror "OpenRC requires tmpfs, ramfs or a ramdisk + ext2"
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "compiled into the kernel"
|
|
|
|
echo
|
2008-01-31 15:18:58 +05:30
|
|
|
return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
2009-11-20 05:33:49 +05:30
|
|
|
mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR"
|
2010-12-04 11:19:34 +05:30
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
svcdir_restorecon
|
|
|
|
[ $? -eq 0 ] && return 0
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2009-05-24 01:08:12 +05:30
|
|
|
. "$RC_LIBEXECDIR"/sh/functions.sh
|
2007-11-23 17:34:11 +05:30
|
|
|
[ -r /etc/rc.conf ] && . /etc/rc.conf
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# By default VServer already has /proc mounted, but OpenVZ does not!
|
2007-05-23 19:42:06 +05:30
|
|
|
# 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 04:57:35 +05:30
|
|
|
# /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 19:42:06 +05:30
|
|
|
mountproc=true
|
2011-03-25 04:57:35 +05:30
|
|
|
f=/proc/self/environ
|
2011-01-18 06:56:34 +05:30
|
|
|
if [ -e $f ]; then
|
2011-03-25 04:57:35 +05:30
|
|
|
if [ "$(VAR=a cat $f)" = "$(VAR=b cat $f)" ]; then
|
2007-05-23 19:42:06 +05:30
|
|
|
eerror "You have cruft in /proc that should be deleted"
|
|
|
|
else
|
|
|
|
einfo "/proc is already mounted, skipping"
|
|
|
|
mountproc=false
|
|
|
|
fi
|
|
|
|
fi
|
2011-03-25 04:57:35 +05:30
|
|
|
unset f
|
2007-05-23 19:42:06 +05:30
|
|
|
|
2009-04-27 02:43:26 +05:30
|
|
|
if $mountproc; then
|
2007-04-05 16:48:42 +05:30
|
|
|
procfs="proc"
|
2009-04-27 02:43:26 +05:30
|
|
|
[ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
2008-03-11 19:25:39 +05:30
|
|
|
ebegin "Mounting /proc"
|
2008-03-11 19:09:20 +05:30
|
|
|
if ! fstabinfo --mount /proc; then
|
2009-04-27 02:43:26 +05:30
|
|
|
mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc
|
2007-09-26 15:39:27 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
|
2011-09-12 21:16:51 +05:30
|
|
|
# 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 15:04:43 +05:30
|
|
|
# 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 01:08:12 +05:30
|
|
|
. "$RC_LIBEXECDIR"/sh/init-common-post.sh
|