Magellan Linux

Contents of /tags/udev-20151110-1/udev.rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2717 - (show annotations) (download)
Tue Nov 10 13:22:37 2015 UTC (8 years, 4 months ago) by niro
File size: 4740 byte(s)
tagged 'udev-20151110-1'
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-udevd --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 # populate /dev with devices already found by the kernel
35 rc_print " Populating /dev with existing devices through uevents ..."
36 if [[ ${RC_COLDPLUG} = yes ]]
37 then
38 udevadm trigger
39 else
40 # do not run any init-scripts
41 udevadm control --property=do_not_run_plug_service=1
42
43 udevadm trigger --type=subsystems --action=add
44 udevadm trigger --type=devices --action=add
45 fi
46 evaluate_retval
47
48 # unset this variable
49 udevadm control --property=do_not_run_plug_service=
50
51 return 0
52 }
53
54 seed_dev()
55 {
56 # seed /dev with some things that we know we need
57 rc_print " Seeding /dev with needed nodes ..."
58 (
59 [ ! -c /dev/console ] && mknod -m 600 /dev/console c 5 1
60 [ ! -c /dev/tty1 ] && mknod -m 620 /dev/tty1 c 4 1
61 [ ! -c /dev/tty ] && mknod -m 666 /dev/tty c 5 0
62 [ ! -c /dev/null ] && mknod -m 666 /dev/null c 1 3
63
64 # create kmsg too, so udev can add its start-message to dmesg
65 [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
66
67 # create problematic directories
68 mkdir -p /dev/pts /dev/shm
69 )
70 evaluate_retval
71 }
72
73 # main function
74 start_devicemanager()
75 {
76 local udev_prefix=""
77 local udev_daemon=""
78
79 # get the right daemon and prefix for newer udev/systemd-udev installations
80 if [ -x /sbin/udevd ]
81 then
82 udev_daemon="/sbin/udevd"
83 udev_prefix=""
84 elif [ -x /lib/udev/udevd ]
85 then
86 udev_daemon="/lib/udev/udevd"
87 udev_prefix=""
88 elif [ -x /usr/lib/systemd/systemd-udevd ]
89 then
90 udev_daemon="/usr/lib/systemd/systemd-udevd"
91 udev_prefix="/usr"
92 fi
93
94 # check if /dev/console exists outside tmpfs
95 [ -c /dev/console ] ; need_redirect=$?
96
97 # create a ramdisk for populating udev
98 if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/self/mountinfo) ]]
99 then
100 rc_print "Mounting udev at /dev ..."
101 # many video drivers needed exec access
102 fstype=ramfs
103 # tmpfs was suggested by Greg Kroah-Hartman
104 kernel_supports_fs tmpfs && fstype=tmpfs
105 # mount devtmpfs if supported
106 kernel_supports_fs devtmpfs && fstype=devtmpfs
107 mount -n -t ${fstype} dev /dev -o exec,nosuid,mode=0755,size=10M
108 evaluate_retval
109 fi
110
111 # if a device tarball exists load it but only if it is activated in the config
112 rc_print "Configurating system to use udev ..."
113 if [[ ${RC_DEVICE_TARBALL} = yes ]]
114 then
115 if [[ -f ${udev_prefix}/lib/udev/state/devices.tar.bz2 ]]
116 then
117 rc_print " Populating /dev with saved device nodes ..."
118 tar -jxpf ${udev_prefix}/lib/udev/state/devices.tar.bz2 -C /dev
119 evaluate_retval
120 fi
121 fi
122
123 # other needed device nodes with udev
124 seed_dev
125
126 if [ -e /proc/sys/kernel/hotplug ]
127 then
128 rc_print " Using netlink for hotplug events ..."
129 echo "" > /proc/sys/kernel/hotplug
130 evaluate_retval
131 else
132 rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !"
133 print_status failure
134 fi
135
136 # load unix domain sockets if built as module
137 if [ -e /proc/modules ]
138 then
139 modprobe -q unix 2>/dev/null
140 fi
141
142 rc_print " Starting udevd daemon ..."
143 if [ ${need_redirect} -eq 1 ]
144 then
145 # we need to open fds 0 1 2
146 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon </dev/console >/dev/console 2>/dev/console
147 else
148 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon
149 fi
150 evaluate_retval
151
152 # write root_link rule
153 if [ -x ${udev_prefix}/lib/udev/write_root_link_rule ]
154 then
155 ${udev_prefix}/lib/udev/write_root_link_rule
156 fi
157
158 # populate udev device nodes
159 populate_udev
160
161 # create nodes that udev can't
162 rc_print " Finializing udev configuration ..."
163 [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
164 [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
165 [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
166 print_status success
167
168 # same thing as /dev/.devfsd
169 touch /dev/.udev
170 }
171
172 stop_devicemanager()
173 {
174 local udev_daemon=""
175
176 # get the right daemon and prefix for newer udev/systemd-udev installations
177 if [ -x /sbin/udevd ]
178 then
179 udev_daemon="/sbin/udevd"
180 elif [ -x /lib/udev/udevd ]
181 then
182 udev_daemon="/lib/udev/udevd"
183 elif [ -x /usr/lib/systemd/systemd-udevd ]
184 then
185 udev_daemon="/usr/lib/systemd/systemd-udevd"
186 fi
187
188 rc_print "Stopping udevd daemon ..."
189 start-stop-daemon --stop --exec "${udev_daemon}"
190 evaluate_retval
191 }