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

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