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

Improve, fixes, big changes, 2 scripts less, one new system.sh, GUI config in live tha work with latest cookutils packages, well tested on Qemu, frugal, first HD install boot
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 16 00:32:16 2011 +0200 (2011-05-16)
parents 1cb12350353b
children 8b16caf41633
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 bootdate=`date +%s`
15 if [ "$1" != "logged" ]; then # logged
17 # Graphical boot start.
18 if [ "$FBSPLASH" == "yes" ]; then
19 reset && fbsplash -c \
20 -s /etc/fbsplash/$FBSPLASH_THEME/fbsplash.ppm \
21 -i /etc/fbsplash/$FBSPLASH_THEME/fbsplash.cfg \
22 -f /etc/fbsplash/fifo &
23 echo "0" > /etc/fbsplash/fifo && sleep 1
24 fi
26 echo "Processing /etc/init.d/rcS..."
28 # Mount /proc.
29 echo -n "Mounting proc filesystem..."
30 /bin/mount proc
31 status
33 [ "$FBSPLASH" == "yes" ] && echo "10" > /etc/fbsplash/fifo
35 # Parse cmdline args for earlier boot options. All other boot options
36 # are in /etc/init./bootopts.sh.
37 echo -n "Searching for early boot options..."
38 for opt in `cat /proc/cmdline`
39 do
40 case $opt in
41 fastbootx|fbx)
42 export FAST_BOOT_X="yes" ;;
43 cdrom=*)
44 export CDROM=${opt#cdrom=} ;;
45 modprobe=*)
46 export MODPROBE="yes" ;;
47 config=*)
48 export CONFIG=${opt#config=} ;;
49 *)
50 continue ;;
51 esac
52 done
53 status
55 [ "$FBSPLASH" == "yes" ] && echo "20" > /etc/fbsplash/fifo
57 # Before mounting filesystems we check fs specified in the file
58 # /etc/rcS.conf and variable $CHECK_FS.
59 if [ -n "$CHECK_FS" ]; then
60 mount -o remount,ro /
61 for i in $CHECK_FS
62 do
63 echo "Checking filesystem on : $i"
64 /sbin/e2fsck -p $i
65 done
66 fi
68 # Remount rootfs rw.
69 echo "Remounting rootfs read/write..."
70 /bin/mount -o remount,rw /
72 # Trigger Udev and handle hotplug events
73 if [ "$UDEV" = "yes" ]; then
74 echo -n "Starting udev daemon..."
75 /sbin/udevd --daemon
76 status
77 echo -n "Udevadm requesting events from the Kernel..."
78 udevadm trigger
79 status
80 echo -n "Udevadm waiting for the event queue to finish..."
81 udevadm settle
82 status
83 echo -n "Using Udev for hotplugging..."
84 echo "/sbin/udevd" > /proc/sys/kernel/hotplug
85 status
86 fi
88 [ "$FBSPLASH" == "yes" ] && echo "30" > /etc/fbsplash/fifo
90 # Mount filesystems in /etc/fstab.
91 echo "Mounting filesystems in fstab..."
92 /bin/mount -a
94 # Store boot messages to log files.
95 /bin/dmesg > /var/log/dmesg.log &
96 conspy -d | sed 's/ *$//;/^$/d;/^Processi\|^.witchi/,$!d' > /var/log/boot.log
97 script -a -q -c '/etc/init.d/rcS logged' /var/log/boot.log
99 else # logged
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=`grep -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 ! grep -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
288 fi # logged