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

/etc/init.d/rcS, /init: use /run
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 02 14:31:16 2012 +0200 (2012-06-02)
parents 6b2d11ed8718
children 1940df4ac550
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. Since we mount /run as tmpfs
94 # and have a symlink for /var/run we should have empty directories. But,
95 # some packages may overwrite the link, so make sure we have it.
96 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
97 echo -n "Cleaning up the system..."
98 rm -rf /tmp /var/run && ln -s /run /var/run
99 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix /run/dbus
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 deamon: 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 populate 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 # Back to a verbose mode
193 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
195 if [ "$MESSAGE" ]; then
196 newline
197 colorize 32 "$MESSAGE"
198 fi
200 # Display and log boot time
201 time=$((`date +%s` - $bootdate))
202 echo $time > /var/log/boot-time
203 echo "SliTaz boot time: ${time}s"
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 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