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

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Feb 17 19:47:59 2014 +0000 (2014-02-17)
parents 6342e4d26e04
children 93758e8de78a
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)"
16 case "$1" in
18 readonly)
20 colorize 34 "Processing: /etc/init.d/rcS..."
22 # Mount /proc
23 echo -n "Mounting proc filesystem on /proc"
24 mount proc && status
26 # Trigger Udev and handle hotplug events
27 if [ "$UDEV" == "yes" ]; then
28 echo -n "Mounting devtmpfs filesystem on: /dev"
29 mount -t devtmpfs devtmpfs /dev
30 status
31 echo "Starting udev daemon..."
32 udevd --daemon 2>/dev/null
33 echo "Udevadm requesting events from the Kernel..."
34 udevadm trigger
35 echo "Udevadm waiting for the event queue to finish..."
36 udevadm settle --timeout=120
37 # Disable hotplug helper since udevd listen to netlink
38 echo "" > /proc/sys/kernel/hotplug
39 fi
41 # Busybox mdev is an udev alternative
42 if [ "$UDEV" == "mdev" ]; then
43 echo -n "Executing mdev -s to populate /dev..."
44 mdev -s && echo "mdev" > /proc/sys/kernel/hotplug
45 status
46 fi
48 # Before mounting filesystems we check fs specified in the file
49 # /etc/rcS.conf and variable $CHECK_FS. WE need udev started to
50 # have /dev/* populated
51 if [ "$CHECK_FS" ]; then
52 mount -o remount,ro /
53 for i in $CHECK_FS; do
54 colorize 36 "Checking filesystem: $i"
55 e2fsck -p $i
56 done
57 fi
59 # Remount rootfs rw.
60 echo "Remounting rootfs read/write..."
61 mount -o remount,rw /
63 # Mount filesystems in /etc/fstab.
64 echo "Mounting filesystems in fstab..."
65 mount -a
66 ;;
68 readwrite)
70 # Be quiet
71 echo "0 0 0 0" > /proc/sys/kernel/printk
73 # Store boot messages to log files.
74 dmesg > /var/log/dmesg.log &
76 # Parse cmdline args for earlier boot options. All other boot options
77 # are in /etc/init./bootopts.sh.
78 echo -n "Searching for early boot options..."
79 for opt in $(cat /proc/cmdline)
80 do
81 case $opt in
82 modprobe=*)
83 export MODPROBE="yes" ;;
84 config=*)
85 export CONFIG=${opt#config=} ;;
86 screen=*)
87 export SCREEN=${opt#screen=} ;;
88 *)
89 continue ;;
90 esac
91 done
92 status
94 # Clean up the system and set up tmp dirs. */run/* are tmpfs so they are
95 # cleaned up at shutdown.
96 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
97 echo -n "Cleaning up the system..."
98 rm -rf /tmp
99 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
100 chmod -R 1777 /tmp
101 status
102 else
103 echo "System clean up is disabled in: /etc/rcS.conf"
104 fi
106 # Handle kernel cmdline parameter modprobe=<module_list>
107 if [ "$MODPROBE" ]; then
108 mods=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
109 for i in $mods; do
110 echo -n "Loading kernel module: $i"
111 modprobe $i
112 status
113 done
114 fi
116 # Handle kernel cmdline parameter config=<device>,<path> to source a
117 # disk init script
118 if [ -n "$CONFIG" ]; then
119 DEVICE=${CONFIG%,*}
120 SCRIPT=${CONFIG#*,}
121 echo "Probing $DEVICE... "
122 if ! mount -r $DEVICE /mnt; then
123 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
124 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
125 USBDELAY=$((1+$USBDELAY))
126 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
127 sleep $USBDELAY
128 fi
129 if ! mount -r $DEVICE /mnt; then
130 CONFIG=""
131 fi
132 fi
133 echo -n "Source $SCRIPT from $DEVICE..."
134 if [ -n "$CONFIG" ]; then
135 . /mnt/$SCRIPT
136 umount /mnt 2> /dev/null || true
137 fi
138 status
139 fi
141 # Mount /proc/bus/usb
142 if [ -d /proc/bus/usb ]; then
143 echo -n "Mounting usbfs filesystem on: /proc/bus/usb"
144 mount -t usbfs usbfs /proc/bus/usb
145 status
146 fi
148 # Start syslogd and klogd
149 echo -n "Starting system log daemon: syslogd..."
150 syslogd -s $SYSLOGD_ROTATED_SIZE && status
151 echo -n "Starting kernel log daemon: klogd..."
152 klogd && status
154 # Load all modules listed in config file
155 if [ "$LOAD_MODULES" ]; then
156 colorize 33 "Loading Kernel modules..."
157 for mod in $LOAD_MODULES; do
158 echo -n "Loading module: $mod"
159 modprobe $mod
160 status
161 done
162 fi
164 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
165 # kernel modules only at first boot or in LiveCD mode.
166 if [ ! -s /var/lib/detected-modules ]; then
167 tazhw init
168 fi
170 # Call udevadm trigger to ensure /dev is fully populated now that all
171 # modules are loaded.
172 if [ "$UDEV" = "yes" ]; then
173 echo -n "Triggering udev events: --action=add"
174 udevadm trigger --action=add
175 status
176 fi
178 # Start all scripts specified with $RUN_SCRIPTS
179 for script in $RUN_SCRIPTS; do
180 echo $(colorize 34 "Processing: /etc/init.d/$script")
181 /etc/init.d/$script
182 done
184 # Start all daemons specified with $RUN_DAEMONS
185 if [ "$RUN_DAEMONS" ]; then
186 colorize 33 "Starting all daemons..."
187 for daemon in $RUN_DAEMONS; do
188 /etc/init.d/$daemon start
189 done
190 fi
192 # Start X session
193 if [ "$SCREEN" != "text" ] && [ "$LOGIN_MANAGER" ] && [ -x /etc/init.d/$LOGIN_MANAGER ]; then
194 mkdir -p /var/run/dbus
195 /etc/init.d/dbus start
196 colorize 36 "Starting X environment..."
197 (sleep 2 && /etc/init.d/$LOGIN_MANAGER start >/dev/null) &
198 fi
200 # Back to a verbose mode
201 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
203 if [ "$MESSAGE" ]; then
204 newline
205 colorize 32 "$MESSAGE"
206 fi
207 ;;
209 *)
210 # --> readonly --> readwrite
211 if [ ! -s /run/boot.log ]; then
212 # Mount /run as tmpfs runtime data are not written to disk
213 mount -t tmpfs tmpfs /run
214 # cp -a in tazpkg does not support /var/run symlink
215 mount --bind /run /var/run
216 fi
217 /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log
218 # Logrotate boot.log
219 last=.9
220 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
221 mv -f /var/log/boot.log${i} /var/log/boot.log${last} 2>/dev/null
222 last=$i
223 done
224 mv -f /run/boot.log /var/log/boot.log
225 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log ;;
226 esac