slitaz-boot-scripts rev 442
etc/init.d/rcS: add creating the udev hardware database; use new cmdline_option() from slitaz-base-files; reformat the script.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Sep 11 23:36:42 2017 +0300 (2017-09-11) |
parents | b4f64eaa4d70 |
children | a25d6905c56f |
files | etc/init.d/rcS |
line diff
1.1 --- a/etc/init.d/rcS Mon Sep 04 03:53:58 2017 +0300 1.2 +++ b/etc/init.d/rcS Mon Sep 11 23:36:42 2017 +0300 1.3 @@ -14,225 +14,223 @@ 1.4 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)" 1.5 1.6 case "$1" in 1.7 + readonly) 1.8 + colorize 34 'Processing /etc/init.d/rcS...' 1.9 1.10 -readonly) 1.11 + # Mount /proc 1.12 + action 'Mounting proc filesystem on /proc' 1.13 + mount proc 1.14 + status 1.15 1.16 -colorize 34 'Processing: /etc/init.d/rcS...' 1.17 + # Trigger udev and handle hotplug events 1.18 + if [ "$UDEV" == 'yes' ]; then 1.19 + action 'Mounting devtmpfs filesystem on /dev' 1.20 + mount -t devtmpfs devtmpfs /dev 1.21 + status 1.22 + [ -d '/lib/udev/devices' ] && cp -af /lib/udev/devices/* /dev/ 1.23 1.24 -# Mount /proc 1.25 -action 'Mounting proc filesystem on /proc' 1.26 -mount proc 1.27 -status 1.28 + if [ -d '/etc/udev/hwdb.d' ]; then 1.29 + echo 'Creating the udev hardware database...' 1.30 + udevadm hwdb --update 1.31 + fi 1.32 1.33 -# Trigger Udev and handle hotplug events 1.34 -if [ "$UDEV" == "yes" ]; then 1.35 - action 'Mounting devtmpfs filesystem on: /dev' 1.36 - mount -t devtmpfs devtmpfs /dev 1.37 - status 1.38 - [ -d '/lib/udev/devices' ] && cp -af /lib/udev/devices/* /dev/ 1.39 + echo 'Starting udev daemon...' 1.40 + udevd --daemon 2>/dev/null 1.41 1.42 - echo 'Starting udev daemon...' 1.43 - udevd --daemon 2>/dev/null 1.44 + echo 'Udevadm requesting events from the Kernel...' 1.45 + udevadm trigger 1.46 1.47 - echo 'Udevadm requesting events from the Kernel...' 1.48 - udevadm trigger 1.49 + echo 'Udevadm waiting for the event queue to finish...' 1.50 + udevadm settle --timeout=120 1.51 + # Disable hotplug helper since udevd listen to netlink 1.52 + echo '' > /proc/sys/kernel/hotplug 1.53 + else 1.54 + action 'Executing mdev -s to populate /dev...' 1.55 + mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug 1.56 + status 1.57 + fi 1.58 1.59 - echo 'Udevadm waiting for the event queue to finish...' 1.60 - udevadm settle --timeout=120 1.61 - # Disable hotplug helper since udevd listen to netlink 1.62 - echo '' > /proc/sys/kernel/hotplug 1.63 -else 1.64 - action 'Executing mdev -s to populate /dev...' 1.65 - mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug 1.66 - status 1.67 -fi 1.68 + # Before mounting filesystems we check FS specified in the file 1.69 + # /etc/rcS.conf and variable $CHECK_FS. We need udev started to 1.70 + # have /dev/* populated 1.71 + if [ -n "$CHECK_FS" ]; then 1.72 + mount -o remount,ro / 1.73 + for i in $CHECK_FS; do 1.74 + colorize 36 "Checking filesystem: $i" 1.75 + e2fsck -p $i 1.76 + done 1.77 + fi 1.78 1.79 -# Before mounting filesystems we check fs specified in the file 1.80 -# /etc/rcS.conf and variable $CHECK_FS. We need udev started to 1.81 -# have /dev/* populated 1.82 -if [ -n "$CHECK_FS" ]; then 1.83 - mount -o remount,ro / 1.84 - for i in $CHECK_FS; do 1.85 - colorize 36 "Checking filesystem: $i" 1.86 - e2fsck -p $i 1.87 - done 1.88 -fi 1.89 + # Remount rootfs rw. 1.90 + echo 'Remounting rootfs read/write...' 1.91 + mount -o remount,rw / 1.92 + sync # ensure rw state 1.93 1.94 -# Remount rootfs rw. 1.95 -echo 'Remounting rootfs read/write...' 1.96 -mount -o remount,rw / 1.97 -sync # ensure rw state 1.98 + # Mount filesystems in /etc/fstab. 1.99 + echo 'Mounting filesystems in fstab...' 1.100 + mount -a 1.101 + ;; 1.102 1.103 -# Mount filesystems in /etc/fstab. 1.104 -echo 'Mounting filesystems in fstab...' 1.105 -mount -a 1.106 -;; 1.107 + readwrite) 1.108 + # Be quiet 1.109 + echo '0 0 0 0' > /proc/sys/kernel/printk 1.110 1.111 + # Store boot messages to log files. 1.112 + dmesg > /var/log/dmesg.log & 1.113 1.114 -readwrite) 1.115 + # Parse cmdline args for earlier boot options. All other boot options 1.116 + # are in /etc/init./bootopts.sh. 1.117 + action 'Searching for early boot options...' 1.118 + opt=$(cmdline_option modprobe); [ -n "$opt" ] && export MODPROBE='yes' 1.119 + opt=$(cmdline_option config); [ -n "$opt" ] && export CONFIG="$opt" 1.120 + opt=$(cmdline_option screen); [ -n "$opt" ] && export SCREEN="$opt" 1.121 + status 1.122 1.123 -# Be quiet 1.124 -echo '0 0 0 0' > /proc/sys/kernel/printk 1.125 + # Clean up the system and set up tmp dirs. 1.126 + # */run/* are tmpfs so they are cleaned up at shutdown. 1.127 + if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then 1.128 + action 'Cleaning up the system...' 1.129 + rm -rf /tmp 1.130 + mkdir -p /tmp/.X11-unix /tmp/.ICE-unix 1.131 + chmod -R 1777 /tmp 1.132 + status 1.133 + else 1.134 + echo 'System clean up is disabled in /etc/rcS.conf' 1.135 + fi 1.136 1.137 -# Store boot messages to log files. 1.138 -dmesg > /var/log/dmesg.log & 1.139 + # Handle kernel cmdline parameter modprobe=<module_list> 1.140 + if [ -n "$MODPROBE" ]; then 1.141 + for i in $(cmdline_option modprobe | tr ',' '\n'); do 1.142 + action 'Loading kernel module: %s' "$i" 1.143 + modprobe $i 1.144 + status 1.145 + done 1.146 + fi 1.147 1.148 -# Parse cmdline args for earlier boot options. All other boot options 1.149 -# are in /etc/init./bootopts.sh. 1.150 -action 'Searching for early boot options...' 1.151 -for opt in $(cat /proc/cmdline); do 1.152 - case $opt in 1.153 - modprobe=*) 1.154 - export MODPROBE='yes' ;; 1.155 - config=*) 1.156 - export CONFIG=${opt#config=} ;; 1.157 - screen=*) 1.158 - export SCREEN=${opt#screen=} ;; 1.159 - *) 1.160 - continue ;; 1.161 - esac 1.162 -done 1.163 -status 1.164 + # Handle kernel cmdline parameter config=<device>,<path> to source a 1.165 + # disk init script 1.166 + if [ -n "$CONFIG" ]; then 1.167 + DEVICE=${CONFIG%,*} 1.168 + SCRIPT=${CONFIG#*,} 1.169 + echo "Probing $DEVICE..." 1.170 + if ! mount -r $DEVICE /mnt; then 1.171 + if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then 1.172 + USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use) 1.173 + USBDELAY=$((1+$USBDELAY)) 1.174 + echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds" 1.175 + sleep $USBDELAY 1.176 + fi 1.177 + if ! mount -r $DEVICE /mnt; then 1.178 + CONFIG='' 1.179 + fi 1.180 + fi 1.181 + action 'Source %s from %s...' "$SCRIPT" "$DEVICE" 1.182 + if [ -n "$CONFIG" ]; then 1.183 + . /mnt/$SCRIPT 1.184 + umount /mnt 2>/dev/null || true 1.185 + fi 1.186 + status 1.187 + fi 1.188 1.189 -# Clean up the system and set up tmp dirs. */run/* are tmpfs so they are 1.190 -# cleaned up at shutdown. 1.191 -if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then 1.192 - action 'Cleaning up the system...' 1.193 - rm -rf /tmp 1.194 - mkdir -p /tmp/.X11-unix /tmp/.ICE-unix 1.195 - chmod -R 1777 /tmp 1.196 - status 1.197 -else 1.198 - echo 'System clean up is disabled in: /etc/rcS.conf' 1.199 -fi 1.200 + # Mount /proc/bus/usb 1.201 + if [ -d '/proc/bus/usb' ]; then 1.202 + action 'Mounting usbfs filesystem on /proc/bus/usb' 1.203 + mount -t usbfs usbfs /proc/bus/usb 1.204 + status 1.205 + fi 1.206 1.207 -# Handle kernel cmdline parameter modprobe=<module_list> 1.208 -if [ "$MODPROBE" ]; then 1.209 - mods=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline) 1.210 - for i in $mods; do 1.211 - action 'Loading kernel module: %s' "$i" 1.212 - modprobe $i 1.213 - status 1.214 - done 1.215 -fi 1.216 + # Start syslogd and klogd 1.217 + action 'Starting system log daemon: syslogd...' 1.218 + syslogd -s $SYSLOGD_ROTATED_SIZE; status 1.219 + action 'Starting kernel log daemon: klogd...' 1.220 + klogd; status 1.221 1.222 -# Handle kernel cmdline parameter config=<device>,<path> to source a 1.223 -# disk init script 1.224 -if [ -n "$CONFIG" ]; then 1.225 - DEVICE=${CONFIG%,*} 1.226 - SCRIPT=${CONFIG#*,} 1.227 - echo "Probing $DEVICE... " 1.228 - if ! mount -r $DEVICE /mnt; then 1.229 - if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then 1.230 - USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use) 1.231 - USBDELAY=$((1+$USBDELAY)) 1.232 - echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds" 1.233 - sleep $USBDELAY 1.234 + # Load all modules listed in config file 1.235 + if [ -n "$LOAD_MODULES" ]; then 1.236 + colorize 33 'Loading Kernel modules...' 1.237 + for mod in $LOAD_MODULES; do 1.238 + action 'Loading module: %s' "$mod" 1.239 + modprobe $mod 1.240 + status 1.241 + done 1.242 fi 1.243 - if ! mount -r $DEVICE /mnt; then 1.244 - CONFIG="" 1.245 + 1.246 + # Detect PCI and USB devices with Tazhw from slitaz-tools. We load 1.247 + # kernel modules only at first boot or in Live CD mode. 1.248 + if [ ! -s '/var/lib/detected-modules' ]; then 1.249 + tazhw init 1.250 fi 1.251 - fi 1.252 - action 'Source %s from %s...' "$SCRIPT" "$DEVICE" 1.253 - if [ -n "$CONFIG" ]; then 1.254 - . /mnt/$SCRIPT 1.255 - umount /mnt 2> /dev/null || true 1.256 - fi 1.257 - status 1.258 -fi 1.259 1.260 -# Mount /proc/bus/usb 1.261 -if [ -d /proc/bus/usb ]; then 1.262 - action 'Mounting usbfs filesystem on: /proc/bus/usb' 1.263 - mount -t usbfs usbfs /proc/bus/usb 1.264 - status 1.265 -fi 1.266 + # Call udevadm trigger to ensure /dev is fully populated now that all 1.267 + # modules are loaded. 1.268 + if [ "$UDEV" == 'yes' ]; then 1.269 + action 'Triggering udev events: --action=add' 1.270 + udevadm trigger --action=add 1.271 + status 1.272 + fi 1.273 1.274 -# Start syslogd and klogd 1.275 -action 'Starting system log daemon: syslogd...' 1.276 -syslogd -s $SYSLOGD_ROTATED_SIZE; status 1.277 -action 'Starting kernel log daemon: klogd...' 1.278 -klogd; status 1.279 + # Start all scripts specified with $RUN_SCRIPTS 1.280 + for script in $RUN_SCRIPTS; do 1.281 + colorize 34 "Processing /etc/init.d/$script" 1.282 + /etc/init.d/$script 1.283 + done 1.284 1.285 -# Load all modules listed in config file 1.286 -if [ "$LOAD_MODULES" ]; then 1.287 - colorize 33 'Loading Kernel modules...' 1.288 - for mod in $LOAD_MODULES; do 1.289 - action 'Loading module: %s' "$mod" 1.290 - modprobe $mod 1.291 - status 1.292 - done 1.293 -fi 1.294 + # Start X session. Dbus must be started before Xorg and other daemons. 1.295 + # We started it here because X is run before RUN_DAEMONS. Sleep, in 1.296 + # some live modes we boot too fast and X can't initialize. 1.297 + if [ "$SCREEN" != 'text' -a \ 1.298 + -n "$LOGIN_MANAGER" -a \ 1.299 + -x '/usr/bin/tazx' -a \ 1.300 + -s '/etc/slitaz/applications.conf' -a \ 1.301 + -x "/etc/init.d/$LOGIN_MANAGER" ]; then 1.302 + colorize 36 'Starting X environment...' 1.303 + # We need Xorg 40-Keyboard.conf and SliTaz applications.conf 1.304 + if [ ! -s '/etc/X11/xorg.conf.d/40-Keyboard.conf' ]; then 1.305 + echo 'Configuring Xorg server...' 1.306 + HOME='/root' 1.307 + tazx init 1.308 + fi 1.309 + /etc/init.d/dbus start 1.310 + (sleep 2; /etc/init.d/$LOGIN_MANAGER start >/dev/null) & 1.311 + fi 1.312 1.313 -# Detect PCI and USB devices with Tazhw from slitaz-tools. We load 1.314 -# kernel modules only at first boot or in LiveCD mode. 1.315 -if [ ! -s /var/lib/detected-modules ]; then 1.316 - tazhw init 1.317 -fi 1.318 + # Start all daemons specified with $RUN_DAEMONS 1.319 + if [ -n "$RUN_DAEMONS" ]; then 1.320 + colorize 33 "Starting all daemons..." 1.321 + for daemon in $RUN_DAEMONS; do 1.322 + [ -x "/etc/init.d/$daemon" ] && /etc/init.d/$daemon start 1.323 + done 1.324 + fi 1.325 1.326 -# Call udevadm trigger to ensure /dev is fully populated now that all 1.327 -# modules are loaded. 1.328 -if [ "$UDEV" == 'yes' ]; then 1.329 - action 'Triggering udev events: --action=add' 1.330 - udevadm trigger --action=add 1.331 - status 1.332 -fi 1.333 + # Back to a verbose mode 1.334 + (sleep 6; echo '7 4 1 7' > /proc/sys/kernel/printk) & 1.335 1.336 -# Start all scripts specified with $RUN_SCRIPTS 1.337 -for script in $RUN_SCRIPTS; do 1.338 - echo $(colorize 34 "Processing: /etc/init.d/$script") 1.339 - /etc/init.d/$script 1.340 -done 1.341 + if [ -n "$MESSAGE" ]; then 1.342 + newline 1.343 + colorize 32 "$MESSAGE" 1.344 + fi 1.345 + ;; 1.346 1.347 -# Start X session. Dbus must be started before Xorg and other daemons. 1.348 -# We started it here because X is run before RUN_DAEMONS. Sleep, in 1.349 -# some live modes we boot too fast and X can't initialize. 1.350 -if [ "$SCREEN" != 'text' ] && [ "$LOGIN_MANAGER" ] && 1.351 - [ -x /usr/bin/tazx ] && [ -s /etc/slitaz/applications.conf ] && 1.352 - [ -x "/etc/init.d/$LOGIN_MANAGER" ]; then 1.353 - colorize 36 'Starting X environment...' 1.354 - # We need Xorg 40-Keyboard.conf and SliTaz applications.conf 1.355 - if [ ! -s '/etc/X11/xorg.conf.d/40-Keyboard.conf' ]; then 1.356 - echo 'Configuring Xorg server...' && HOME='/root' 1.357 - tazx init 1.358 - fi 1.359 - /etc/init.d/dbus start 1.360 - (sleep 2; /etc/init.d/${LOGIN_MANAGER} start >/dev/null) & 1.361 -fi 1.362 + *) 1.363 + # Main entry point. 1.364 + # --> readonly --> readwrite 1.365 + if [ ! -s '/run/boot.log' ]; then 1.366 + # Mount /run as tmpfs runtime data are not written to disk 1.367 + mount -t tmpfs tmpfs /run 1.368 + # cp -a in tazpkg does not support /var/run symlink 1.369 + mount --bind /run /var/run 1.370 + fi 1.371 1.372 -# Start all daemons specified with $RUN_DAEMONS 1.373 -if [ "$RUN_DAEMONS" ]; then 1.374 - colorize 33 "Starting all daemons..." 1.375 - for daemon in $RUN_DAEMONS; do 1.376 - [ -x /etc/init.d/$daemon ] && 1.377 - /etc/init.d/$daemon start 1.378 - done 1.379 -fi 1.380 + /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log 1.381 1.382 -# Back to a verbose mode 1.383 -(sleep 6 && echo '7 4 1 7' > /proc/sys/kernel/printk) & 1.384 + # Logrotate boot.log 1.385 + last='.9' 1.386 + for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 ''; do 1.387 + mv -f "/var/log/boot.log$i" "/var/log/boot.log$last" 2>/dev/null 1.388 + last="$i" 1.389 + done 1.390 + mv -f /run/boot.log /var/log/boot.log 1.391 1.392 -if [ "$MESSAGE" ]; then 1.393 - newline 1.394 - colorize 32 "$MESSAGE" 1.395 -fi 1.396 -;; 1.397 - 1.398 -*) 1.399 - # --> readonly --> readwrite 1.400 - if [ ! -s /run/boot.log ]; then 1.401 - # Mount /run as tmpfs runtime data are not written to disk 1.402 - mount -t tmpfs tmpfs /run 1.403 - # cp -a in tazpkg does not support /var/run symlink 1.404 - mount --bind /run /var/run 1.405 - fi 1.406 - /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log 1.407 - # Logrotate boot.log 1.408 - last=.9 1.409 - for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do 1.410 - mv -f /var/log/boot.log${i} /var/log/boot.log${last} 2>/dev/null 1.411 - last=$i 1.412 - done 1.413 - mv -f /run/boot.log /var/log/boot.log 1.414 - /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log ;; 1.415 + /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log 1.416 + ;; 1.417 esac