slitaz-boot-scripts annotate etc/init.d/rcS @ 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 7d4da3b01181
rev   line source
pankso@5 1 #!/bin/sh
pankso@302 2 #
pankso@302 3 # /etc/init.d/rcS : Initial boot script for SliTaz GNU/Linux
pankso@302 4 # Configuration file : /etc/rcS.conf
pankso@5 5 #
pankso@153 6 # rcS is the main initialization script used to check fs, mount, clean,
pankso@153 7 # run scripts and start daemons.
pankso@5 8 #
pankso@5 9 . /etc/init.d/rc.functions
pankso@5 10 . /etc/rcS.conf
pankso@5 11
pankso@302 12 # Set PATH, TZ and boot time.
pankso@302 13 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
pankso@262 14 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)"
pankso@187 15
pascal@276 16 case "$1" in
al@442 17 readonly)
al@442 18 colorize 34 'Processing /etc/init.d/rcS...'
pascal@276 19
al@442 20 # Mount /proc
al@442 21 action 'Mounting proc filesystem on /proc'
al@442 22 mount proc
al@442 23 status
pankso@246 24
al@442 25 # Trigger udev and handle hotplug events
al@442 26 if [ "$UDEV" == 'yes' ]; then
al@442 27 action 'Mounting devtmpfs filesystem on /dev'
al@442 28 mount -t devtmpfs devtmpfs /dev
al@442 29 status
al@442 30 [ -d '/lib/udev/devices' ] && cp -af /lib/udev/devices/* /dev/
pankso@171 31
al@442 32 if [ -d '/etc/udev/hwdb.d' ]; then
al@442 33 echo 'Creating the udev hardware database...'
al@442 34 udevadm hwdb --update
al@442 35 fi
pankso@302 36
al@442 37 echo 'Starting udev daemon...'
al@442 38 udevd --daemon 2>/dev/null
al@393 39
al@442 40 echo 'Udevadm requesting events from the Kernel...'
al@442 41 udevadm trigger
al@393 42
al@442 43 echo 'Udevadm waiting for the event queue to finish...'
al@442 44 udevadm settle --timeout=120
al@442 45 # Disable hotplug helper since udevd listen to netlink
al@442 46 echo '' > /proc/sys/kernel/hotplug
al@442 47 else
al@442 48 action 'Executing mdev -s to populate /dev...'
al@442 49 mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug
al@442 50 status
al@442 51 fi
al@393 52
al@442 53 # Before mounting filesystems we check FS specified in the file
al@442 54 # /etc/rcS.conf and variable $CHECK_FS. We need udev started to
al@442 55 # have /dev/* populated
al@442 56 if [ -n "$CHECK_FS" ]; then
al@442 57 mount -o remount,ro /
al@442 58 for i in $CHECK_FS; do
al@442 59 colorize 36 "Checking filesystem: $i"
al@442 60 e2fsck -p $i
al@442 61 done
al@442 62 fi
pankso@305 63
al@442 64 # Remount rootfs rw.
al@442 65 echo 'Remounting rootfs read/write...'
al@442 66 mount -o remount,rw /
al@442 67 sync # ensure rw state
pankso@305 68
al@442 69 # Mount filesystems in /etc/fstab.
al@442 70 echo 'Mounting filesystems in fstab...'
al@442 71 mount -a
al@442 72 ;;
pankso@305 73
al@442 74 readwrite)
al@442 75 # Be quiet
al@442 76 echo '0 0 0 0' > /proc/sys/kernel/printk
pankso@305 77
al@442 78 # Store boot messages to log files.
al@442 79 dmesg > /var/log/dmesg.log &
al@393 80
al@442 81 # Parse cmdline args for earlier boot options. All other boot options
al@442 82 # are in /etc/init./bootopts.sh.
al@442 83 action 'Searching for early boot options...'
al@442 84 opt=$(cmdline_option modprobe); [ -n "$opt" ] && export MODPROBE='yes'
al@442 85 opt=$(cmdline_option config); [ -n "$opt" ] && export CONFIG="$opt"
al@442 86 opt=$(cmdline_option screen); [ -n "$opt" ] && export SCREEN="$opt"
al@442 87 status
pankso@302 88
al@442 89 # Clean up the system and set up tmp dirs.
al@442 90 # */run/* are tmpfs so they are cleaned up at shutdown.
al@442 91 if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then
al@442 92 action 'Cleaning up the system...'
al@442 93 rm -rf /tmp
al@442 94 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
al@442 95 chmod -R 1777 /tmp
al@442 96 status
al@442 97 else
al@442 98 echo 'System clean up is disabled in /etc/rcS.conf'
al@442 99 fi
pankso@5 100
al@442 101 # Handle kernel cmdline parameter modprobe=<module_list>
al@442 102 if [ -n "$MODPROBE" ]; then
al@442 103 for i in $(cmdline_option modprobe | tr ',' '\n'); do
al@442 104 action 'Loading kernel module: %s' "$i"
al@442 105 modprobe $i
al@442 106 status
al@442 107 done
al@442 108 fi
pascal@276 109
al@442 110 # Handle kernel cmdline parameter config=<device>,<path> to source a
al@442 111 # disk init script
al@442 112 if [ -n "$CONFIG" ]; then
al@442 113 DEVICE=${CONFIG%,*}
al@442 114 SCRIPT=${CONFIG#*,}
al@442 115 echo "Probing $DEVICE..."
al@442 116 if ! mount -r $DEVICE /mnt; then
al@442 117 if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then
al@442 118 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
al@442 119 USBDELAY=$((1+$USBDELAY))
al@442 120 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
al@442 121 sleep $USBDELAY
al@442 122 fi
al@442 123 if ! mount -r $DEVICE /mnt; then
al@442 124 CONFIG=''
al@442 125 fi
al@442 126 fi
al@442 127 action 'Source %s from %s...' "$SCRIPT" "$DEVICE"
al@442 128 if [ -n "$CONFIG" ]; then
al@442 129 . /mnt/$SCRIPT
al@442 130 umount /mnt 2>/dev/null || true
al@442 131 fi
al@442 132 status
al@442 133 fi
pascal@41 134
al@442 135 # Mount /proc/bus/usb
al@442 136 if [ -d '/proc/bus/usb' ]; then
al@442 137 action 'Mounting usbfs filesystem on /proc/bus/usb'
al@442 138 mount -t usbfs usbfs /proc/bus/usb
al@442 139 status
al@442 140 fi
pankso@262 141
al@442 142 # Start syslogd and klogd
al@442 143 action 'Starting system log daemon: syslogd...'
al@442 144 syslogd -s $SYSLOGD_ROTATED_SIZE; status
al@442 145 action 'Starting kernel log daemon: klogd...'
al@442 146 klogd; status
pankso@15 147
al@442 148 # Load all modules listed in config file
al@442 149 if [ -n "$LOAD_MODULES" ]; then
al@442 150 colorize 33 'Loading Kernel modules...'
al@442 151 for mod in $LOAD_MODULES; do
al@442 152 action 'Loading module: %s' "$mod"
al@442 153 modprobe $mod
al@442 154 status
al@442 155 done
pascal@110 156 fi
al@442 157
al@442 158 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
al@442 159 # kernel modules only at first boot or in Live CD mode.
al@442 160 if [ ! -s '/var/lib/detected-modules' ]; then
al@442 161 tazhw init
pascal@110 162 fi
pankso@5 163
al@442 164 # Call udevadm trigger to ensure /dev is fully populated now that all
al@442 165 # modules are loaded.
al@442 166 if [ "$UDEV" == 'yes' ]; then
al@442 167 action 'Triggering udev events: --action=add'
al@442 168 udevadm trigger --action=add
al@442 169 status
al@442 170 fi
pascal@124 171
al@442 172 # Start all scripts specified with $RUN_SCRIPTS
al@442 173 for script in $RUN_SCRIPTS; do
al@442 174 colorize 34 "Processing /etc/init.d/$script"
al@442 175 /etc/init.d/$script
al@442 176 done
pankso@262 177
al@442 178 # Start X session. Dbus must be started before Xorg and other daemons.
al@442 179 # We started it here because X is run before RUN_DAEMONS. Sleep, in
al@442 180 # some live modes we boot too fast and X can't initialize.
al@442 181 if [ "$SCREEN" != 'text' -a \
al@442 182 -n "$LOGIN_MANAGER" -a \
al@442 183 -x '/usr/bin/tazx' -a \
al@442 184 -s '/etc/slitaz/applications.conf' -a \
al@442 185 -x "/etc/init.d/$LOGIN_MANAGER" ]; then
al@442 186 colorize 36 'Starting X environment...'
al@442 187 # We need Xorg 40-Keyboard.conf and SliTaz applications.conf
al@442 188 if [ ! -s '/etc/X11/xorg.conf.d/40-Keyboard.conf' ]; then
al@442 189 echo 'Configuring Xorg server...'
al@442 190 HOME='/root'
al@442 191 tazx init
al@442 192 fi
al@442 193 /etc/init.d/dbus start
al@442 194 (sleep 2; /etc/init.d/$LOGIN_MANAGER start >/dev/null) &
al@442 195 fi
pankso@5 196
al@442 197 # Start all daemons specified with $RUN_DAEMONS
al@442 198 if [ -n "$RUN_DAEMONS" ]; then
al@442 199 colorize 33 "Starting all daemons..."
al@442 200 for daemon in $RUN_DAEMONS; do
al@442 201 [ -x "/etc/init.d/$daemon" ] && /etc/init.d/$daemon start
al@442 202 done
al@442 203 fi
pankso@153 204
al@442 205 # Back to a verbose mode
al@442 206 (sleep 6; echo '7 4 1 7' > /proc/sys/kernel/printk) &
slaxemulator@260 207
al@442 208 if [ -n "$MESSAGE" ]; then
al@442 209 newline
al@442 210 colorize 32 "$MESSAGE"
al@442 211 fi
al@442 212 ;;
pankso@5 213
al@442 214 *)
al@442 215 # Main entry point.
al@442 216 # --> readonly --> readwrite
al@442 217 if [ ! -s '/run/boot.log' ]; then
al@442 218 # Mount /run as tmpfs runtime data are not written to disk
al@442 219 mount -t tmpfs tmpfs /run
al@442 220 # cp -a in tazpkg does not support /var/run symlink
al@442 221 mount --bind /run /var/run
al@442 222 fi
pankso@359 223
al@442 224 /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log
pankso@5 225
al@442 226 # Logrotate boot.log
al@442 227 last='.9'
al@442 228 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 ''; do
al@442 229 mv -f "/var/log/boot.log$i" "/var/log/boot.log$last" 2>/dev/null
al@442 230 last="$i"
al@442 231 done
al@442 232 mv -f /run/boot.log /var/log/boot.log
pankso@302 233
al@442 234 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log
al@442 235 ;;
pascal@276 236 esac