Magellan Linux

Annotation of /tags/udev-185-r4/udev.rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1725 - (hide annotations) (download)
Mon Apr 2 13:08:49 2012 UTC (12 years ago) by niro
Original Path: trunk/udev/udev.rc
File size: 4351 byte(s)
-do not mount /dev if already mounted, and fixed mount options (mount as dev and use 10MB)
1 niro 1058 #!/bin/bash
2 niro 1087 # $Header: /root/magellan-cvs/src/udev/udev.rc,v 1.2 2010-08-18 00:57:31 niro Exp $
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     # 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 niro 1289 rc_print " Populating /dev with existing devices through uevents ..."
34 niro 1058 if [[ ${RC_COLDPLUG} = yes ]]
35     then
36     /sbin/udevadm trigger
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/udevadm trigger --attr-match=dev
43    
44     # run persistent-net stuff
45     /sbin/udevadm trigger --subsystem-match=net
46     fi
47     evaluate_retval
48    
49     # loop until everything is finished
50 niro 1289 rc_print " Letting udev process events ..."
51 niro 1058 /sbin/udevadm settle --timeout=60
52     evaluate_retval
53    
54     # unset this variable
55     /sbin/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 niro 1289 rc_print " Seeding /dev with needed nodes ..."
65 niro 1058 (
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     # create kmsg too, so udev can add its start-message to dmesg
71     [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
72    
73     # copy over any persistant things
74     if [[ -d /lib/udev/devices ]]
75     then
76     cp -RPp /lib/udev/devices/* /dev 2>/dev/null
77     fi
78    
79     # not provided by sysfs but needed
80     ln -snf /proc/self/fd /dev/fd
81     ln -snf fd/0 /dev/stdin
82     ln -snf fd/1 /dev/stdout
83     ln -snf fd/2 /dev/stderr
84     [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
85    
86     # create problematic directories
87     mkdir -p /dev/pts /dev/shm
88     )
89     evaluate_retval
90     }
91    
92     # main function
93     start_devicemanager()
94     {
95     # check if /dev/console exists outside tmpfs
96     [ -c /dev/console ] ; need_redirect=$?
97    
98     # create a ramdisk for populating udev
99 niro 1725 if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/mounts | cut -d ' ' -f2) ]]
100     then
101     rc_print "Mounting udev at /dev ..."
102     # many video drivers needed exec access
103     fstype=ramfs
104     # tmpfs was suggested by Greg Kroah-Hartman
105     kernel_supports_fs tmpfs && fstype=tmpfs
106     # mount devtmpfs if supported
107     kernel_supports_fs devtmpfs && fstype=devtmpfs
108     mount -n -t ${fstype} dev /dev -o exec,nosuid,mode=0755,size=10M
109     evaluate_retval
110     fi
111 niro 1058
112     # if a device tarball exists load it and if it is activated
113 niro 1289 rc_print "Configurating system to use udev ..."
114 niro 1058 if [[ ${RC_DEVICE_TARBALL} = yes ]]
115     then
116 niro 1289 rc_print " Populating /dev with saved device nodes ..."
117 niro 1058 tar -jxpf /lib/udev/state/devices.tar.bz2 -C /dev
118     evaluate_retval
119     fi
120    
121 niro 1724 # other needed device nodes with udev
122 niro 1058 seed_dev
123    
124     if [ -e /proc/sys/kernel/hotplug ]
125     then
126 niro 1289 rc_print " Using netlink for hotplug events ..."
127 niro 1058 echo "" > /proc/sys/kernel/hotplug
128     evaluate_retval
129     else
130 niro 1289 rc_print ${COLYELLOW}" Kernel was not compiled with hotplug support !"
131 niro 1058 print_status failure
132     fi
133    
134     # load unix domain sockets if built as module
135     if [ -e /proc/modules ]
136     then
137     modprobe -q unix 2>/dev/null
138     fi
139    
140 niro 1289 rc_print " Starting udevd daemon ..."
141 niro 1058 if [ ${need_redirect} -eq 1 ]
142     then
143     # we need to open fds 0 1 2
144     start-stop-daemon --start --exec /sbin/udevd -- --daemon </dev/console >/dev/console 2>/dev/console
145     else
146     start-stop-daemon --start --exec /sbin/udevd -- --daemon
147     fi
148     evaluate_retval
149    
150     # write root_link rule
151     /lib/udev/write_root_link_rule
152     # populate udev device nodes
153     populate_udev
154    
155     # create nodes that udev can't
156 niro 1289 rc_print " Finializing udev configuration ..."
157 niro 1058 [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
158     [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
159     [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
160     print_status success
161    
162     # same thing as /dev/.devfsd
163     touch /dev/.udev
164     }
165    
166     stop_devicemanager()
167     {
168 niro 1289 rc_print "Stopping udevd daemon ..."
169 niro 1058 start-stop-daemon --stop --exec /sbin/udevd
170     evaluate_retval
171     }