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

rcS: log readwrite
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jun 02 00:22:08 2012 +0200 (2012-06-02)
parents 1ac4d1be812e
children 175982c0484c
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 to avoid pidfile and other runtime data behing
28 # writting to disk.
29 echo -n "Mounting tmpfs filesystem on: /run"
30 mount -t tmpfs tmpfs /run
31 status
33 # Trigger Udev and handle hotplug events
34 if [ "$UDEV" == "yes" ]; then
35 echo -n "Mounting devtmpfs filesystem on: /dev"
36 mount -t devtmpfs devtmpfs /dev
37 status
38 echo "Starting udev daemon..."
39 udevd --daemon 2>/dev/null
40 echo "Udevadm requesting events from the Kernel..."
41 udevadm trigger
42 echo "Udevadm waiting for the event queue to finish..."
43 udevadm settle --timeout=120
44 # Disable hotplug helper since udevd listen to netlink
45 echo "" > /proc/sys/kernel/hotplug
46 fi
48 # Busybox mdev is an udev alternative tu Udev.
49 if [ "$UDEV" == "mdev" ]; then
50 echo -n "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 [ "$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 /
70 # Mount filesystems in /etc/fstab.
71 echo "Mounting filesystems in fstab..."
72 mount -a
73 ;;
75 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 echo -n "Searching for early boot options..."
86 for opt in $(cat /proc/cmdline)
87 do
88 case $opt in
89 modprobe=*)
90 export MODPROBE="yes" ;;
91 config=*)
92 export CONFIG=${opt#config=} ;;
93 *)
94 continue ;;
95 esac
96 done
97 status
99 # Clean up the system and set up tmp dirs. Since we mount /run as tmpfs
100 # and have a symlink for /var/run we should have empty directories. But,
101 # some packages may overwrite the link, so make sure we have it.
102 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
103 echo -n "Cleaning up the system..."
104 rm -rf /tmp /var/run && ln -s /run /var/run
105 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix /run/dbus
106 chmod -R 1777 /tmp
107 status
108 else
109 echo "System clean up is disabled in: /etc/rcS.conf"
110 fi
112 # Handle kernel cmdline parameter modprobe=<module_list>
113 if [ "$MODPROBE" ]; then
114 MODULES=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
115 for i in $MODULES; do
116 echo -n "Loading kernel module: $i"
117 modprobe $i
118 status
119 done
120 fi
122 # Handle kernel cmdline parameter config=<device>,<path> to source a
123 # disk init script
124 if [ -n "$CONFIG" ]; then
125 DEVICE=${CONFIG%,*}
126 SCRIPT=${CONFIG#*,}
127 echo "Probing $DEVICE... "
128 if ! mount -r $DEVICE /mnt; then
129 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
130 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
131 USBDELAY=$((1+$USBDELAY))
132 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
133 sleep $USBDELAY
134 fi
135 if ! mount -r $DEVICE /mnt; then
136 CONFIG=""
137 fi
138 fi
139 echo -n "Source $SCRIPT from $DEVICE..."
140 if [ -n "$CONFIG" ]; then
141 . /mnt/$SCRIPT
142 umount /mnt 2> /dev/null || true
143 fi
144 status
145 fi
147 # Mount /proc/bus/usb
148 if [ -d /proc/bus/usb ]; then
149 echo -n "Mounting /proc/bus/usb filesystem..."
150 mount -t usbfs usbfs /proc/bus/usb
151 status
152 fi
154 # Start syslogd and klogd
155 echo -n "Starting system log deamon: syslogd..."
156 syslogd -s $SYSLOGD_ROTATED_SIZE && status
157 echo -n "Starting kernel log daemon: klogd..."
158 klogd && status
160 # Load all modules listed in config file
161 if [ "$LOAD_MODULES" ]; then
162 colorize 33 "Loading Kernel modules..."
163 for mod in $LOAD_MODULES; do
164 echo -n "Loading module: $mod"
165 modprobe $mod
166 status
167 done
168 fi
170 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
171 # kernel modules only at first boot or in LiveCD mode.
172 if [ ! -s /var/lib/detected-modules ]; then
173 tazhw init
174 fi
176 # Call udevadm trigger to ensure /dev is fully populate now that all
177 # modules are loaded.
178 if [ "$UDEV" = "yes" ]; then
179 echo -n "Triggering udev events: --action=add"
180 udevadm trigger --action=add
181 status
182 fi
184 # Start all scripts specified with $RUN_SCRIPTS
185 for script in $RUN_SCRIPTS; do
186 echo $(colorize 34 "Processing: /etc/init.d/$script")
187 /etc/init.d/$script
188 done
190 # Start all daemons specified with $RUN_DAEMONS
191 if [ "$RUN_DAEMONS" ]; then
192 colorize 33 "Starting all daemons..."
193 for daemon in $RUN_DAEMONS; do
194 /etc/init.d/$daemon start
195 done
196 fi
198 # Back to a verbose mode
199 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
201 if [ "$MESSAGE" ]; then
202 newline
203 colorize 32 "$MESSAGE"
204 fi
206 # Display and log boot time
207 time=$((`date +%s` - $bootdate))
208 echo $time > /var/log/boot-time
209 echo "SliTaz boot time: ${time}s"
210 ;;
212 *)
213 # --> readonly --> readwrite
214 #if [ ! -s /tmp/boot.log ]; then
215 #mount -t tmpfs tmpfs /tmp
216 #mount -t devpts devpts /dev/pts
217 #fi
218 #script -aqc '/etc/init.d/rcS readonly' /tmp/boot.log
219 /etc/init.d/rcS readonly
220 #umount /tmp
221 # Lograde boot.log
222 last=.9
223 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
224 mv -f /var/log/boot.log$i /var/log/boot.log$last 2>/dev/null
225 last=$i
226 done
227 #mv -f /tmp/boot.log /var/log/boot.log
228 script -aqc '/etc/init.d/rcS readwrite' /var/log/boot.log ;;
229 esac