2013-12-22 02:21:11 +05:30
|
|
|
#!@SBINDIR@/openrc-run
|
2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2008-10-10 14:07:21 +05:30
|
|
|
|
2013-12-02 04:01:02 +05:30
|
|
|
description="Set up the /dev directory"
|
2008-10-10 14:07:21 +05:30
|
|
|
|
2013-12-02 04:01:02 +05:30
|
|
|
depend()
|
|
|
|
{
|
|
|
|
provide dev-mount
|
2012-10-20 07:23:46 +05:30
|
|
|
before dev
|
2015-04-29 06:33:49 +05:30
|
|
|
keyword -prefix -systemd-nspawn -vserver -lxc
|
2008-10-10 14:07:21 +05:30
|
|
|
}
|
|
|
|
|
2013-12-02 04:01:02 +05:30
|
|
|
mount_dev()
|
|
|
|
{
|
|
|
|
local action=--mount devfstype msg=Mounting
|
|
|
|
# Some devices require exec, Bug #92921
|
|
|
|
local mountopts="exec,nosuid,mode=0755"
|
2014-08-09 01:19:00 +05:30
|
|
|
if yesno ${skip_mount_dev:-no} ; then
|
|
|
|
einfo "/dev will not be mounted due to user request"
|
2013-12-02 04:01:02 +05:30
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if mountinfo -q /dev; then
|
|
|
|
action=--remount
|
|
|
|
mountopts="remount,$mountopts"
|
|
|
|
msg=Remounting
|
|
|
|
fi
|
|
|
|
if fstabinfo -q /dev; then
|
|
|
|
ebegin "$msg /dev according to @SYSCONFDIR@/fstab"
|
|
|
|
fstabinfo -q $action /dev
|
|
|
|
eend $?
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if grep -q devtmpfs /proc/filesystems; then
|
|
|
|
devfstype=devtmpfs
|
|
|
|
mountopts="$mountopts,size=10M"
|
|
|
|
elif grep -q tmpfs /proc/filesystems; then
|
|
|
|
devfstype=tmpfs
|
|
|
|
mountopts="$mountopts,size=10M"
|
|
|
|
fi
|
|
|
|
if [ -n "$devfstype" ]; then
|
|
|
|
ebegin "$msg $devfstype on /dev"
|
|
|
|
mount -n -t $devfstype -o $mountopts dev /dev
|
|
|
|
eend $?
|
|
|
|
else
|
2014-08-09 01:19:00 +05:30
|
|
|
ewarn "This kernel does not have devtmpfs or tmpfs support, and there"
|
|
|
|
ewarn "is no entry for /dev in fstab."
|
|
|
|
ewarn "This means /dev will not be mounted."
|
|
|
|
ewarn "To avoid this message, set CONFIG_DEVTMPFS or CONFIG_TMPFS to y"
|
|
|
|
ewarn "in your kernel configuration or see @SYSCONFDIR@/conf.d/devfs"
|
2013-12-02 04:01:02 +05:30
|
|
|
fi
|
2014-08-09 01:19:00 +05:30
|
|
|
return 0
|
2013-12-02 04:01:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
seed_dev()
|
|
|
|
{
|
|
|
|
# Seed /dev with some things that we know we need
|
|
|
|
|
|
|
|
# creating /dev/console, /dev/tty and /dev/tty1 to be able to write
|
|
|
|
# to $CONSOLE with/without bootsplash before udevd creates it
|
|
|
|
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
|
|
|
|
[ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
|
|
|
|
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
|
|
|
|
|
|
|
|
# udevd will dup its stdin/stdout/stderr to /dev/null
|
|
|
|
# and we do not want a file which gets buffered in ram
|
|
|
|
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
|
|
|
|
|
|
|
|
# so udev can add its start-message to dmesg
|
|
|
|
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
|
|
|
|
|
2014-11-20 22:25:53 +05:30
|
|
|
# extra symbolic links not provided by default
|
|
|
|
[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd
|
|
|
|
[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin
|
|
|
|
[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout
|
|
|
|
[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr
|
|
|
|
[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
|
|
|
|
|
|
|
|
# Mount required directories as user may not have them in /etc/fstab
|
2008-10-10 14:07:21 +05:30
|
|
|
for x in \
|
2013-02-15 05:19:46 +05:30
|
|
|
"mqueue /dev/mqueue 1777 ,nodev mqueue" \
|
2008-10-10 14:07:21 +05:30
|
|
|
"devpts /dev/pts 0755 ,gid=5,mode=0620 devpts" \
|
2014-01-23 11:49:35 +05:30
|
|
|
"tmpfs /dev/shm 1777 ,nodev,mode=1777 shm" \
|
2008-10-10 14:07:21 +05:30
|
|
|
; do
|
2009-04-27 13:21:18 +05:30
|
|
|
set -- $x
|
2008-10-10 14:07:21 +05:30
|
|
|
grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue
|
2009-04-27 13:21:18 +05:30
|
|
|
mountinfo -q $2 && continue
|
2008-10-10 14:07:21 +05:30
|
|
|
|
2009-04-27 13:21:18 +05:30
|
|
|
if [ ! -d $2 ]; then
|
|
|
|
mkdir -m $3 -p $2 >/dev/null 2>&1 || \
|
2008-10-10 14:07:21 +05:30
|
|
|
ewarn "Could not create $2!"
|
|
|
|
fi
|
|
|
|
|
2009-04-27 13:21:18 +05:30
|
|
|
if [ -d $2 ]; then
|
2008-10-10 14:07:21 +05:30
|
|
|
ebegin "Mounting $2"
|
2009-04-27 13:21:18 +05:30
|
|
|
if ! fstabinfo --mount $2; then
|
|
|
|
mount -n -t $1 -o noexec,nosuid$4 $5 $2
|
2008-10-10 14:07:21 +05:30
|
|
|
fi
|
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
done
|
2013-12-02 04:01:02 +05:30
|
|
|
}
|
|
|
|
|
2014-07-15 23:57:33 +05:30
|
|
|
restorecon_dev()
|
|
|
|
{
|
|
|
|
if [ -x /sbin/restorecon ]; then
|
2014-07-17 04:37:19 +05:30
|
|
|
ebegin "Restoring SELinux contexts in /dev"
|
2014-07-15 23:57:33 +05:30
|
|
|
restorecon -rF /dev >/dev/null 2>&1
|
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-12-02 04:01:02 +05:30
|
|
|
start()
|
|
|
|
{
|
|
|
|
mount_dev
|
|
|
|
seed_dev
|
2014-07-15 23:57:33 +05:30
|
|
|
restorecon_dev
|
2008-10-10 14:07:21 +05:30
|
|
|
return 0
|
|
|
|
}
|