aboutsummaryrefslogtreecommitdiff
path: root/init.d/devfs.in
blob: 196bc57dee95adf849636eca38fe62df7f697c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!@SBINDIR@/openrc-run
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.

description="Set up the /dev directory"

depend()
{
	provide dev-mount
	before dev
	keyword -prefix -vserver -lxc
}

mount_dev()
{
	local action=--mount devfstype msg=Mounting
	# Some devices require exec, Bug #92921
	local mountopts="exec,nosuid,mode=0755"
	if yesno ${static_dev:-no}; then
		einfo "Using static /dev"
		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
		ewarn "This kernel does not have devtmpfs or tmpfs support."
		ewarn "Assuming you want static /dev. If this is not the case,"
		ewarn "please set the CONFIG_DEVTMPFS or CONFIG_TMPFS option"
		ewarn "in your kernel."
	fi
}

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

	# Mount required stuff as user may not have then in /etc/fstab
	for x in \
		"mqueue /dev/mqueue 1777 ,nodev mqueue" \
		"devpts /dev/pts 0755 ,gid=5,mode=0620 devpts" \
		"tmpfs /dev/shm 1777 ,nodev,mode=1777 shm" \
	; do
		set -- $x
		grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue
		mountinfo -q $2 && continue

		if [ ! -d $2 ]; then
			mkdir -m $3 -p $2 >/dev/null 2>&1 || \
				ewarn "Could not create $2!"
		fi

		if [ -d $2 ]; then
			ebegin "Mounting $2"
			if ! fstabinfo --mount $2; then
				mount -n -t $1 -o noexec,nosuid$4 $5 $2
			fi
			eend $?
		fi
	done
}

restorecon_dev()
{
	if [ -x /sbin/restorecon ]; then
		ebegin "Set SELinux labels in /dev"
		restorecon -rF /dev >/dev/null 2>&1
		eend $?
	fi

	return 0
}

start()
{
	mount_dev
	seed_dev
	restorecon_dev
	return 0
}