slitaz-boot-scripts view etc/init.d/rcS @ rev 453

etc/init.d/rcS: do not start udevd twice
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 05 08:08:51 2019 +0100 (2019-02-05)
parents 7d4da3b01181
children 01ab2b1d9b4d
line source
1 #!/bin/sh
2 #
3 # /etc/init.d/rcS : Initial boot script for SliTaz GNU/Linux
4 # Configuration file : /etc/rcS.conf
5 #
6 # rcS is the main initialization script used to check fs, mount, clean,
7 # run scripts and start daemons.
8 #
9 . /etc/init.d/rc.functions
10 . /etc/rcS.conf
12 # Set PATH, TZ and boot time.
13 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
14 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)"
16 case "$1" in
17 readonly)
18 colorize 34 'Processing /etc/init.d/rcS...'
20 # Mount /proc
21 action 'Mounting proc filesystem on /proc'
22 mount proc
23 status
25 # Trigger udev and handle hotplug events
26 if [ "$UDEV" == 'yes' ]; then
27 action 'Mounting devtmpfs filesystem on /dev'
28 mount -t devtmpfs devtmpfs /dev
29 status
30 [ -d '/lib/udev/devices' ] && cp -af /lib/udev/devices/* /dev/
32 if [ -d '/etc/udev/hwdb.d' ]; then
33 echo 'Creating the udev hardware database...'
34 udevadm hwdb --update
35 fi
37 if [ -z "$(pidof udevd)" ]; then
38 echo 'Starting udev daemon...'
39 udevd --daemon 2>/dev/null
40 fi
42 echo 'Udevadm requesting events from the Kernel...'
43 udevadm trigger
45 echo 'Udevadm waiting for the event queue to finish...'
46 udevadm settle --timeout=120
47 # Disable hotplug helper since udevd listen to netlink
48 echo '' > /proc/sys/kernel/hotplug
49 else
50 action 'Executing mdev -s to populate /dev...'
51 mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug
52 status
53 fi
55 # Before mounting filesystems we check FS specified in the file
56 # /etc/rcS.conf and variable $CHECK_FS. We need udev started to
57 # have /dev/* populated
58 if [ -n "$CHECK_FS" ]; then
59 mount -o remount,ro /
60 for i in $CHECK_FS; do
61 colorize 36 "Checking filesystem: $i"
62 e2fsck -p $i
63 done
64 fi
66 # Remount rootfs rw.
67 echo 'Remounting rootfs read/write...'
68 mount -o remount,rw /
69 sync # ensure rw state
71 # Mount filesystems in /etc/fstab.
72 echo 'Mounting filesystems in fstab...'
73 mount -a
74 ;;
76 readwrite)
77 # Be quiet
78 echo '0 0 0 0' > /proc/sys/kernel/printk
80 # Store boot messages to log files.
81 dmesg > /var/log/dmesg.log &
83 # Parse cmdline args for earlier boot options. All other boot options
84 # are in /etc/init./bootopts.sh.
85 action 'Searching for early boot options...'
86 opt=$(cmdline_option modprobe); [ -z "$opt" ] || export MODPROBE='yes'
87 opt=$(cmdline_option config); [ -z "$opt" ] || export CONFIG="$opt"
88 opt=$(cmdline_option screen); [ -z "$opt" ] || export SCREEN="$opt"
89 status
91 # Clean up the system and set up tmp dirs.
92 # */run/* are tmpfs so they are cleaned up at shutdown.
93 if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then
94 action 'Cleaning up the system...'
95 rm -rf /tmp
96 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
97 chmod -R 1777 /tmp
98 status
99 else
100 echo 'System clean up is disabled in /etc/rcS.conf'
101 fi
103 # Handle kernel cmdline parameter modprobe=<module_list>
104 if [ -n "$MODPROBE" ]; then
105 for i in $(cmdline_option modprobe | tr ',' '\n'); do
106 action 'Loading kernel module: %s' "$i"
107 modprobe $i
108 status
109 done
110 fi
112 # Handle kernel cmdline parameter config=<device>,<path> to source a
113 # disk init script
114 if [ -n "$CONFIG" ]; then
115 DEVICE=${CONFIG%,*}
116 SCRIPT=${CONFIG#*,}
117 echo "Probing $DEVICE..."
118 if ! mount -r $DEVICE /mnt; then
119 if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then
120 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
121 USBDELAY=$((1+$USBDELAY))
122 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
123 sleep $USBDELAY
124 fi
125 if ! mount -r $DEVICE /mnt; then
126 CONFIG=''
127 fi
128 fi
129 action 'Source %s from %s...' "$SCRIPT" "$DEVICE"
130 if [ -n "$CONFIG" ]; then
131 . /mnt/$SCRIPT
132 umount /mnt 2>/dev/null || true
133 fi
134 status
135 fi
137 # Mount /proc/bus/usb
138 if [ -d '/proc/bus/usb' ]; then
139 action 'Mounting usbfs filesystem on /proc/bus/usb'
140 mount -t usbfs usbfs /proc/bus/usb
141 status
142 fi
144 # Start syslogd and klogd
145 action 'Starting system log daemon: syslogd...'
146 syslogd -s $SYSLOGD_ROTATED_SIZE; status
147 action 'Starting kernel log daemon: klogd...'
148 klogd; status
150 # Load all modules listed in config file
151 if [ -n "$LOAD_MODULES" ]; then
152 colorize 33 'Loading Kernel modules...'
153 for mod in $LOAD_MODULES; do
154 action 'Loading module: %s' "$mod"
155 modprobe $mod
156 status
157 done
158 fi
160 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
161 # kernel modules only at first boot or in Live CD mode.
162 if [ ! -s '/var/lib/detected-modules' ]; then
163 tazhw init
164 fi
166 # Call udevadm trigger to ensure /dev is fully populated now that all
167 # modules are loaded.
168 if [ "$UDEV" == 'yes' ]; then
169 action 'Triggering udev events: --action=add'
170 udevadm trigger --action=add
171 status
172 fi
174 # Start all scripts specified with $RUN_SCRIPTS
175 for script in $RUN_SCRIPTS; do
176 colorize 34 "Processing /etc/init.d/$script"
177 /etc/init.d/$script
178 done
180 # Start X session. Dbus must be started before Xorg and other daemons.
181 # We started it here because X is run before RUN_DAEMONS. Sleep, in
182 # some live modes we boot too fast and X can't initialize.
183 if [ "$SCREEN" != 'text' -a \
184 -n "$LOGIN_MANAGER" -a \
185 -x '/usr/bin/tazx' -a \
186 -s '/etc/slitaz/applications.conf' -a \
187 -x "/etc/init.d/$LOGIN_MANAGER" ]; then
188 colorize 36 'Starting X environment...'
189 # We need Xorg 40-Keyboard.conf and SliTaz applications.conf
190 if [ ! -s '/etc/X11/xorg.conf.d/40-Keyboard.conf' ]; then
191 echo 'Configuring Xorg server...'
192 HOME='/root'
193 tazx init
194 fi
195 /etc/init.d/dbus start
196 (sleep 2; /etc/init.d/$LOGIN_MANAGER start >/dev/null) &
197 fi
199 # Start all daemons specified with $RUN_DAEMONS
200 if [ -n "$RUN_DAEMONS" ]; then
201 colorize 33 "Starting all daemons..."
202 for daemon in $RUN_DAEMONS; do
203 [ -x "/etc/init.d/$daemon" ] && /etc/init.d/$daemon start
204 done
205 fi
207 # Back to a verbose mode
208 (sleep 6; echo '7 4 1 7' > /proc/sys/kernel/printk) &
210 if [ -n "$MESSAGE" ]; then
211 newline
212 colorize 32 "$MESSAGE"
213 fi
214 ;;
216 *)
217 # Main entry point.
218 # --> readonly --> readwrite
219 if [ ! -s '/run/boot.log' ]; then
220 # Mount /run as tmpfs runtime data are not written to disk
221 mount -t tmpfs tmpfs /run
222 # cp -a in tazpkg does not support /var/run symlink
223 mount --bind /run /var/run
224 fi
226 /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log
228 # Logrotate boot.log
229 last='.9'
230 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 ''; do
231 mv -f "/var/log/boot.log$i" "/var/log/boot.log$last" 2>/dev/null
232 last="$i"
233 done
234 mv -f /run/boot.log /var/log/boot.log
236 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log
237 ;;
238 esac