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

rcS: log execution time for slitaz boot scripts
author Christophe Lincoln <pankso@slitaz.org>
date Tue Dec 22 12:10:13 2009 +0100 (2009-12-22)
parents c9e9d25f04a3
children 29d705b21621
line source
1 #!/bin/sh
2 # /etc/init.d/rcS - Initial boot script for SliTaz GNU/Linux.
3 # Config file is : /etc/rcS.conf
4 #
5 # rcS is the main initialization script used to check fs, mount, clean,
6 # run scripts and start daemons.
7 #
8 . /etc/init.d/rc.functions
9 . /etc/rcS.conf
11 # Boot time.
12 bootdate=`date +%s`
14 if [ "$1" != "logged" ]; then # logged
16 echo "Processing /etc/init.d/rcS..."
18 # Mount /proc.
19 echo -n "Mounting proc filesystem..."
20 /bin/mount proc
21 status
23 # Parse cmdline args for earlier boot options. All other boot options
24 # are in /etc/init./bootopts.sh.
25 echo -n "Searching for early boot options..."
26 for opt in `cat /proc/cmdline`
27 do
28 case $opt in
29 fastbootx|fbx)
30 FAST_BOOT_X="yes" ;;
31 cdrom=*)
32 CDROM=${opt#cdrom=} ;;
33 modprobe=*)
34 MODPROBE="yes" ;;
35 config=*)
36 CONFIG=${opt#config=} ;;
37 *)
38 continue ;;
39 esac
40 done
41 status
43 # Start Udev to populate /dev and handle hotplug events
44 if [ "$UDEV" = "yes" ]; then
45 echo -n "Starting udev daemon..."
46 /sbin/udevd --daemon
47 status
48 echo -n "Udevadm requesting events from the Kernel..."
49 udevadm trigger
50 status
51 echo -n "Udevadm waiting for the event queue to finish..."
52 udevadm settle
53 status
54 echo "/sbin/udevd" > /proc/sys/kernel/hotplug
55 fi
57 # Before mounting filesystems we check fs specified in the file
58 # /etc/rcS.conf and variable $CHECK_FS.
59 if [ -n "$CHECK_FS" ]; then
60 mount -o remount,ro /
61 for i in $CHECK_FS
62 do
63 echo "Checking filesystem on : $i"
64 /sbin/e2fsck -p $i
65 done
66 fi
68 # Remount rootfs rw.
69 echo "Remounting rootfs read/write..."
70 /bin/mount -o remount,rw /
72 # Mount filesystems in /etc/fstab.
73 echo "Mounting filesystems in fstab..."
74 /bin/mount -a
76 # Store boot messages to log files.
77 /bin/dmesg > /var/log/dmesg.log &
78 vcsa2txt < /dev/vcsa1 | awk 'BEGIN {s=0} /^Processing|^.witching/ {s=1} { if (s) print }' >/var/log/boot.log
79 script -a -q -c '/etc/init.d/rcS logged' /var/log/boot.log
81 else # logged
83 # Clean up the system.
84 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
85 echo -n "Cleaning up the system..."
86 find /var/run -name "*.pid" -type f | xargs /bin/rm -f
87 /bin/rm -rf /tmp /var/run/dbus/* /var/run/hald/pid /var/lock/*
88 /bin/mkdir -p /tmp && /bin/chmod 1777 /tmp
89 status
90 else
91 echo "System clean up is disabled in /etc/rcS.conf..."
92 echo -n "Keeping all tmp and pid files..."
93 status
94 fi
96 # Set up tmp X11 and ICE dir.
97 echo -n "Setting up tmp X11 and ICE unix dir..."
98 /bin/mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
99 /bin/chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix
100 status
102 # Fast boot into X for HD install or custom Live system. We need
103 # keymap settings since Xvesa dumps the console mapping and a correct
104 # slim configuration for screen resolution. DBUS and HAL must also start
105 # before X session (manual login or autologin) to have devices in PCmanFM.
106 if [ "$FAST_BOOT_X" = "yes" ]; then
107 /etc/init.d/i18n.sh
108 /etc/init.d/dbus start
109 /etc/init.d/hald start
110 /etc/init.d/slim start &
111 fi
113 # Create /dev/cdrom if needed (symlink does not exist on LiveCD).
114 # Also add /dev/cdrom to fstab if entry does not exist.
115 if [ -n "$CDROM" ]; then
116 DRIVE_NAME=${CDROM#/dev/}
117 else
118 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
119 fi
120 if [ -n "$DRIVE_NAME" -a ! "`readlink /dev/cdrom`" ]; then
121 echo -n "Creating symlink : /dev/cdrom..."
122 ln -s /dev/$DRIVE_NAME /dev/cdrom
123 ln -s /dev/$DRIVE_NAME /dev/dvd
124 status
125 fi
126 if ! grep -q "/dev/cdrom" /etc/fstab; then
127 echo -n "Adding /dev/cdrom to fstab..."
128 echo '/dev/cdrom /media/cdrom iso9660 user,ro,noauto 0 0' \
129 >> /etc/fstab
130 status
131 fi
132 # Chmod hack on each boot for Asunder and burnbox. Allowing all users
133 # to burn/rip CD/DVD.
134 if [ -n "$DRIVE_NAME" -a "`readlink /dev/cdrom`" ]; then
135 echo -n "Chmoding cdrom device..."
136 chmod 0666 /dev/cdrom
137 chmod 0666 /dev/dvd
138 chmod 0666 /dev/$DRIVE_NAME
139 status
140 fi
142 # Handle kernel cmdline parameter modprobe=<module_list>
143 if [ -n "$MODPROBE" ]; then
144 MODULES=`sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline`
145 for i in $MODULES; do
146 echo -n "Loading kernel module $i"
147 /sbin/modprobe $i
148 status
149 done
150 fi
152 # Handle kernel cmdline parameter config=<device>,<path> to source a
153 # disk init script
154 if [ -n "$CONFIG" ]; then
155 DEVICE=${CONFIG%,*}
156 SCRIPT=${CONFIG#*,}
157 echo "Probing $DEVICE... "
158 if ! /bin/mount -r $DEVICE /mnt; then
159 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
160 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
161 USBDELAY=$((1+$USBDELAY))
162 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
163 sleep $USBDELAY
164 fi
165 if ! /bin/mount -r $DEVICE /mnt; then
166 CONFIG=""
167 fi
168 fi
169 echo -n "Source $SCRIPT from $DEVICE..."
170 if [ -n "$CONFIG" ]; then
171 . /mnt/$SCRIPT
172 /bin/umount /mnt 2> /dev/null || true
173 fi
174 status
175 fi
177 # Mount /proc/bus/usb.
178 if [ -d /proc/bus/usb ]; then
179 echo -n "Mounting /proc/bus/usb filesystem..."
180 /bin/mount -t usbfs usbfs /proc/bus/usb
181 status
182 fi
184 # Start syslogd and klogd.
185 if [ "$KERNEL_LOG_DAEMONS" = "yes" ]; then
186 echo -n "Starting system log deamon: syslogd..."
187 /sbin/syslogd -s $SYSLOGD_ROTATED_SIZE && status
188 echo -n "Starting kernel log daemon: klogd..."
189 /sbin/klogd && status
190 else
191 echo "Kernel log daemons are disabled in /etc/rc.conf..."
192 fi
194 # Load all modules listed in config file.
195 if [ -n "$LOAD_MODULES" ]; then
196 for mod in $LOAD_MODULES
197 do
198 modprobe $mod
199 done
200 fi
202 # Be quiet on configuration to avoid messages overwriting ncurses dialog
203 echo "0 0 0 0" > /proc/sys/kernel/printk
205 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
206 # kernel modules only at first boot or in LiveCD mode.
207 if [ ! -s /var/lib/detected-modules ]; then
208 /sbin/tazhw init
209 fi
211 # Call udevadm trigger to ensure /dev is fully populate now that all
212 # modules are loaded.
213 if [ "$UDEV" = "yes" ]; then
214 echo -n "Requesting events from the Kernel..."
215 udevadm trigger
216 status
217 fi
219 # Start all scripts specified with $RUN_SCRIPTS.
220 echo "Executing all initialization scripts..."
221 for script in $RUN_SCRIPTS
222 do
223 if [ -x /etc/init.d/$script ]; then
224 /etc/init.d/$script
225 fi
226 done
228 # Re-source main config file. In Live mode, daemons list can be modified
229 # by boot options (screen=text will remove slim).
230 . /etc/rcS.conf
232 # Start all daemons specified with $RUN_DAEMONS.
233 echo "Starting all daemons specified in /etc/rcS.conf..."
234 for daemon in $RUN_DAEMONS
235 do
236 if [ -x /etc/init.d/$daemon ]; then
237 /etc/init.d/$daemon start
238 fi
239 done
241 # Back to a verbose mode.
242 echo "7 4 1 7" > /proc/sys/kernel/printk
244 # Reset screen and display a bold message.
245 if [ -n "$MESSAGE" ]; then
246 /usr/bin/reset
247 echo -e "\033[1m$MESSAGE\033[0m"
248 fi
250 # Display and log boot time.
251 time=$((`date +%s` - $bootdate))
252 echo $time > /var/log/boot-time
253 echo "SliTaz boot time: ${time}s"
255 fi # logged