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

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