slitaz-boot-scripts annotate etc/init.d/rcS @ rev 453

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