3 # /etc/rc.d/rc.sysinit - run once at boot time
4 # $Id: rc.sysinit,v 1.69.2.10 2001/07/05 21:07:14 misiek Exp $
6 # Taken in part from Miquel van Smoorenburg's bcheckrc.
7 # Changes: Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
10 # Rerun ourselves through initlog
11 if [ -z "$IN_INITLOG" ]; then
12 [ -f /sbin/initlog ] && exec /sbin/initlog -r /etc/rc.d/rc.sysinit
16 PATH=/bin:/sbin:/usr/bin:/usr/sbin
20 if [ -r /etc/sysconfig/i18n ]; then
22 [ -n "$LANG" ] && export LANG || unset LANG
23 [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
24 [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
25 [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
26 [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
27 [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
28 [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
29 [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
30 [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
31 [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
35 . /etc/rc.d/init.d/functions
37 # Read network config data.
38 if [ -r /etc/sysconfig/network ]; then
39 . /etc/sysconfig/network
45 # Read system config data.
46 if [ -r /etc/sysconfig/system ]; then
47 . /etc/sysconfig/system
49 RUN_SULOGIN_ON_ERR=yes
60 # Print welcome message
61 nls "\t\t\t%sPowered by %sPLD GNU/Linux%s" "$(termput setaf 6)" "$(termput setaf 2)" "$(termput setaf 7)"
62 if is_yes "$PROMPT"; then
63 nls -n "\t\t Press %sI%s to enter interactive startup." "$(termput setaf 1)" "$(termput setaf 7)"
68 # we need /proc mounted before everything
69 mount -n -o gid=17 -t proc /proc /proc
71 # /dev must be also mounted before everything but only if we want use them ;-)
72 if is_yes "$MOUNT_DEVFS"; then
73 run_cmd "Mounting Device Filesystem" mount -n -t devfs /dev /dev
77 if [ -c /dev/.devfsd -a -x /sbin/devfsd ]; then
78 run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
79 if [ -e /dev/cdroms/cdrom0 ]; then
80 ln -sf /dev/cdroms/cdrom0 /dev/cdrom
82 if [ -f /etc/sysconfig/mouse ]; then
83 . /etc/sysconfig/mouse
84 if [ -n "$DEVICE" -a "$DEVICE" != "/dev/mouse" ]; then
85 ln -s $DEVICE /dev/mouse
90 # Set console loglevel
91 /bin/dmesg -n $CONSOLE_LOGLEVEL
93 # Configure Linux kernel
94 run_cmd "Configuring kernel parameters" /sbin/sysctl -p /etc/sysctl.conf
96 # Set the system clock.
101 if [ -f /etc/sysconfig/clock ]; then
102 . /etc/sysconfig/clock
104 # convert old style clock config to new values
105 if [ "${CLOCKMODE}" = "GMT" ]; then
107 elif [ "${CLOCKMODE}" = "ARC" ]; then
112 if grep "system serial" /proc/cpuinfo | grep -q MILO ; then
117 CLOCKFLAGS="--hctosys"
121 CLOCKFLAGS="$CLOCKFLAGS --utc";
122 CLOCKDEF="$CLOCKDEF (utc)";
125 CLOCKFLAGS="$CLOCKFLAGS --localtime";
126 CLOCKDEF="$CLOCKDEF (local)";
132 CLOCKFLAGS="$CLOCKFLAGS -A";
133 CLOCKDEF="$CLOCKDEF (arc)";
138 CLOCKFLAGS="$CLOCKFLAGS -S";
139 CLOCKDEF="$CLOCKDEF (srm)";
143 # Check if timezone definition is available
144 if [ -e /etc/localtime ] ; then
145 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
146 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
149 TIME_SETUP_DELAYED=yes
153 run_cmd "Activating swap partitions" swapon -a
156 run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
158 # Set the NIS domain name
159 if [ -n "$NISDOMAIN" ]; then
160 run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
165 # Initialize USB controller and HID devices
167 if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && ! grep -q "usb" /proc/devices 2>/dev/null ; then
168 aliases=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+usb-controller" | awk '{ print $3 }')
169 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
170 /sbin/modprobe -k usbcore
171 run_cmd "Mounting USB filesystem" mount -t usbdevfs usbdevfs /proc/bus/usb
172 for alias in $aliases ; do
173 run_cmd "$(nls 'Initializing USB controller') ($alias)" /sbin/modprobe $alias
175 [ $? -eq 0 -a -n "$aliases" ] && usb=1
179 if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && grep -q "usb" /proc/devices 2>/dev/null ; then
184 if [ $usb = "1" ]; then
186 mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02")
187 kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01")
188 needusbstorage=$(cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08")
189 if [ -n "$kbdoutput" ] || [ -n "$mouseoutput" ]; then
190 run_cmd "Initializing USB HID interface" modprobe hid 2> /dev/null
192 if [ -n "$kbdoutput" ]; then
193 run_cmd "Initializing USB keyboard" modprobe keybdev
195 if [ -n "$mouseoutput" ]; then
196 run_cmd "Initializing USB mouse" modprobe mousedev
200 if [ -f /fastboot ] || grep -iq "fastboot" /proc/cmdline 2> /dev/null ; then
206 if [ -f /fsckoptions ]; then
207 fsckoptions=$(cat /fsckoptions)
212 if [ -f /forcefsck ]; then
213 fsckoptions="-f $fsckoptions"
216 if is_yes "$COLOR_INIT"; then
217 fsckoptions="-C $fsckoptions"
219 fsckoptions="-V $fsckoptions"
223 _ROOTFS_TYPE=$(grep " / " /proc/mounts | awk '{ print $3 }')
225 if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" ]; then
226 show "Checking root filesystems."; started
227 initlog -c "fsck -T -a $fsckoptions /"
231 # A return of 2 or higher means there were serious problems.
232 if [ $rc -gt 1 ]; then
233 # don't use '\n' in nls macro !
236 nls "*** An error occurred during the file system check."
237 nls "*** Dropping you to a shell; the system will reboot"
238 nls "*** when you leave the shell."
241 PS1="$(nls '(Repair filesystem)# ')"; export PS1
242 if is_yes "$RUN_SULOGIN_ON_ERR"; then
248 run_cmd "Unmounting file systems" umount -a
249 mount -n -o remount,ro /
250 run_cmd "Automatic reboot in progress." reboot
251 elif [ "$rc" = "1" ]; then
256 # check for arguments
257 if grep -iq nopnp /proc/cmdline; then
263 # set up pnp and kernel pnp
264 if [ -n "$PNP" ]; then
265 if [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ] && is_yes "$RUN_ISAPNP"; then
266 run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
268 if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
269 show "Setting up ISA PNP devices (kernelspace pnp)"; busy
270 cat /etc/isapnp/isapnp-kernel.conf > /proc/isapnp && (deltext; ok) || (deltext; fail)
274 # Remount the root filesystem read-write.
275 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
277 # Find and activate volume groups
278 if [ -e /proc/lvm -a -x /sbin/vgscan -a -x /sbin/vgchange -a -e /etc/lvmtab ]; then
279 run_cmd "Scanning for LVM volume groups" /sbin/vgscan && \
280 run_cmd "Activating LVM volume groups" /sbin/vgchange -a y
286 # Remove stale backups
287 rm -f /etc/mtab~ /etc/mtab~~
289 # Enter root, /proc and (potentially) /proc/bus/usb and devfs into mtab.
292 [ -f /proc/bus/usb/devices ] && mount -f -t usbdevfs usbdevfs /proc/bus/usb
293 [ -e /dev/.devfsd ] && mount -f -t devfs devfs /dev
296 # Setup hdparm thing (if exists and is needed)
297 if ! grep -iq nohdparm /proc/cmdline; then
298 [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
301 # Update quotas if fsck was run on /.
302 if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
303 if [ -x /sbin/convertquota ]; then
304 if [ -f /quota.user ]; then
305 /sbin/convertquota -u / && rm -f /quota.user
307 if [ -f /quota.group ]; then
308 /sbin/convertquota -g / && rm -f /quota.group
311 run_cmd "Checking root filesystem quotas" /sbin/quotacheck -v /
314 # /etc/nologin when starting system
315 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
317 if is_yes "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
318 show "Enabling Delay Login"; busy
320 nls "System bootup in progress - please wait" >> /etc/nologin
322 chmod 644 /etc/nologin
323 cp -fp /etc/nologin /etc/nologin.boot
327 # The root filesystem is now read-write, so we can now log via
328 # syslog() directly..
329 if [ -n "$IN_INITLOG" ]; then
333 echo ${HOSTNAME} > /etc/HOSTNAME
335 if [ ! -f /proc/modules ]; then
337 elif ! grep -iq nomodules /proc/cmdline; then
343 # Kernel dependent links
344 rm -f /lib/modules/preferred
345 rm -f /lib/modules/default
346 if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
347 if is_yes "$SET_SLINKS"; then
348 # Get ready for kmod if module support in the kernel
349 if [ -z $(uname -r | grep "-") ]; then
350 # we're using a new kernel, no preferred needed
353 ktag="$(cat /proc/version)"
354 mtag=grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null
355 if [ -n "$mtag" ]; then
356 mver=$(echo $mtag | awk ' { gsub(/\/lib\/modules\//,NIL); gsub(/.rhkmvtag/,NIL); gsub(/[ ].*$/,NIL); print $0 } ')
358 if [ -n "$mver" ]; then
359 ln -sf /lib/modules/$mver /lib/modules/default
363 [ -n "$mver" -a -f "/boot/module-info-$mver" ] && \
364 ln -sf /boot/module-info-$mver /boot/module-info
365 [ -n "$mver" -a -f "/boot/System.map-$mver" ] && \
366 ln -sf /boot/System.map-$mver /boot/System.map
370 # Run depmod if RUN_DEPMOD != "no" and:
371 # a) user requested or RUN_DEPMOD="";
372 # b) modules.dep is missing
373 # c) modules.dep is older than /etc/modules.conf or /lib/modules/$mver
375 if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
376 is_yes "$RUN_DEPMOD" && _RUN_DEPMOD=1
377 [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ] && _RUN_DEPMOD=1
378 [ /lib/modules/$mver/modules.dep -ot /etc/modules.conf ] && _RUN_DEPMOD=1
379 [ /lib/modules/$mver/modules.dep -ot /lib/modules/$mver ] && _RUN_DEPMOD=1
382 if [ "$_RUN_DEPMOD" = "1" ]; then
383 run_cmd "Finding module dependencies" depmod -a
386 # Load sound modules iff they need persistent DMA buffers
387 if grep -q "options sound dmabuf=1" /etc/modules.conf 2>/dev/null ; then
389 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound[[:space:]]+" | awk '{ print $3 }')
390 if [ -n "$alias" -a "$alias" != "off" ] ; then
391 run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -k $alias
394 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound-slot-0[[:space:]]+" | awk '{ print $3 }')
395 if [ -n "$alias" -a "$alias" != "off" ] ; then
396 run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -k $alias
401 if [ -f /proc/sys/kernel/modprobe ]; then
402 if [ -n "$USEMODULES" ]; then
403 sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
404 sysctl -w kernel.hotplug="/sbin/hotplug" >/dev/null 2>&1
406 # We used to set this to NULL, but that causes
407 # 'failed to exec' messages"
408 sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
409 sysctl -w kernel.hotplug="/bin/true" >/dev/null 2>&1
414 if [ -x /etc/rc.d/rc.modules ]; then
419 if [ ! -f /proc/mdstat ]; then
420 modprobe -k md >/dev/null 2>&1
424 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
428 for i in $(grep -v "^#" /etc/raidtab | grep "raiddev" | awk '{print $2}')
430 RAIDDEV=$(basename $i)
431 RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat)
432 show "Starting up RAID device %s" $RAIDDEV
434 if [ -z "$RAIDSTAT" ]; then
435 # Try raidstart first...if that fails then
436 # fall back to raid0run and if that fails, too
437 # fall back to raidadd, raidrun.
439 if [ -x /sbin/raidstart ]; then
443 if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
447 if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
452 if [ $RESULT -gt 0 ]; then
463 # A non-zero return means there were problems.
464 if [ $rc -gt 0 ]; then
465 show "Starting up RAID devices."; fail
468 nls "*** An error occurred during the RAID startup"
469 nls "*** Dropping you to a shell; the system will reboot"
470 nls "*** when you leave the shell."
473 PS1="$(nls '(RAID Repair)# ')"; export PS1
474 if is_yes "$RUN_SULOGIN_ON_ERR"; then
480 run_cmd "Unmounting file systems" umount -a
481 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
482 run_cmd "Automatic reboot in progress" reboot
484 show "Starting up RAID devices."; ok
489 if [ -z "$fastboot" ] && ! grep -q nofsck /proc/cmdline; then
490 show "Checking filesystems"; started
491 initlog -c "fsck -T -R -A -a $fsckoptions"
495 # A return of 2 or higher means there were serious problems.
496 if [ $rc -gt 1 ]; then
499 nls "*** An error occurred during the file system check."
500 nls "*** Dropping you to a shell; the system will reboot"
501 nls "*** when you leave the shell."
504 PS1="$(nls '(Repair filesystem)# ')"; export PS1
505 if is_yes "$RUN_SULOGIN_ON_ERR"; then
511 run_cmd "Unmounting file systems" umount -a
512 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
513 run_cmd "Automatic reboot in progress." reboot
514 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
519 # Mount all other filesystems (except for NFS and /proc, which is already
520 # mounted). Contrary to standard usage,
521 # filesystems are NOT unmounted in single user mode.
522 run_cmd "Mounting local filesystems." mount -a -t nonfs,smbfs,ncpfs
524 if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
525 if [ -x /sbin/convertquota ]; then
526 # try to convert old quotas
527 for mountpt in $(cat /etc/mtab | awk '$4 ~ /quota/{print $2}'); do
528 if [ -f "$mountpt/quota.user" ]; then
529 /sbin/convertquota -u $mountpt && \
530 rm -f $mountpt/quota.user
532 if [ -f "$mountpt/quota.group" ]; then
533 /sbin/convertquota -g $mountpt && \
534 rm -f $mountpt/quota.group
538 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -R -a
542 if [ -x /sbin/quotaon ]; then
543 run_cmd "Turning on user and group quotas for local filesystems" /sbin/quotaon -a
546 # Turn on process accounting
547 if [ -x /sbin/accton ] ; then
548 run_cmd "Turning on process accounting" /sbin/accton /var/log/pacct
551 # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
552 if is_yes "$TIME_SETUP_DELAYED"; then
553 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
554 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
558 # Initialize the serial ports.
559 if [ -f /etc/rc.d/rc.serial ]; then
560 . /etc/rc.d/rc.serial
563 if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
564 show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
565 if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME 2> /dev/null); then ok; else fail; fi
569 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff
572 # I'd use find, but /usr may not be mounted.
573 for afile in /var/lock/* /var/run/*; do
574 if [ -d "$afile" ]; then
575 bafile=$(basename $afile)
576 [ "$bafile" != "news" -a "$bafile" != "sudo" -a "$bafile" != "mon" ] && rm -f $afile/*
585 if ! is_no "$NEED_XFILES" ; then
588 chown root.utmp /var/run/utmpx /var/log/wtmpx
589 chmod 0664 /var/run/utmpx /var/log/wtmpx
593 chown root.utmp /var/run/utmp /var/log/wtmp
594 chmod 0664 /var/run/utmp /var/log/wtmp
598 if is_yes "$CLEAN_TMP"; then
605 # Delete Postgres sockets
606 rm -f /tmp/.s.PGSQL.*
608 # Right, now turn on swap in case we swap to files.
609 swapon -a >/dev/null 2>&1
610 run_cmd "Enabling swap space" /bin/true
612 # If a SCSI tape has been detected, load the st module unconditionally
613 # since many SCSI tapes don't deal well with st being loaded and unloaded
614 if [ -f /proc/scsi/scsi ] && grep -q 'Type: Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
615 if grep -qv ' 9 st' /proc/devices ; then
616 if [ -n "$USEMODULES" ] ; then
617 # Try to load the module. If it fails, ignore it...
618 insmod -p st >/dev/null 2>&1 && modprobe st >/dev/null 2>&1
623 # Load usb storage here, to match most other things
624 if [ -n "$needusbstorage" ]; then
625 modprobe usb-storage >/dev/null 2>&1
628 # If they asked for ide-scsi, load it
629 if grep -q "ide-scsi" /proc/cmdline ; then
630 modprobe -k ide-cd >/dev/null 2>&1
631 modprobe -k ide-scsi >/dev/null 2>&1
634 # Adjust symlinks as necessary in /boot to keep system services from
635 # spewing messages about mismatched System maps and so on.
636 if [ -L /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
637 ln -s -f System.map-`uname -r` /boot/System.map
639 if [ ! -e /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
640 ln -s -f System.map-`uname -r` /boot/System.map
643 # there could be a new kernel version. remove old psdevtab database
646 # Now that we have all of our basic modules loaded and the kernel going,
647 # let's dump the syslog ring somewhere so we can find it later
648 dmesg > /var/log/dmesg
649 chmod 640 /var/log/dmesg
652 # Now that we have all of our basic modules loaded and the kernel going,
653 # let's dump the syslog ring somewhere so we can find it later
654 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
656 if is_yes "$PROMPT"; then
657 /sbin/getkey i && touch /var/run/confirm
662 # This must be last line !
663 # vi:syntax=sh:tw=78:ts=8:sw=4