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

Added tag 5.0 for changeset 1dbfd813e21e
author Christophe Lincoln <pankso@slitaz.org>
date Wed May 02 17:03:41 2012 +0200 (2012-05-02)
parents e5d3e6f80efd
children 175315b7699d
line source
1 #!/bin/sh
2 # /etc/init.d/rcS - Initial boot script for SliTaz GNU/Linux.
3 # Config file is : /etc/rcS.conf
4 #
5 # rcS is the main initialization script used to check fs, mount, clean,
6 # run scripts and start daemons.
7 #
8 . /etc/init.d/rc.functions
9 . /etc/rcS.conf
11 # Set TZ and boot time.
12 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)"
13 [ -n "$bootdate" ] || bootdate=`date +%s`
15 case "$1" in
17 readonly)
19 # Graphical boot start.
20 if [ "$FBSPLASH" == "yes" ]; then
21 reset && fbsplash -c \
22 -s /etc/fbsplash/$FBSPLASH_THEME/fbsplash.ppm \
23 -i /etc/fbsplash/$FBSPLASH_THEME/fbsplash.cfg \
24 -f /etc/fbsplash/fifo &
25 echo "0" > /etc/fbsplash/fifo && sleep 1
26 fi
28 echo "Processing /etc/init.d/rcS..."
30 # Mount /proc.
31 echo -n "Mounting proc filesystem..."
32 /bin/mount proc
33 status
35 [ "$FBSPLASH" == "yes" ] && echo "10" > /etc/fbsplash/fifo
37 [ "$FBSPLASH" == "yes" ] && echo "20" > /etc/fbsplash/fifo
39 # Before mounting filesystems we check fs specified in the file
40 # /etc/rcS.conf and variable $CHECK_FS.
41 if [ -n "$CHECK_FS" ]; then
42 mount -o remount,ro /
43 for i in $CHECK_FS
44 do
45 echo "Checking filesystem on : $i"
46 /sbin/e2fsck -p $i
47 done
48 fi
50 # Remount rootfs rw.
51 echo "Remounting rootfs read/write..."
52 /bin/mount -o remount,rw /
53 ;;
55 readwrite)
57 # Trigger Udev and handle hotplug events
58 if [ "$UDEV" = "yes" ]; then
59 echo "Starting udev daemon..."
60 /sbin/udevd --daemon
61 echo "Udevadm requesting events from the Kernel..."
62 udevadm trigger
63 echo "Udevadm waiting for the event queue to finish..."
64 udevadm settle
65 echo "Using Udev for hotplugging..."
66 echo "/sbin/udevd" > /proc/sys/kernel/hotplug
67 fi
69 [ "$FBSPLASH" == "yes" ] && echo "30" > /etc/fbsplash/fifo
71 # Mount filesystems in /etc/fstab.
72 echo "Mounting filesystems in fstab..."
73 /bin/mount -a
74 ;;
76 logged)
78 # Store boot messages to log files.
79 /bin/dmesg > /var/log/dmesg.log &
81 # Parse cmdline args for earlier boot options. All other boot options
82 # are in /etc/init./bootopts.sh.
83 echo -n "Searching for early boot options..."
84 for opt in `cat /proc/cmdline`
85 do
86 case $opt in
87 fastbootx|fbx)
88 export FAST_BOOT_X="yes" ;;
89 cdrom=*)
90 export CDROM=${opt#cdrom=} ;;
91 modprobe=*)
92 export MODPROBE="yes" ;;
93 config=*)
94 export CONFIG=${opt#config=} ;;
95 *)
96 continue ;;
97 esac
98 done
99 status
101 # Clean up the system.
102 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
103 echo -n "Cleaning up the system..."
104 find /var/run -name "*.pid" -type f | xargs /bin/rm -f
105 /bin/rm -rf /tmp /var/run/dbus/* /var/run/hald/pid /var/lock/*
106 /bin/mkdir -p /tmp && /bin/chmod 1777 /tmp
107 status
108 else
109 echo "System clean up is disabled in /etc/rcS.conf..."
110 echo -n "Keeping all tmp and pid files..."
111 status
112 fi
114 [ "$FBSPLASH" == "yes" ] && echo "40" > /etc/fbsplash/fifo
116 # Set up tmp X11 and ICE dir.
117 echo -n "Setting up tmp X11 and ICE unix dir..."
118 /bin/mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
119 /bin/chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix
120 status
122 # Fast boot into X for HD install or custom Live system. We need
123 # keymap settings since Xvesa dumps the console mapping and a correct
124 # slim configuration for screen resolution. DBUS and HAL must also start
125 # before X session (manual login or autologin) to have devices in PCmanFM.
126 if [ "$FAST_BOOT_X" = "yes" ]; then
127 /etc/init.d/system.sh
128 /etc/init.d/dbus start
129 /etc/init.d/hald start
130 /etc/init.d/slim start &
131 fi
133 # Create /dev/cdrom if needed (symlink does not exist on LiveCD).
134 # Also add /dev/cdrom to fstab if entry does not exist.
135 if [ -n "$CDROM" ]; then
136 DRIVE_NAME=${CDROM#/dev/}
137 else
138 DRIVE_NAME=$(fgrep -s "drive name" /proc/sys/dev/cdrom/info | cut -f 3)
139 fi
140 if [ -n "$DRIVE_NAME" -a ! "`readlink /dev/cdrom`" ]; then
141 echo -n "Creating symlink : /dev/cdrom..."
142 ln -s /dev/$DRIVE_NAME /dev/cdrom
143 ln -s /dev/$DRIVE_NAME /dev/dvd
144 status
145 fi
146 if ! fgrep -q "/dev/cdrom" /etc/fstab; then
147 echo -n "Adding /dev/cdrom to fstab..."
148 echo '/dev/cdrom /media/cdrom iso9660 user,ro,noauto 0 0' \
149 >> /etc/fstab
150 status
151 fi
152 # Chmod hack on each boot for Asunder and burnbox. Allowing all users
153 # to burn/rip CD/DVD.
154 if [ -n "$DRIVE_NAME" -a "`readlink /dev/cdrom`" ]; then
155 echo -n "Chmoding cdrom device..."
156 chmod 0666 /dev/cdrom
157 chmod 0666 /dev/dvd
158 chmod 0666 /dev/$DRIVE_NAME
159 status
160 fi
162 [ "$FBSPLASH" == "yes" ] && echo "50" > /etc/fbsplash/fifo
164 # Handle kernel cmdline parameter modprobe=<module_list>
165 if [ -n "$MODPROBE" ]; then
166 MODULES=`sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline`
167 for i in $MODULES; do
168 echo -n "Loading kernel module $i"
169 /sbin/modprobe $i
170 status
171 done
172 fi
174 # Handle kernel cmdline parameter config=<device>,<path> to source a
175 # disk init script
176 if [ -n "$CONFIG" ]; then
177 DEVICE=${CONFIG%,*}
178 SCRIPT=${CONFIG#*,}
179 echo "Probing $DEVICE... "
180 if ! /bin/mount -r $DEVICE /mnt; then
181 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
182 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
183 USBDELAY=$((1+$USBDELAY))
184 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
185 sleep $USBDELAY
186 fi
187 if ! /bin/mount -r $DEVICE /mnt; then
188 CONFIG=""
189 fi
190 fi
191 echo -n "Source $SCRIPT from $DEVICE..."
192 if [ -n "$CONFIG" ]; then
193 . /mnt/$SCRIPT
194 /bin/umount /mnt 2> /dev/null || true
195 fi
196 status
197 fi
199 # Mount /proc/bus/usb.
200 if [ -d /proc/bus/usb ]; then
201 echo -n "Mounting /proc/bus/usb filesystem..."
202 /bin/mount -t usbfs usbfs /proc/bus/usb
203 status
204 fi
206 [ "$FBSPLASH" == "yes" ] && echo "60" > /etc/fbsplash/fifo
208 # Start syslogd and klogd.
209 if [ "$KERNEL_LOG_DAEMONS" = "yes" ]; then
210 echo -n "Starting system log deamon: syslogd..."
211 /sbin/syslogd -s $SYSLOGD_ROTATED_SIZE && status
212 echo -n "Starting kernel log daemon: klogd..."
213 /sbin/klogd && status
214 else
215 echo "Kernel log daemons are disabled in /etc/rc.conf..."
216 fi
218 # Load all modules listed in config file.
219 if [ -n "$LOAD_MODULES" ]; then
220 for mod in $LOAD_MODULES
221 do
222 modprobe $mod
223 done
224 fi
226 # Be quiet on configuration to avoid messages overwriting ncurses dialog
227 echo "0 0 0 0" > /proc/sys/kernel/printk
229 [ "$FBSPLASH" == "yes" ] && echo "70" > /etc/fbsplash/fifo
231 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
232 # kernel modules only at first boot or in LiveCD mode.
233 if [ ! -s /var/lib/detected-modules ]; then
234 /sbin/tazhw init
235 fi
237 [ "$FBSPLASH" == "yes" ] && echo "80" > /etc/fbsplash/fifo
239 # Call udevadm trigger to ensure /dev is fully populate now that all
240 # modules are loaded.
241 if [ "$UDEV" = "yes" ]; then
242 echo -n "Requesting events from the Kernel..."
243 udevadm trigger
244 status
245 fi
247 # Start all scripts specified with $RUN_SCRIPTS.
248 echo "Executing all initialization scripts..."
249 for script in $RUN_SCRIPTS
250 do
251 if [ -x /etc/init.d/$script ]; then
252 /etc/init.d/$script
253 fi
254 done
256 [ "$FBSPLASH" == "yes" ] && echo "90" > /etc/fbsplash/fifo
258 # Re-source main config file. In Live mode, daemons list can be modified
259 # by boot options (screen=text will remove slim).
260 . /etc/rcS.conf
262 # Start all daemons specified with $RUN_DAEMONS.
263 echo "Starting all daemons specified in /etc/rcS.conf..."
264 for daemon in $RUN_DAEMONS
265 do
266 if [ -x /etc/init.d/$daemon ]; then
267 /etc/init.d/$daemon start
268 fi
269 done
271 [ "$FBSPLASH" == "yes" ] && echo "100" > /etc/fbsplash/fifo
273 # Back to a verbose mode.
274 echo "7 4 1 7" > /proc/sys/kernel/printk
276 # Reset screen and display a bold message.
277 if [ -n "$MESSAGE" ]; then
278 /usr/bin/reset
279 echo -e "\033[1m$MESSAGE\033[0m"
280 fi
282 # Display and log boot time.
283 time=$((`date +%s` - $bootdate))
284 echo $time > /var/log/boot-time
285 echo "SliTaz boot time: ${time}s"
286 [ "$FBSPLASH" == "yes" ] && echo "exit" > /etc/fbsplash/fifo
287 ;;
289 *)
290 if [ ! -s /dev/shm/boot.log ]; then
291 mount -t devpts devpts /dev/pts
292 mount -t tmpfs tmpfs /dev/shm
293 fi
294 script -aqc '/etc/init.d/rcS readonly' /dev/shm/boot.log
295 mv -f /dev/shm/boot.log /boot.log
296 umount /dev/shm
297 script -aqc '/etc/init.d/rcS readwrite' /boot.log
298 last=.9
299 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
300 mv -f /var/log/boot.log$i /var/log/boot.log$last 2>/dev/null
301 last=$i
302 done
303 mv -f /boot.log /var/log/boot.log
304 script -aqc '/etc/init.d/rcS logged' /var/log/boot.log
305 ;;
307 esac