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

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