Magellan Linux

Annotation of /trunk/udev/udev.rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1868 - (hide annotations) (download)
Mon Jul 30 18:10:19 2012 UTC (12 years, 3 months ago) by niro
File size: 4740 byte(s)
-fixed rc to work with newer udev versions (>= 185)
1 niro 1058 #!/bin/bash
2 niro 1813 # $Id$
3 niro 1058
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 niro 1813 elif [[ -x /lib/udev/udevd ]]
15     then
16     version=$(/lib/udev/udevd --version)
17     elif [[ -x /usr/lib/systemd/systemd-udevd ]]
18     then
19 niro 1868 version=$(/usr/lib/systemd/systemd-udevd --version)
20 niro 1058 fi
21    
22 niro 1813 # 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 niro 1058 echo "${version}"
28     }
29    
30     populate_udev()
31     {
32     local opts
33    
34     # populate /dev with devices already found by the kernel
35 niro 1289 rc_print " Populating /dev with existing devices through uevents ..."
36 niro 1058 if [[ ${RC_COLDPLUG} = yes ]]
37     then
38 niro 1813 udevadm trigger
39 niro 1058 else
40     # do not run any init-scripts
41 niro 1868 udevadm control --property=do_not_run_plug_service=1
42 niro 1058
43 niro 1868 udevadm trigger --type=subsystems --action=add
44     udevadm trigger --type=devices --action=add
45 niro 1058 fi
46     evaluate_retval
47    
48     # unset this variable
49 niro 1868 udevadm control --property=do_not_run_plug_service=
50 niro 1058
51     return 0
52     }
53    
54     seed_dev()
55     {
56     # seed /dev with some things that we know we need
57 niro 1289 rc_print " Seeding /dev with needed nodes ..."
58 niro 1058 (
59 niro 1868 [ ! -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 niro 1058
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 niro 1813 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 niro 1058 # check if /dev/console exists outside tmpfs
95     [ -c /dev/console ] ; need_redirect=$?
96    
97     # create a ramdisk for populating udev
98 niro 1868 if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/self/mountinfo) ]]
99 niro 1725 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 niro 1058
111 niro 1813 # if a device tarball exists load it but only if it is activated in the config
112 niro 1289 rc_print "Configurating system to use udev ..."
113 niro 1058 if [[ ${RC_DEVICE_TARBALL} = yes ]]
114     then
115 niro 1813 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 niro 1058 fi
122    
123 niro 1724 # other needed device nodes with udev
124 niro 1058 seed_dev
125    
126     if [ -e /proc/sys/kernel/hotplug ]
127     then
128 niro 1289 rc_print " Using netlink for hotplug events ..."
129 niro 1058 echo "" > /proc/sys/kernel/hotplug
130     evaluate_retval
131     else
132 niro 1289 rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !"
133 niro 1058 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 niro 1289 rc_print " Starting udevd daemon ..."
143 niro 1058 if [ ${need_redirect} -eq 1 ]
144     then
145     # we need to open fds 0 1 2
146 niro 1813 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon </dev/console >/dev/console 2>/dev/console
147 niro 1058 else
148 niro 1813 start-stop-daemon --start --exec "${udev_daemon}" -- --daemon
149 niro 1058 fi
150     evaluate_retval
151    
152     # write root_link rule
153 niro 1813 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 niro 1058 # populate udev device nodes
159     populate_udev
160    
161     # create nodes that udev can't
162 niro 1289 rc_print " Finializing udev configuration ..."
163 niro 1058 [[ -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 niro 1813 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 niro 1289 rc_print "Stopping udevd daemon ..."
189 niro 1813 start-stop-daemon --stop --exec "${udev_daemon}"
190 niro 1058 evaluate_retval
191     }