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

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