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

Start X later in boot process
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 15 18:50:46 2014 +0100 (2014-02-15)
parents 89d0f484166f
children 6342e4d26e04
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 fi
41 # Busybox mdev is an udev alternative
42 if [ "$UDEV" == "mdev" ]; then
43 echo -n "Executing mdev -s to populate /dev..."
44 mdev -s && echo "mdev" > /proc/sys/kernel/hotplug
45 status
46 fi
48 # Before mounting filesystems we check fs specified in the file
49 # /etc/rcS.conf and variable $CHECK_FS. WE need udev started to
50 # have /dev/* populated
51 if [ "$CHECK_FS" ]; then
52 mount -o remount,ro /
53 for i in $CHECK_FS; do
54 colorize 36 "Checking filesystem: $i"
55 e2fsck -p $i
56 done
57 fi
59 # Remount rootfs rw.
60 echo "Remounting rootfs read/write..."
61 mount -o remount,rw /
63 # Mount filesystems in /etc/fstab.
64 echo "Mounting filesystems in fstab..."
65 mount -a
66 ;;
68 readwrite)
70 # Be quiet
71 echo "0 0 0 0" > /proc/sys/kernel/printk
73 # Store boot messages to log files.
74 dmesg > /var/log/dmesg.log &
76 # Parse cmdline args for earlier boot options. All other boot options
77 # are in /etc/init./bootopts.sh.
78 echo -n "Searching for early boot options..."
79 for opt in $(cat /proc/cmdline)
80 do
81 case $opt in
82 modprobe=*)
83 export MODPROBE="yes" ;;
84 config=*)
85 export CONFIG=${opt#config=} ;;
86 *)
87 continue ;;
88 esac
89 done
90 status
92 # Clean up the system and set up tmp dirs */run/* are tmpfs so ther are
93 # clean up at shutdown.
94 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
95 echo -n "Cleaning up the system..."
96 rm -rf /tmp
97 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
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 populated 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 # Start X sesssion
191 if [ "$SCREEN" != "text" ] && [ "$LOGIN_MANAGER" ] && [ -x /etc/init.d/$LOGIN_MANAGER ]; then
192 mkdir -p /var/run/dbus
193 /etc/init.d/dbus start
194 colorize 36 "Starting X environment..."
195 (sleep 2 && /etc/init.d/$LOGIN_MANAGER start >/dev/null) &
196 fi
198 # Back to a verbose mode
199 (sleep 6 && echo "7 4 1 7" > /proc/sys/kernel/printk) &
201 if [ "$MESSAGE" ]; then
202 newline
203 colorize 32 "$MESSAGE"
204 fi
205 ;;
207 *)
208 # --> readonly --> readwrite
209 if [ ! -s /run/boot.log ]; then
210 # Mount /run as tmpfs runtime data are not written to disk
211 mount -t tmpfs tmpfs /run
212 # cp -a in tazpkg does not support /var/run symlink
213 mount --bind /run /var/run
214 fi
215 /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log
216 # Logrotate boot.log
217 last=.9
218 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
219 mv -f /var/log/boot.log${i} /var/log/boot.log${last} 2>/dev/null
220 last=$i
221 done
222 mv -f /run/boot.log /var/log/boot.log
223 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log ;;
224 esac