Magellan Linux

Contents of /tags/udev-185-r1/udev.rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1814 - (show annotations) (download)
Tue Jun 26 17:12:14 2012 UTC (11 years, 10 months ago) by niro
File size: 5291 byte(s)
tagged 'udev-185-r1'
1 #!/bin/bash
2 # $Id$
3
4 udev_version()
5 {
6 local version=0
7
8 if [[ -x /sbin/udev ]]
9 then
10 version=$(/sbin/udev -V)
11 elif [[ -x /sbin/udevd ]]
12 then
13 version=$(/sbin/udevd --version)
14 elif [[ -x /lib/udev/udevd ]]
15 then
16 version=$(/lib/udev/udevd --version)
17 elif [[ -x /usr/lib/systemd/systemd-udevd ]]
18 then
19 version=$(/usr/lib/systemd/systemd-udev --version)
20 fi
21
22 # We need it without a leading '0', else bash do the wrong thing
23 version=${version##0}
24 # Older udev's will print nothing
25 [[ -z ${version} ]] && version=0
26
27 echo "${version}"
28 }
29
30 populate_udev()
31 {
32 local opts
33
34 # tell modprobe.sh to be verbose to $CONSOLE
35 echo CONSOLE=${CONSOLE} > /dev/.udev_populate
36
37 # populate /dev with devices already found by the kernel
38 rc_print " Populating /dev with existing devices through uevents ..."
39 if [[ ${RC_COLDPLUG} = yes ]]
40 then
41 udevadm trigger
42 else
43 # do not run any init-scripts
44 udevadm control --env do_not_run_plug_service=1
45
46 # only create device nodes
47 udevadm trigger --attr-match=dev
48
49 # run persistent-net stuff
50 udevadm trigger --subsystem-match=net
51 fi
52 evaluate_retval
53
54 # loop until everything is finished
55 rc_print " Letting udev process events ..."
56 udevadm settle --timeout=60
57 evaluate_retval
58
59 # unset this variable
60 udevadm control --env do_not_run_plug_service=
61
62 rm -f /dev/.udev_populate
63 return 0
64 }
65
66 seed_dev()
67 {
68 # seed /dev with some things that we know we need
69 rc_print " Seeding /dev with needed nodes ..."
70 (
71 [ ! -c /dev/console ] && mknod /dev/console c 5 1
72 [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1
73 [ ! -c /dev/null ] && mknod /dev/null c 1 3
74
75 # create kmsg too, so udev can add its start-message to dmesg
76 [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
77
78 # copy over any persistant things
79 if [[ -d /lib/udev/devices ]]
80 then
81 cp -RPp /lib/udev/devices/* /dev 2>/dev/null
82 fi
83
84 # not provided by sysfs but needed
85 ln -snf /proc/self/fd /dev/fd
86 ln -snf fd/0 /dev/stdin
87 ln -snf fd/1 /dev/stdout
88 ln -snf fd/2 /dev/stderr
89 [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
90
91 # create problematic directories
92 mkdir -p /dev/pts /dev/shm
93 )
94 evaluate_retval
95 }
96
97 # main function
98 start_devicemanager()
99 {
100 local udev_prefix=""
101 local udev_daemon=""
102
103 # get the right daemon and prefix for newer udev/systemd-udev installations
104 if [ -x /sbin/udevd ]
105 then
106 udev_daemon="/sbin/udevd"
107 udev_prefix=""
108 elif [ -x /lib/udev/udevd ]
109 then
110 udev_daemon="/lib/udev/udevd"
111 udev_prefix=""
112 elif [ -x /usr/lib/systemd/systemd-udevd ]
113 then
114 udev_daemon="/usr/lib/systemd/systemd-udevd"
115 udev_prefix="/usr"
116 fi
117
118 # check if /dev/console exists outside tmpfs
119 [ -c /dev/console ] ; need_redirect=$?
120
121 # create a ramdisk for populating udev
122 if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/mounts | cut -d ' ' -f2) ]]
123 then
124 rc_print "Mounting udev at /dev ..."
125 # many video drivers needed exec access
126 fstype=ramfs
127 # tmpfs was suggested by Greg Kroah-Hartman
128 kernel_supports_fs tmpfs && fstype=tmpfs
129 # mount devtmpfs if supported
130 kernel_supports_fs devtmpfs && fstype=devtmpfs
131 mount -n -t ${fstype} dev /dev -o exec,nosuid,mode=0755,size=10M
132 evaluate_retval
133 fi
134
135 # if a device tarball exists load it but only if it is activated in the config
136 rc_print "Configurating system to use udev ..."
137 if [[ ${RC_DEVICE_TARBALL} = yes ]]
138 then
139 if [[ -f ${udev_prefix}/lib/udev/state/devices.tar.bz2 ]]
140 then
141 rc_print " Populating /dev with saved device nodes ..."
142 tar -jxpf ${udev_prefix}/lib/udev/state/devices.tar.bz2 -C /dev
143 evaluate_retval
144 fi
145 fi
146
147 # other needed device nodes with udev
148 seed_dev
149
150 if [ -e /proc/sys/kernel/hotplug ]
151 then
152 rc_print " Using netlink for hotplug events ..."
153 echo "" > /proc/sys/kernel/hotplug
154 evaluate_retval
155 else
156 rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !"
157 print_status failure
158 fi
159
160 # load unix domain sockets if built as module
161 if [ -e /proc/modules ]
162 then
163 modprobe -q unix 2>/dev/null
164 fi
165
166 rc_print " Starting udevd daemon ..."
167 if [ ${need_redirect} -eq 1 ]
168 then
169 # we need to open fds 0 1 2
170 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon </dev/console >/dev/console 2>/dev/console
171 else
172 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon
173 fi
174 evaluate_retval
175
176 # write root_link rule
177 if [ -x ${udev_prefix}/lib/udev/write_root_link_rule ]
178 then
179 ${udev_prefix}/lib/udev/write_root_link_rule
180 fi
181
182 # populate udev device nodes
183 populate_udev
184
185 # create nodes that udev can't
186 rc_print " Finializing udev configuration ..."
187 [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
188 [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
189 [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
190 print_status success
191
192 # same thing as /dev/.devfsd
193 touch /dev/.udev
194 }
195
196 stop_devicemanager()
197 {
198 local udev_daemon=""
199
200 # get the right daemon and prefix for newer udev/systemd-udev installations
201 if [ -x /sbin/udevd ]
202 then
203 udev_daemon="/sbin/udevd"
204 elif [ -x /lib/udev/udevd ]
205 then
206 udev_daemon="/lib/udev/udevd"
207 elif [ -x /usr/lib/systemd/systemd-udevd ]
208 then
209 udev_daemon="/usr/lib/systemd/systemd-udevd"
210 fi
211
212 rc_print "Stopping udevd daemon ..."
213 start-stop-daemon --stop --exec "${udev_daemon}"
214 evaluate_retval
215 }