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

/init: use tee instead of script
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 02 13:49:20 2012 +0200 (2012-06-02)
parents 175982c0484c
children 6b2d11ed8718
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)"
15 [ -n "$bootdate" ] || bootdate=$(date +%s)
17 case "$1" in
19 readonly)
21 colorize 34 "Processing: /etc/init.d/rcS..."
23 # Mount /proc
24 echo -n "Mounting proc filesystem on /proc"
25 mount proc && status
27 # Mount /run as tmpfs runtime data are not written to disk
28 echo -n "Mounting tmpfs filesystem on: /run"
29 mount -t tmpfs tmpfs /run
30 status
32 # Trigger Udev and handle hotplug events
33 if [ "$UDEV" == "yes" ]; then
34 echo -n "Mounting devtmpfs filesystem on: /dev"
35 mount -t devtmpfs devtmpfs /dev
36 status
37 echo "Starting udev daemon..."
38 udevd --daemon 2>/dev/null
39 echo "Udevadm requesting events from the Kernel..."
40 udevadm trigger
41 echo "Udevadm waiting for the event queue to finish..."
42 udevadm settle --timeout=120
43 # Disable hotplug helper since udevd listen to netlink
44 echo "" > /proc/sys/kernel/hotplug
45 fi
47 # Busybox mdev is an udev alternative
48 if [ "$UDEV" == "mdev" ]; then
49 echo -n "Executing mdev -s to populate /dev..."
50 mdev -s && echo "mdev" > /proc/sys/kernel/hotplug
51 status
52 fi
54 # Before mounting filesystems we check fs specified in the file
55 # /etc/rcS.conf and variable $CHECK_FS. WE need udev started to
56 # have /dev/* populated
57 if [ "$CHECK_FS" ]; then
58 mount -o remount,ro /
59 for i in $CHECK_FS; do
60 colorize 36 "Checking filesystem: $i"
61 e2fsck -p $i
62 done
63 fi
65 # Remount rootfs rw.
66 echo "Remounting rootfs read/write..."
67 mount -o remount,rw /
69 # Mount filesystems in /etc/fstab.
70 echo "Mounting filesystems in fstab..."
71 mount -a
72 ;;
74 readwrite)
76 # Be quiet
77 echo "0 0 0 0" > /proc/sys/kernel/printk
79 # Store boot messages to log files.
80 dmesg > /var/log/dmesg.log &
82 # Parse cmdline args for earlier boot options. All other boot options
83 # are in /etc/init./bootopts.sh.
84 echo -n "Searching for early boot options..."
85 for opt in $(cat /proc/cmdline)
86 do
87 case $opt in
88 modprobe=*)
89 export MODPROBE="yes" ;;
90 config=*)
91 export CONFIG=${opt#config=} ;;
92 *)
93 continue ;;
94 esac
95 done
96 status
98 # Clean up the system and set up tmp dirs. Since we mount /run as tmpfs
99 # and have a symlink for /var/run we should have empty directories. But,
100 # some packages may overwrite the link, so make sure we have it.
101 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
102 echo -n "Cleaning up the system..."
103 rm -rf /tmp /var/run && ln -s /run /var/run
104 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix /run/dbus
105 chmod -R 1777 /tmp
106 status
107 else
108 echo "System clean up is disabled in: /etc/rcS.conf"
109 fi
111 # Handle kernel cmdline parameter modprobe=<module_list>
112 if [ "$MODPROBE" ]; then
113 mods=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
114 for i in $mods; do
115 echo -n "Loading kernel module: $i"
116 modprobe $i
117 status
118 done
119 fi
121 # Handle kernel cmdline parameter config=<device>,<path> to source a
122 # disk init script
123 if [ -n "$CONFIG" ]; then
124 DEVICE=${CONFIG%,*}
125 SCRIPT=${CONFIG#*,}
126 echo "Probing $DEVICE... "
127 if ! mount -r $DEVICE /mnt; then
128 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
129 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
130 USBDELAY=$((1+$USBDELAY))
131 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
132 sleep $USBDELAY
133 fi
134 if ! mount -r $DEVICE /mnt; then
135 CONFIG=""
136 fi
137 fi
138 echo -n "Source $SCRIPT from $DEVICE..."
139 if [ -n "$CONFIG" ]; then
140 . /mnt/$SCRIPT
141 umount /mnt 2> /dev/null || true
142 fi
143 status
144 fi
146 # Mount /proc/bus/usb
147 if [ -d /proc/bus/usb ]; then
148 echo -n "Mounting usbfs filesystem on: /proc/bus/usb"
149 mount -t usbfs usbfs /proc/bus/usb
150 status
151 fi
153 # Start syslogd and klogd
154 echo -n "Starting system log deamon: syslogd..."
155 syslogd -s $SYSLOGD_ROTATED_SIZE && status
156 echo -n "Starting kernel log daemon: klogd..."
157 klogd && status
159 # Load all modules listed in config file
160 if [ "$LOAD_MODULES" ]; then
161 colorize 33 "Loading Kernel modules..."
162 for mod in $LOAD_MODULES; do
163 echo -n "Loading module: $mod"
164 modprobe $mod
165 status
166 done
167 fi
169 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
170 # kernel modules only at first boot or in LiveCD mode.
171 if [ ! -s /var/lib/detected-modules ]; then
172 tazhw init
173 fi
175 # Call udevadm trigger to ensure /dev is fully populate now that all
176 # modules are loaded.
177 if [ "$UDEV" = "yes" ]; then
178 echo -n "Triggering udev events: --action=add"
179 udevadm trigger --action=add
180 status
181 fi
183 # Start all scripts specified with $RUN_SCRIPTS
184 for script in $RUN_SCRIPTS; do
185 echo $(colorize 34 "Processing: /etc/init.d/$script")
186 /etc/init.d/$script
187 done
189 # Start all daemons specified with $RUN_DAEMONS
190 if [ "$RUN_DAEMONS" ]; then
191 colorize 33 "Starting all daemons..."
192 for daemon in $RUN_DAEMONS; do
193 /etc/init.d/$daemon start
194 done
195 fi
197 # Back to a verbose mode
198 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
200 if [ "$MESSAGE" ]; then
201 newline
202 colorize 32 "$MESSAGE"
203 fi
205 # Display and log boot time
206 time=$((`date +%s` - $bootdate))
207 echo $time > /var/log/boot-time
208 echo "SliTaz boot time: ${time}s"
209 ;;
211 *)
212 # --> readonly --> readwrite
213 if [ ! -s /tmp/boot.log ]; then
214 mount -t tmpfs tmpfs /tmp
215 fi
216 /etc/init.d/rcS readonly 2>&1 | tee -a /tmp/boot.log
217 # Lograde boot.log
218 last=.9
219 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
220 mv -f /var/log/boot.log${i} /var/log/boot.log${last} 2>/dev/null
221 last=$i
222 done
223 mv -f /tmp/boot.log /var/log/boot.log
224 umount /tmp
225 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log ;;
226 esac