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

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