Annotation of /tags/busybox-init-0_1_7/rc/udev
Parent Directory | Revision Log
Revision 724 -
(hide annotations)
(download)
Mon Jun 2 22:14:35 2008 UTC (16 years, 3 months ago) by niro
Original Path: trunk/busybox-initscripts/rc/udev
File size: 3870 byte(s)
Mon Jun 2 22:14:35 2008 UTC (16 years, 3 months ago) by niro
Original Path: trunk/busybox-initscripts/rc/udev
File size: 3870 byte(s)
-busybox port of magellan-initscript
1 | niro | 724 | #!/bin/sh |
2 | # $Header: /home/cvsd/magellan-cvs/magellan-src/busybox-initscripts/rc/udev,v 1.1 2008-06-02 22:14:35 niro Exp $ | ||
3 | |||
4 | udev_version() | ||
5 | { | ||
6 | local version=0 | ||
7 | |||
8 | if [[ -x /sbin/udev ]] | ||
9 | then | ||
10 | version=$(/sbin/udev -V) | ||
11 | # We need it without a leading '0', else bash do the wrong thing | ||
12 | version=${version##0} | ||
13 | # Older udev's will print nothing | ||
14 | [[ -z ${version} ]] && version=0 | ||
15 | elif [[ -x /sbin/udevd ]] | ||
16 | then | ||
17 | version=$(/sbin/udevd --version) | ||
18 | version=${version##0} | ||
19 | [[ -z ${version} ]] && version=0 | ||
20 | fi | ||
21 | |||
22 | echo "${version}" | ||
23 | } | ||
24 | |||
25 | populate_udev() | ||
26 | { | ||
27 | local opts | ||
28 | |||
29 | # tell modprobe.sh to be verbose to $CONSOLE | ||
30 | echo CONSOLE=${CONSOLE} > /dev/.udev_populate | ||
31 | |||
32 | # populate /dev with devices already found by the kernel | ||
33 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." | ||
34 | if [[ ${RC_COLDPLUG} = yes ]] | ||
35 | then | ||
36 | /sbin/udevtrigger | ||
37 | else | ||
38 | # do not run any init-scripts | ||
39 | /sbin/udevadm control --env do_not_run_plug_service=1 | ||
40 | |||
41 | # only create device nodes | ||
42 | /sbin/udevtrigger --attr-match=dev | ||
43 | |||
44 | # run persistent-net stuff | ||
45 | /sbin/udevtrigger --subsystem-match=net | ||
46 | fi | ||
47 | evaluate_retval | ||
48 | |||
49 | # loop until everything is finished | ||
50 | echo -e ${COLOREDSTAR}" Letting udev process events ..." | ||
51 | /sbin/udevsettle --timeout=60 | ||
52 | evaluate_retval | ||
53 | |||
54 | # unset this variable | ||
55 | udevadm control --env do_not_run_plug_service= | ||
56 | |||
57 | rm -f /dev/.udev_populate | ||
58 | return 0 | ||
59 | } | ||
60 | |||
61 | seed_dev() | ||
62 | { | ||
63 | # seed /dev with some things that we know we need | ||
64 | echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." | ||
65 | ( | ||
66 | [ ! -c /dev/console ] && mknod /dev/console c 5 1 | ||
67 | [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1 | ||
68 | [ ! -c /dev/null ] && mknod /dev/null c 1 3 | ||
69 | |||
70 | # copy over any persistant things | ||
71 | if [[ -d /lib/udev/devices ]] | ||
72 | then | ||
73 | cp -RPp /lib/udev/devices/* /dev 2>/dev/null | ||
74 | fi | ||
75 | |||
76 | # not provided by sysfs but needed | ||
77 | ln -snf /proc/self/fd /dev/fd | ||
78 | ln -snf fd/0 /dev/stdin | ||
79 | ln -snf fd/1 /dev/stdout | ||
80 | ln -snf fd/2 /dev/stderr | ||
81 | [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core | ||
82 | |||
83 | # create problematic directories | ||
84 | mkdir -p /dev/pts /dev/shm | ||
85 | ) | ||
86 | evaluate_retval | ||
87 | } | ||
88 | |||
89 | # main functions | ||
90 | start_udev() | ||
91 | { | ||
92 | # check if /dev/console exists outside tmpfs | ||
93 | [ -c /dev/console ] ; need_redirect=$? | ||
94 | |||
95 | # create a ramdisk for populating udev | ||
96 | echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." | ||
97 | # many video drivers needed exec access | ||
98 | fstype=ramfs | ||
99 | # tmpfs was suggested by Greg Kroah-Hartman | ||
100 | kernel_supports_fs tmpfs && fstype=tmpfs | ||
101 | mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755,size=10M | ||
102 | evaluate_retval | ||
103 | |||
104 | # if a device tarball exists load it and if it is activated | ||
105 | echo -e ${COLOREDSTAR}"Configurating system to use udev ..." | ||
106 | if [[ ${RC_DEVICE_TARBALL} = yes ]] | ||
107 | then | ||
108 | echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." | ||
109 | tar -jxpf /lib/udev/state/devices.tar.bz2 -C /dev | ||
110 | evaluate_retval | ||
111 | fi | ||
112 | |||
113 | # other eeded device nodes with udev | ||
114 | seed_dev | ||
115 | |||
116 | if [ -e /proc/sys/kernel/hotplug ] | ||
117 | then | ||
118 | echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." | ||
119 | echo "" > /proc/sys/kernel/hotplug | ||
120 | evaluate_retval | ||
121 | else | ||
122 | echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" | ||
123 | print_status failure | ||
124 | fi | ||
125 | |||
126 | echo -e ${COLOREDSTAR}" Starting udevd daemon ..." | ||
127 | if [ ${need_redirect} -eq 1 ] | ||
128 | then | ||
129 | # we need to open fds 0 1 2 | ||
130 | /sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console | ||
131 | else | ||
132 | /sbin/udevd --daemon | ||
133 | fi | ||
134 | evaluate_retval | ||
135 | |||
136 | # write root_link rule | ||
137 | /lib/udev/write_root_link_rule | ||
138 | # populate udev device nodes | ||
139 | populate_udev | ||
140 | |||
141 | # create nodes that udev can't | ||
142 | echo -e ${COLOREDSTAR}" Finializing udev configuration ..." | ||
143 | [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null | ||
144 | [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null | ||
145 | [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null | ||
146 | print_status success | ||
147 | |||
148 | # same thing as /dev/.devfsd | ||
149 | touch /dev/.udev | ||
150 | } |