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

Huge clean, colored rcS, faster, fix sound and other devices (used need a devtmpfs mounted on /dev) disabled logging for now
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 01 21:46:07 2012 +0200 (2012-06-01)
parents e507111d6d32
children 445b09ea0b07
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 mkdir -p /run/udev
57 udevd --daemon 2>/dev/null
58 echo "Udevadm requesting events from the Kernel..."
59 udevadm trigger
60 echo "Udevadm waiting for the event queue to finish..."
61 udevadm settle --timeout=120
62 # Disable hotplug helper since udevd listen to netlink
63 echo "" > /proc/sys/kernel/hotplug
64 fi
66 # Mount filesystems in /etc/fstab.
67 echo "Mounting filesystems in fstab..."
68 mount -a
70 # Be quiet
71 echo "0 0 0 0" > /proc/sys/kernel/printk
72 ;;
74 logged)
76 # Store boot messages to log files.
77 dmesg > /var/log/dmesg.log &
79 # Parse cmdline args for earlier boot options. All other boot options
80 # are in /etc/init./bootopts.sh.
81 echo -n "Searching for early boot options..."
82 for opt in $(cat /proc/cmdline)
83 do
84 case $opt in
85 cdrom=*)
86 export CDROM=${opt#cdrom=} ;;
87 modprobe=*)
88 export MODPROBE="yes" ;;
89 config=*)
90 export CONFIG=${opt#config=} ;;
91 *)
92 continue ;;
93 esac
94 done
95 status
97 # Clean up the system and set up tmp X11 and ICE dir
98 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
99 echo -n "Cleaning up the system..."
100 find /var/run -name "*.pid" -type f | xargs /bin/rm -f
101 rm -rf /tmp /var/run/dbus/* /var/run/hald/pid /var/lock/*
102 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
103 chmod -R 1777 /tmp
104 status
105 else
106 echo "System clean up is disabled in: /etc/rcS.conf"
107 fi
109 # Create /dev/cdrom if needed (symlink does not exist on LiveCD).
110 # Also add /dev/cdrom to fstab if entry does not exist.
111 if [ "$CDROM" ]; then
112 DRIVE_NAME=${CDROM#/dev/}
113 else
114 DRIVE_NAME=$(fgrep -s "drive name" /proc/sys/dev/cdrom/info | cut -f 3)
115 fi
116 if [ "$DRIVE_NAME" -a ! "$(readlink /dev/cdrom)" ]; then
117 echo -n "Creating symlink : /dev/cdrom..."
118 ln -s /dev/$DRIVE_NAME /dev/cdrom
119 ln -s /dev/$DRIVE_NAME /dev/dvd
120 status
121 fi
123 # Handle kernel cmdline parameter modprobe=<module_list>
124 if [ "$MODPROBE" ]; then
125 MODULES=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
126 for i in $MODULES; do
127 echo -n "Loading kernel module: $i"
128 modprobe $i
129 status
130 done
131 fi
133 # Handle kernel cmdline parameter config=<device>,<path> to source a
134 # disk init script
135 if [ -n "$CONFIG" ]; then
136 DEVICE=${CONFIG%,*}
137 SCRIPT=${CONFIG#*,}
138 echo "Probing $DEVICE... "
139 if ! mount -r $DEVICE /mnt; then
140 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
141 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
142 USBDELAY=$((1+$USBDELAY))
143 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
144 sleep $USBDELAY
145 fi
146 if ! mount -r $DEVICE /mnt; then
147 CONFIG=""
148 fi
149 fi
150 echo -n "Source $SCRIPT from $DEVICE..."
151 if [ -n "$CONFIG" ]; then
152 . /mnt/$SCRIPT
153 umount /mnt 2> /dev/null || true
154 fi
155 status
156 fi
158 # Mount /proc/bus/usb
159 if [ -d /proc/bus/usb ]; then
160 echo -n "Mounting /proc/bus/usb filesystem..."
161 mount -t usbfs usbfs /proc/bus/usb
162 status
163 fi
165 # Start syslogd and klogd
166 echo -n "Starting system log deamon: syslogd..."
167 syslogd -s $SYSLOGD_ROTATED_SIZE && status
168 echo -n "Starting kernel log daemon: klogd..."
169 klogd && status
171 # Load all modules listed in config file
172 if [ "$LOAD_MODULES" ]; then
173 colorize 33 "Loading Kernel modules..."
174 for mod in $LOAD_MODULES; do
175 echo -n "Loading module: $mod"
176 modprobe $mod
177 status
178 done
179 fi
181 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
182 # kernel modules only at first boot or in LiveCD mode.
183 if [ ! -s /var/lib/detected-modules ]; then
184 tazhw init
185 fi
187 # Call udevadm trigger to ensure /dev is fully populate now that all
188 # modules are loaded.
189 if [ "$UDEV" = "yes" ]; then
190 echo -n "Triggering udev events: --action=add"
191 udevadm trigger --action=add
192 status
193 fi
195 # Start all scripts specified with $RUN_SCRIPTS
196 for script in $RUN_SCRIPTS; do
197 echo $(colorize 34 "Processing: /etc/init.d/$script")
198 /etc/init.d/$script
199 done
201 # Start all daemons specified with $RUN_DAEMONS
202 if [ "$RUN_DAEMONS" ]; then
203 colorize 33 "Starting all daemons..."
204 for daemon in $RUN_DAEMONS; do
205 /etc/init.d/$daemon start
206 done
207 fi
209 # Back to a verbose mode
210 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
212 if [ "$MESSAGE" ]; then
213 newline
214 colorize 32 "$MESSAGE"
215 fi
217 # Display and log boot time
218 time=$((`date +%s` - $bootdate))
219 echo $time > /var/log/boot-time
220 echo "SliTaz boot time: ${time}s"
221 ;;
223 *)
224 # --> readonly --> readwrite --> logged.
225 #if [ ! -s /run/boot.log ]; then
226 #mount -t devpts devpts /dev/pts
227 #mount -t tmpfs tmpfs /run
228 #fi
229 #script -aqc '/etc/init.d/rcS readonly' /run/boot.log
230 #script -aqc '/etc/init.d/rcS readwrite' /run/boot.log
231 /etc/init.d/rcS readonly
232 /etc/init.d/rcS readwrite
233 # Lograde boot.log
234 #last=.9
235 #for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
236 #mv -f /var/log/boot.log$i /var/log/boot.log$last 2>/dev/null
237 #last=$i
238 #done
239 #mv -f /run/boot.log /var/log/boot.log
240 #script -aqc '/etc/init.d/rcS logged' /var/log/boot.log
241 /etc/init.d/rcS logged ;;
242 esac