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

rcS: /dev/cdrom is created by udev and add bin/rcSconf for rcS.conf migration
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 01 22:00:52 2012 +0200 (2012-06-01)
parents 175315b7699d
children 1ac4d1be812e
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 # Handle kernel cmdline parameter modprobe=<module_list>
110 if [ "$MODPROBE" ]; then
111 MODULES=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
112 for i in $MODULES; do
113 echo -n "Loading kernel module: $i"
114 modprobe $i
115 status
116 done
117 fi
119 # Handle kernel cmdline parameter config=<device>,<path> to source a
120 # disk init script
121 if [ -n "$CONFIG" ]; then
122 DEVICE=${CONFIG%,*}
123 SCRIPT=${CONFIG#*,}
124 echo "Probing $DEVICE... "
125 if ! mount -r $DEVICE /mnt; then
126 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
127 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
128 USBDELAY=$((1+$USBDELAY))
129 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
130 sleep $USBDELAY
131 fi
132 if ! mount -r $DEVICE /mnt; then
133 CONFIG=""
134 fi
135 fi
136 echo -n "Source $SCRIPT from $DEVICE..."
137 if [ -n "$CONFIG" ]; then
138 . /mnt/$SCRIPT
139 umount /mnt 2> /dev/null || true
140 fi
141 status
142 fi
144 # Mount /proc/bus/usb
145 if [ -d /proc/bus/usb ]; then
146 echo -n "Mounting /proc/bus/usb filesystem..."
147 mount -t usbfs usbfs /proc/bus/usb
148 status
149 fi
151 # Start syslogd and klogd
152 echo -n "Starting system log deamon: syslogd..."
153 syslogd -s $SYSLOGD_ROTATED_SIZE && status
154 echo -n "Starting kernel log daemon: klogd..."
155 klogd && status
157 # Load all modules listed in config file
158 if [ "$LOAD_MODULES" ]; then
159 colorize 33 "Loading Kernel modules..."
160 for mod in $LOAD_MODULES; do
161 echo -n "Loading module: $mod"
162 modprobe $mod
163 status
164 done
165 fi
167 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
168 # kernel modules only at first boot or in LiveCD mode.
169 if [ ! -s /var/lib/detected-modules ]; then
170 tazhw init
171 fi
173 # Call udevadm trigger to ensure /dev is fully populate now that all
174 # modules are loaded.
175 if [ "$UDEV" = "yes" ]; then
176 echo -n "Triggering udev events: --action=add"
177 udevadm trigger --action=add
178 status
179 fi
181 # Start all scripts specified with $RUN_SCRIPTS
182 for script in $RUN_SCRIPTS; do
183 echo $(colorize 34 "Processing: /etc/init.d/$script")
184 /etc/init.d/$script
185 done
187 # Start all daemons specified with $RUN_DAEMONS
188 if [ "$RUN_DAEMONS" ]; then
189 colorize 33 "Starting all daemons..."
190 for daemon in $RUN_DAEMONS; do
191 /etc/init.d/$daemon start
192 done
193 fi
195 # Back to a verbose mode
196 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
198 if [ "$MESSAGE" ]; then
199 newline
200 colorize 32 "$MESSAGE"
201 fi
203 # Display and log boot time
204 time=$((`date +%s` - $bootdate))
205 echo $time > /var/log/boot-time
206 echo "SliTaz boot time: ${time}s"
207 ;;
209 *)
210 # --> readonly --> readwrite --> logged.
211 #if [ ! -s /run/boot.log ]; then
212 #mount -t devpts devpts /dev/pts
213 #mount -t tmpfs tmpfs /run
214 #fi
215 #script -aqc '/etc/init.d/rcS readonly' /run/boot.log
216 #script -aqc '/etc/init.d/rcS readwrite' /run/boot.log
217 /etc/init.d/rcS readonly
218 /etc/init.d/rcS readwrite
219 # Lograde boot.log
220 #last=.9
221 #for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
222 #mv -f /var/log/boot.log$i /var/log/boot.log$last 2>/dev/null
223 #last=$i
224 #done
225 #mv -f /run/boot.log /var/log/boot.log
226 #script -aqc '/etc/init.d/rcS logged' /var/log/boot.log
227 /etc/init.d/rcS logged ;;
228 esac