This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mdev.init
executable file
·93 lines (79 loc) · 2.61 KB
/
mdev.init
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
#!/sbin/openrc-run
depend()
{
provide dev
need sysfs
}
start()
{
ebegin "Mounting /dev (mdev)"
# First umount /dev and friends if it is already mounted.
# It may be leftover from initramfs mount --move, we don't
# want to use it.
umount /dev/pts /dev/shm /dev/mqueue /dev >/dev/null 2>&1
if fstabinfo --quiet /dev ; then
mount -n /dev
else
mount -n -t tmpfs -o "exec,nosuid,mode=0755,size=10M" mdev-tmpfs /dev
fi
# Create a file so that our rc system knows it's still in sysinit.
# Existance means init scripts will not directly run.
# rc will remove the file when done with sysinit.
touch /dev/.rcsysinit
# Avoid race conditions, serialize hotplug events.
touch /dev/mdev.seq
# Some basic nodes.
[ ! -e /dev/console ] && mknod /dev/console c 5 1
[ ! -e /dev/null ] && mknod /dev/null c 1 3
[ ! -e /dev/tty ] && mknod /dev/tty c 5 0
[ ! -e /dev/tty1 ] && mknod /dev/tty1 c 4 1
[ ! -e /dev/urandom ] && mknod /dev/urandom c 1 9
[ ! -e /dev/random ] && mknod /dev/random c 1 8
[ ! -e /dev/zero ] && mknod /dev/zero c 1 5
ln -snf /proc/self/fd /dev/fd
ln -snf fd/0 /dev/stdin
ln -snf fd/1 /dev/stdout
ln -snf fd/2 /dev/stderr
[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
mkdir -m 0755 /dev/pts /dev/shm /dev/mqueue /dev/mapper
if [ -e /proc/sys/kernel/hotplug ] ; then
ebegin "Setting up mdev as hotplug agent"
echo /sbin/mdev > /proc/sys/kernel/hotplug
eend 0
fi
ebegin "Loading kernel modules for detected hardware"
env -i /sbin/mdev -s
# mdev -s does not poke network interfaces or usb devices so we need to do it here.
for i in /sys/class/net/*/uevent; do printf 'add' > "$i"; done 2>/dev/null; unset i
for i in /sys/bus/usb/devices/*; do
case "${i##*/}" in
[0-9]*-[0-9]*)
printf 'add' > "$i/uevent"
;;
esac
done; unset i
# Load kernel modules, run twice.
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
eend 0
ebegin "Mounting /dev/pts"
if ! fstabinfo --mount /dev/pts; then
mount -n -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts
fi
eend "$?"
ebegin "Mounting /dev/shm"
if ! fstabinfo --mount /dev/shm; then
mount -n -t tmpfs -o noexec,nosuid,nodev,mode=1777 shm-tmpfs /dev/shm
fi
eend "$?"
ebegin "Mounting /dev/mqueue"
if ! fstabinfo --mount /dev/mqueue && grep -q mqueue /proc/filesystems; then
mount -n -t mqueue -o noexec,nosuid,nodev mqueue /dev/mqueue
fi
eend "$?"
}
stop() {
ebegin "Disabling mdev hotplug agent."
[ -e /proc/sys/kernel/hotplug ] && echo '' >/proc/sys/kernel/hotplug
eend 0
}