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

Use udev trigger to ensure everything is fine
author Christophe Lincoln <pankso@slitaz.org>
date Thu Feb 24 22:05:12 2011 +0100 (2011-02-24)
parents be7c1a2e97d7
children 35d59233d736
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 # Boot time.
12 bootdate=`date +%s`
14 if [ "$1" != "logged" ]; then # logged
16 echo "Processing /etc/init.d/rcS..."
18 # Mount /proc.
19 echo -n "Mounting proc filesystem..."
20 /bin/mount proc
21 status
23 # Parse cmdline args for earlier boot options. All other boot options
24 # are in /etc/init./bootopts.sh.
25 echo -n "Searching for early boot options..."
26 for opt in `cat /proc/cmdline`
27 do
28 case $opt in
29 fastbootx|fbx)
30 export FAST_BOOT_X="yes" ;;
31 cdrom=*)
32 export CDROM=${opt#cdrom=} ;;
33 modprobe=*)
34 export MODPROBE="yes" ;;
35 config=*)
36 export CONFIG=${opt#config=} ;;
37 *)
38 continue ;;
39 esac
40 done
41 status
43 # Trigger Udev and handle hotplug events
44 if [ "$UDEV" = "yes" ]; then
45 echo -n "Udevadm requesting events from the Kernel..."
46 udevadm trigger
47 status
48 echo -n "Using udev daemon for hotplugging..."
49 echo "/sbin/udevd" > /proc/sys/kernel/hotplug
50 status
51 fi
53 # Before mounting filesystems we check fs specified in the file
54 # /etc/rcS.conf and variable $CHECK_FS.
55 if [ -n "$CHECK_FS" ]; then
56 mount -o remount,ro /
57 for i in $CHECK_FS
58 do
59 echo "Checking filesystem on : $i"
60 /sbin/e2fsck -p $i
61 done
62 fi
64 # Remount rootfs rw.
65 echo "Remounting rootfs read/write..."
66 /bin/mount -o remount,rw /
68 # Mount filesystems in /etc/fstab.
69 echo "Mounting filesystems in fstab..."
70 /bin/mount -a
72 # Store boot messages to log files.
73 /bin/dmesg > /var/log/dmesg.log &
74 conspy -d | sed 's/ *$//;/^$/d;/^Processi\|^.witchi/,$!d' > /var/log/boot.log
75 script -a -q -c '/etc/init.d/rcS logged' /var/log/boot.log
77 else # logged
79 # Clean up the system.
80 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
81 echo -n "Cleaning up the system..."
82 find /var/run -name "*.pid" -type f | xargs /bin/rm -f
83 /bin/rm -rf /tmp /var/run/dbus/* /var/run/hald/pid /var/lock/*
84 /bin/mkdir -p /tmp && /bin/chmod 1777 /tmp
85 status
86 else
87 echo "System clean up is disabled in /etc/rcS.conf..."
88 echo -n "Keeping all tmp and pid files..."
89 status
90 fi
92 # Set up tmp X11 and ICE dir.
93 echo -n "Setting up tmp X11 and ICE unix dir..."
94 /bin/mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
95 /bin/chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix
96 status
98 # Fast boot into X for HD install or custom Live system. We need
99 # keymap settings since Xvesa dumps the console mapping and a correct
100 # slim configuration for screen resolution. DBUS and HAL must also start
101 # before X session (manual login or autologin) to have devices in PCmanFM.
102 if [ "$FAST_BOOT_X" = "yes" ]; then
103 /etc/init.d/i18n.sh
104 /etc/init.d/dbus start
105 /etc/init.d/hald start
106 /etc/init.d/slim start &
107 fi
109 # Create /dev/cdrom if needed (symlink does not exist on LiveCD).
110 # Also add /dev/cdrom to fstab if entry does not exist.
111 if [ -n "$CDROM" ]; then
112 DRIVE_NAME=${CDROM#/dev/}
113 else
114 DRIVE_NAME=`grep -s "drive name" /proc/sys/dev/cdrom/info | cut -f 3`
115 fi
116 if [ -n "$DRIVE_NAME" -a ! "`readlink /dev/cdrom`" ]; then
117 echo -n "Creating symlink : /dev/cdrom..."
118 ln -s /dev/$DRIVE_NAME /dev/cdrom
119 ln -s /dev/$DRIVE_NAME /dev/dvd
120 status
121 fi
122 if ! grep -q "/dev/cdrom" /etc/fstab; then
123 echo -n "Adding /dev/cdrom to fstab..."
124 echo '/dev/cdrom /media/cdrom iso9660 user,ro,noauto 0 0' \
125 >> /etc/fstab
126 status
127 fi
128 # Chmod hack on each boot for Asunder and burnbox. Allowing all users
129 # to burn/rip CD/DVD.
130 if [ -n "$DRIVE_NAME" -a "`readlink /dev/cdrom`" ]; then
131 echo -n "Chmoding cdrom device..."
132 chmod 0666 /dev/cdrom
133 chmod 0666 /dev/dvd
134 chmod 0666 /dev/$DRIVE_NAME
135 status
136 fi
138 # Handle kernel cmdline parameter modprobe=<module_list>
139 if [ -n "$MODPROBE" ]; then
140 MODULES=`sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline`
141 for i in $MODULES; do
142 echo -n "Loading kernel module $i"
143 /sbin/modprobe $i
144 status
145 done
146 fi
148 # Handle kernel cmdline parameter config=<device>,<path> to source a
149 # disk init script
150 if [ -n "$CONFIG" ]; then
151 DEVICE=${CONFIG%,*}
152 SCRIPT=${CONFIG#*,}
153 echo "Probing $DEVICE... "
154 if ! /bin/mount -r $DEVICE /mnt; then
155 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
156 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
157 USBDELAY=$((1+$USBDELAY))
158 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
159 sleep $USBDELAY
160 fi
161 if ! /bin/mount -r $DEVICE /mnt; then
162 CONFIG=""
163 fi
164 fi
165 echo -n "Source $SCRIPT from $DEVICE..."
166 if [ -n "$CONFIG" ]; then
167 . /mnt/$SCRIPT
168 /bin/umount /mnt 2> /dev/null || true
169 fi
170 status
171 fi
173 # Mount /proc/bus/usb.
174 if [ -d /proc/bus/usb ]; then
175 echo -n "Mounting /proc/bus/usb filesystem..."
176 /bin/mount -t usbfs usbfs /proc/bus/usb
177 status
178 fi
180 # Start syslogd and klogd.
181 if [ "$KERNEL_LOG_DAEMONS" = "yes" ]; then
182 echo -n "Starting system log deamon: syslogd..."
183 /sbin/syslogd -s $SYSLOGD_ROTATED_SIZE && status
184 echo -n "Starting kernel log daemon: klogd..."
185 /sbin/klogd && status
186 else
187 echo "Kernel log daemons are disabled in /etc/rc.conf..."
188 fi
190 # Load all modules listed in config file.
191 if [ -n "$LOAD_MODULES" ]; then
192 for mod in $LOAD_MODULES
193 do
194 modprobe $mod
195 done
196 fi
198 # Be quiet on configuration to avoid messages overwriting ncurses dialog
199 echo "0 0 0 0" > /proc/sys/kernel/printk
201 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
202 # kernel modules only at first boot or in LiveCD mode.
203 if [ ! -s /var/lib/detected-modules ]; then
204 /sbin/tazhw init
205 fi
207 # Call udevadm trigger to ensure /dev is fully populate now that all
208 # modules are loaded.
209 if [ "$UDEV" = "yes" ]; then
210 echo -n "Requesting events from the Kernel..."
211 udevadm trigger
212 status
213 fi
215 # Start all scripts specified with $RUN_SCRIPTS.
216 echo "Executing all initialization scripts..."
217 for script in $RUN_SCRIPTS
218 do
219 if [ -x /etc/init.d/$script ]; then
220 /etc/init.d/$script
221 fi
222 done
224 # Re-source main config file. In Live mode, daemons list can be modified
225 # by boot options (screen=text will remove slim).
226 . /etc/rcS.conf
228 # Start all daemons specified with $RUN_DAEMONS.
229 echo "Starting all daemons specified in /etc/rcS.conf..."
230 for daemon in $RUN_DAEMONS
231 do
232 if [ -x /etc/init.d/$daemon ]; then
233 /etc/init.d/$daemon start
234 fi
235 done
237 # Back to a verbose mode.
238 echo "7 4 1 7" > /proc/sys/kernel/printk
240 # Reset screen and display a bold message.
241 if [ -n "$MESSAGE" ]; then
242 /usr/bin/reset
243 echo -e "\033[1m$MESSAGE\033[0m"
244 fi
246 # Display and log boot time.
247 time=$((`date +%s` - $bootdate))
248 echo $time > /var/log/boot-time
249 echo "SliTaz boot time: ${time}s"
251 fi # logged