wok-tiny view base-tiny/stuff/etc/init.d/rcS @ rev 94

Refresh, remove kernel*, add linux
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Oct 02 21:45:05 2015 +0200 (2015-10-02)
parents
children a10bae21f602
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" ] || bootdate=$(date +%s)
15 case "$1" in
17 readonly)
19 echo "Processing /etc/init.d/rcS..."
21 # Mount /proc.
22 echo -n "Mounting proc filesystem..."
23 mount proc
24 status
26 if [ "$EARLY_RUN_SCRIPTS" ]; then
27 echo "Executing early initialization scripts..."
28 for script in $EARLY_RUN_SCRIPTS
29 do
30 [ -x /etc/init.d/$script ] && /etc/init.d/$script
31 done
32 fi
34 # Load all modules listed in config file.
35 if [ "$LOAD_MODULES" ]; then
36 echo -n "Loading modules..."
37 for mod in $LOAD_MODULES
38 do
39 echo -n " ${mod%%|*}"
40 modprobe ${mod//|/ }
41 done
42 status
43 [ "$KEEP_MODULES" ] || rm -rf /lib/modules
44 fi
46 # Mount /sys.
47 echo -n "Mounting sys filesystem..."
48 mount sysfs
49 status
51 echo -n "Updating /dev..."
52 for i in /sys/block/*/dev /sys/block/*/*/dev ; do
53 [ -s "$i" ] || continue
54 n=${i%/dev}
55 n=/dev/${n##*/}
56 [ -e $n ] && continue
57 echo -n " ${n##*/}"
58 mknod $n b $(sed 's/:/ /' < $i)
59 done
60 status
62 # Before mounting filesystems we check fs specified in the file
63 # /etc/rcS.conf and variable $CHECK_FS.
64 if [ "$CHECK_FS" ]; then
65 mount -o remount,ro /
66 for i in $CHECK_FS
67 do
68 echo "Checking filesystem on : $i"
69 e2fsck -p $i
70 done
71 fi
73 # Remount rootfs rw.
74 echo "Remounting rootfs read/write..."
75 mount -o remount,rw /
76 ;;
78 readwrite)
80 # Mount filesystems in /etc/fstab.
81 echo "Mounting filesystems in fstab..."
82 mount -a
83 ;;
85 logged)
87 # Store boot messages to log files.
88 dmesg > /var/log/dmesg.log &
90 # Parse cmdline args for earlier boot options. All other boot options
91 # are in /etc/init./bootopts.sh.
92 echo -n "Searching for early boot options..."
93 for opt in $(cat /proc/cmdline)
94 do
95 case $opt in
96 cdrom=*)
97 export CDROM=${opt#cdrom=} ;;
98 modprobe=*)
99 export MODPROBE="yes" ;;
100 config=*)
101 export CONFIG=${opt#config=} ;;
102 *)
103 continue ;;
104 esac
105 done
106 status
108 # Clean up the system.
109 if [ "$CLEAN_UP_SYSTEM" = "yes" ]; then
110 echo -n "Cleaning up the system..."
111 find /var/run -name "*.pid" -type f | xargs rm -f
112 rm -rf /tmp /var/lock/*
113 mkdir -p /tmp && chmod 1777 /tmp
114 status
115 else
116 echo "System clean up is disabled in /etc/rcS.conf..."
117 echo -n "Keeping all tmp and pid files..."
118 status
119 fi
121 # Create /dev/cdrom if needed (symlink does not exist on LiveCD).
122 # Also add /dev/cdrom to fstab if entry does not exist.
123 if [ "$CDROM" ]; then
124 DRIVE_NAME=${CDROM#/dev/}
125 else
126 DRIVE_NAME=$(fgrep -s "drive name" /proc/sys/dev/cdrom/info | cut -f 3)
127 fi
128 if [ -n "$DRIVE_NAME" -a ! "$(readlink /dev/cdrom)" ]; then
129 echo -n "Creating symlink : /dev/cdrom..."
130 ln -s /dev/$DRIVE_NAME /dev/cdrom
131 ln -s /dev/$DRIVE_NAME /dev/dvd
132 chmod 0666 /dev/cdrom /dev/dvd /dev/$DRIVE_NAME
133 status
134 fi
135 if ! fgrep -q "/dev/cdrom" /etc/fstab; then
136 echo -n "Adding /dev/cdrom to fstab..."
137 echo '/dev/cdrom /media/cdrom iso9660 user,ro,noauto 0 0' \
138 >> /etc/fstab
139 status
140 fi
142 # Handle kernel cmdline parameter modprobe=<module_list>
143 if [ "$MODPROBE" ]; then
144 MODULES=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
145 for i in $MODULES; do
146 echo -n "Loading kernel module $i"
147 modprobe $i
148 status
149 done
150 fi
152 # Handle kernel cmdline parameter config=<device>,<path> to source a
153 # disk init script
154 if [ "$CONFIG" ]; then
155 DEVICE=${CONFIG%,*}
156 SCRIPT=${CONFIG#*,}
157 echo "Probing $DEVICE... "
158 if ! mount -r $DEVICE /mnt; then
159 if echo $DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
160 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
161 USBDELAY=$((1+$USBDELAY))
162 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
163 sleep $USBDELAY
164 fi
165 if ! mount -r $DEVICE /mnt; then
166 CONFIG=""
167 fi
168 fi
169 echo -n "Source $SCRIPT from $DEVICE..."
170 if [ "$CONFIG" ]; then
171 . /mnt/$SCRIPT
172 umount /mnt 2> /dev/null || true
173 fi
174 status
175 fi
177 # Mount /proc/bus/usb.
178 if [ -d /proc/bus/usb ]; then
179 echo -n "Mounting /proc/bus/usb filesystem..."
180 mount -t usbfs usbfs /proc/bus/usb
181 status
182 fi
184 # Start syslogd and klogd.
185 if [ "$KERNEL_LOG_DAEMONS" = "yes" ]; then
186 echo -n "Starting system log deamon: syslogd..."
187 syslogd -s $SYSLOGD_ROTATED_SIZE && status
188 echo -n "Starting kernel log daemon: klogd..."
189 klogd && status
190 else
191 echo "Kernel log daemons are disabled in /etc/rc.conf..."
192 fi
194 [ -d /usr/share/kmap ] &&
195 echo "Load keymap $(basename /usr/share/kmap/* .kmap)" &&
196 cat /usr/share/kmap/* | loadkmap &&
197 rm -rf /usr/share/kmap
199 # Start all scripts specified with $RUN_SCRIPTS.
200 echo "Executing all initialization scripts..."
201 for script in $RUN_SCRIPTS
202 do
203 [ -x /etc/init.d/$script ] && /etc/init.d/$script
204 done
206 # Re-source main config file. In Live mode, daemons list can be modified
207 # by boot options (screen=text will remove slim).
208 . /etc/rcS.conf
210 # Start all daemons specified with $RUN_DAEMONS.
211 echo "Starting all daemons specified in /etc/rcS.conf..."
212 for daemon in $RUN_DAEMONS
213 do
214 if [ -x /etc/init.d/$daemon ]; then
215 /etc/init.d/$daemon start
216 fi
217 done
219 # Reset screen and display a bold message.
220 if [ "$MESSAGE" ]; then
221 reset
222 echo -e "\033[1m$MESSAGE\033[0m"
223 fi
225 # Display and log boot time.
226 time=$(($(date +%s) - $bootdate))
227 echo $time > /var/log/boot-time
228 echo "SliTaz boot time: ${time}s"
229 ;;
231 *)
232 if [ ! -s /dev/shm/boot.log ]; then
233 mount -t devpts devpts /dev/pts
234 mount -t tmpfs tmpfs /dev/shm
235 fi
236 script -aqc '/etc/init.d/rcS readonly' /dev/shm/boot.log
237 mv -f /dev/shm/boot.log /boot.log
238 umount /dev/shm
239 script -aqc '/etc/init.d/rcS readwrite' /boot.log
240 last=.9
241 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
242 mv -f /var/log/boot.log$i /var/log/boot.log$last 2>/dev/null
243 last=$i
244 done
245 mv -f /boot.log /var/log/boot.log
246 script -aqc '/etc/init.d/rcS logged' /var/log/boot.log
247 ;;
249 esac