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

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