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

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