3 # /etc/rc.d/rc.sysinit - run once at boot time
4 # $Id: rc.sysinit,v 1.83 2001/07/05 15:47:39 baggins Exp $
6 # Taken in part from Miquel van Smoorenburg's bcheckrc.
7 # Changes: Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
11 PATH=/bin:/sbin:/usr/bin:/usr/sbin
15 if [ -r /etc/sysconfig/i18n ]; then
17 [ -n "$LANG" ] && export LANG || unset LANG
18 [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
19 [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
20 [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
21 [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
22 [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
23 [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
24 [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
25 [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
26 [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
30 . /etc/rc.d/init.d/functions
32 # Read network config data
33 if [ -r /etc/sysconfig/network ]; then
34 . /etc/sysconfig/network
40 # Read system config data
41 if [ -r /etc/sysconfig/system ]; then
42 . /etc/sysconfig/system
44 RUN_SULOGIN_ON_ERR=yes
55 # Print welcome message
56 nls "\t\t\t%sPowered by %sPLD GNU/Linux%s" "$(termput setaf 6)" "$(termput setaf 2)" "$(termput setaf 7)"
57 if is_yes "$PROMPT"; then
58 nls -n "\t\t Press %sI%s to enter interactive startup." "$(termput setaf 1)" "$(termput setaf 7)"
63 # We need /proc mounted before everything
64 mount -n -o gid=17 -t proc /proc /proc
66 # /dev must be also mounted before everything but only if we want use them ;-)
67 if is_yes "$MOUNT_DEVFS"; then
68 run_cmd "Mounting Device Filesystem" mount -n -t devfs /dev /dev
72 if is_yes "$RUN_DEVFSD"; then
73 if [ -x /sbin/devfsd -a -f /etc/devfsd.conf ]; then
74 run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
78 # Set console loglevel
79 /bin/dmesg -n $CONSOLE_LOGLEVEL
81 # Configure Linux kernel
82 run_cmd "Configuring kernel parameters" /sbin/sysctl -p /etc/sysctl.conf
84 # Set the system clock.
89 if [ -f /etc/sysconfig/clock ]; then
90 . /etc/sysconfig/clock
92 # convert old style clock config to new values
93 if [ "${CLOCKMODE}" = "GMT" ]; then
95 elif [ "${CLOCKMODE}" = "ARC" ]; then
100 if grep "system serial" /proc/cpuinfo | grep -q MILO ; then
105 CLOCKFLAGS="--hctosys"
109 CLOCKFLAGS="$CLOCKFLAGS --utc";
110 CLOCKDEF="$CLOCKDEF (utc)";
113 CLOCKFLAGS="$CLOCKFLAGS --localtime";
114 CLOCKDEF="$CLOCKDEF (local)";
120 CLOCKFLAGS="$CLOCKFLAGS -A";
121 CLOCKDEF="$CLOCKDEF (arc)";
126 CLOCKFLAGS="$CLOCKFLAGS -S";
127 CLOCKDEF="$CLOCKDEF (srm)";
131 # Check if timezone definition is available
132 if [ -e /etc/localtime ] ; then
133 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
134 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
137 TIME_SETUP_DELAYED=yes
141 run_cmd "Activating swap partitions" swapon -a
144 run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
146 # Set the NIS domain name
147 if [ -n "$NISDOMAIN" ]; then
148 run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
153 # Setup hdparm thing (if exists and is needed)
154 if ! grep -iq nohdparm /proc/cmdline; then
155 [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
158 if [ -f /fsckoptions ]; then
159 fsckoptions=$(cat /fsckoptions)
164 if [ -f /forcefsck ]; then
165 fsckoptions="-f $fsckoptions"
169 if awk '{ if ($2 ~ /^\/$/ && ( $3 ~ /^(nfs|romfs)$/ || $6 ~ /^0$/ ) ) exit 1 ; else exit 0}' /etc/fstab; then
171 if [ ! -f /fastboot ]; then
172 show "Checking root filesystem"; started
173 initlog -c "fsck -C -T -a $fsckoptions /"
177 # A return of 2 or higher means there were serious problems.
178 if [ $rc -gt 1 ]; then
179 # don't use '\n' in nls macro !
182 nls "*** An error occurred during the file system check."
183 nls "*** Dropping you to a shell; the system will reboot"
184 nls "*** when you leave the shell."
187 PS1="$(nls '(Repair filesystem)# ')"; export PS1
188 if is_yes "$RUN_SULOGIN_ON_ERR"; then
194 run_cmd "Unmounting file systems" umount -a
195 mount -n -o remount,ro /
196 run_cmd "Automatic reboot in progress" reboot
197 elif [ "$rc" = "1" ]; then
204 # Check for arguments
205 if grep -iq nopnp /proc/cmdline; then
212 if [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
213 if [ -n "$PNP" ] && is_yes "$RUN_ISAPNP"; then
214 run_cmd "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp/isapnp.conf
219 # Remount the root filesystem read-write
220 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
222 # Update quotas if fsck was run on /
223 if [ X"$_RUN_QUOTACHECK" = "X1" -a -x /sbin/quotacheck ]; then
224 run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vug /
227 # Remove /etc/nologin when starting system
228 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
230 if is_yes "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
231 show "Enabling Delay Login"; busy
233 nls "System bootup in progress - please wait" >> /etc/nologin
235 chmod 644 /etc/nologin
236 cp -fp /etc/nologin /etc/nologin.boot
240 # The root filesystem is now read-write, so we can now log via
241 # syslog() directly...
242 if [ -n "$IN_INITLOG" ]; then
249 # Write root and /proc to mtab
252 [ -f /proc/bus/usb/devices ] && mount -f -t usbdevfs usbdevfs /proc/bus/usb
254 if [ ! -f /proc/modules ]; then
256 elif ! grep -iq nomodules /proc/cmdline; then
262 # Kernel dependent links
263 rm -f /lib/modules/preferred
264 rm -f /lib/modules/default
265 if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
266 if is_yes "$SET_SLINKS"; then
267 # Get ready for kmod if module support in the kernel
268 if [ -z $(uname -r | grep "-") ]; then
269 # We're using a new kernel, no preferred needed
272 ktag="$(cat /proc/version)"
273 mtag=grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null
274 if [ -n "$mtag" ]; then
275 mver=$(echo $mtag | awk ' { gsub(/\/lib\/modules\//,NIL); gsub(/.rhkmvtag/,NIL); gsub(/[ ].*$/,NIL); print $0 } ')
277 if [ -n "$mver" ]; then
278 ln -sf /lib/modules/$mver /lib/modules/default
282 [ -n "$mver" -a -f "/boot/module-info-$mver" ] && \
283 ln -sf /boot/module-info-$mver /boot/module-info
284 [ -n "$mver" -a -f "/boot/System.map-$mver" ] && \
285 ln -sf /boot/System.map-$mver /boot/System.map
289 # Run depmod if RUN_DEPMOD != "no" and:
290 # a) user requested or RUN_DEPMOD="";
291 # b) modules.dep is missing
292 # c) modules.dep is older than /etc/modules.conf or /lib/modules/$mver
293 if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
294 if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ] || \
295 [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ] ||\
296 [ /lib/modules/$mver/modules.dep -ot /etc/modules.conf ] ||\
297 [ /lib/modules/$mver/modules.dep -ot /lib/modules/$mver ]; then
298 run_cmd "Finding module dependencies" depmod -a
302 if [ -f /proc/sys/kernel/modprobe ]; then
303 if [ -n "$USEMODULES" ]; then
304 sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
306 # We used to set this to NULL, but that causes
307 # 'failed to exec' messages"
308 sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
313 if [ -x /etc/rc.d/rc.modules ]; then
318 if [ -n "$USEMODULES" ] && is_yes "$LOAD_SOUND"; then
319 if grep -s -q "^alias sound-slot-0" /etc/modules.conf ; then
320 run_cmd "Loading sound module" modprobe -s sound-slot-0
322 if grep -s -q "^alias synth0" /etc/modules.conf ; then
323 run_cmd "Loading synthesiser module" modprobe -s synth0
328 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
332 for i in $(grep -v "^#" /etc/raidtab | grep "raiddev" | awk '{print $2}')
334 RAIDDEV=$(basename $i)
335 RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat)
336 show "Starting up RAID device %s" $RAIDDEV
338 if [ -z "$RAIDSTAT" ]; then
339 # Try raidstart first...if that fails then
340 # fall back to raid0run and if that fails too
341 # fall back to raidadd, raidrun.
343 if [ -x /sbin/raidstart ]; then
347 if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
351 if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
356 if [ $RESULT -gt 0 ]; then
367 # A non-zero return means there were problems
368 if [ $rc -gt 0 ]; then
369 show "Starting up RAID devices."; fail
372 nls "*** An error occurred during the RAID startup"
373 nls "*** Dropping you to a shell; the system will reboot"
374 nls "*** when you leave the shell."
377 PS1="$(nls '(RAID Repair)# ')"; export PS1
378 if is_yes "$RUN_SULOGIN_ON_ERR"; then
384 run_cmd "Unmounting file systems" umount -a
385 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
386 run_cmd "Automatic reboot in progress" reboot
388 show "Starting up RAID devices."; ok
391 # Find and activate volume groups
392 if [ -e /proc/lvm -a -x /sbin/vgscan -a -x /sbin/vgchange ]; then
393 run_cmd "Scanning for LVM volume groups" /sbin/vgscan && \
394 run_cmd "Activating LVM volume groups" /sbin/vgchange -a y
398 if ! grep -q nofsck /proc/cmdline && [ ! -f /fastboot ]; then
399 show "Checking filesystems"; started
400 initlog -c "fsck -C -T -R -A -a $fsckoptions"
404 # A return of 2 or higher means there were serious problems
405 if [ $rc -gt 1 ]; then
408 nls "*** An error occurred during the file system check."
409 nls "*** Dropping you to a shell; the system will reboot"
410 nls "*** when you leave the shell."
413 PS1="$(nls '(Repair filesystem)# ')"; export PS1
414 if is_yes "$RUN_SULOGIN_ON_ERR"; then
420 run_cmd "Unmounting file systems" umount -a
421 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
422 run_cmd "Automatic reboot in progress" reboot
423 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
424 if [ -x /sbin/convertquota ]; then
425 if [ -f /quota.user ]; then
426 /sbin/convertquota -u / && rm -f /quota.user
428 if [ -f /quota.group ]; then
429 /sbin/convertquota -g / && rm -f /quota.group
432 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -u -g -R -a
436 # Mount all other filesystems (except for NFS and /proc, which is already
437 # mounted). Contrary to standard usage,
438 # filesystems are NOT unmounted in single user mode.
440 # Don'n mount devpts if devfs is already mounted
441 if is_yes "$MOUNT_DEVFS"; then
442 run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc,devpts
444 run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc
447 # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
448 # before mount - that's where the password is entered.
449 # mount is buggy - when remounting loopback filesystem, loop=XXX
450 # option is removed from /etc/mtab
451 if grep -q "encryption=" /etc/fstab; then
452 show "Checking encrypted filesystems"; started
454 grep "encryption=" /etc/fstab | grep -v 'noauto' | grep -w 'ro' |\
455 while read FILE DIR TYPE OPTS TMP1; do
456 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
459 grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
460 while read FILE DIR TYPE OPTS TMP1; do
461 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
462 LOOPLIST="$LOOPLIST $LOOP"
463 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,ro"
465 mount "$DIR" -o "$NEWOPTS"
469 initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
472 # A return of 2 or higher means there were serious problems.
473 if [ $rc -gt 1 ]; then
475 nls "*** An error occurred during the file system check."
476 nls "*** Dropping you to a shell; the system will reboot"
477 nls "*** when you leave the shell."
480 PS1="`nls '(Repair filesystem)# '`"; export PS1
481 if is_yes "$RUN_SULOGIN_ON_ERR"; then
487 run_cmd "Unmounting file systems" umount -a
488 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
489 run_cmd "Automatic reboot in progress." reboot
492 show "Remounting encrypted filesystems back in rw mode"; busy
493 grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
494 while read FILE DIR TYPE OPTS TMP1; do
495 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
496 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,rw"
497 mount "$DIR" -o "$NEWOPTS"
502 # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
503 if is_yes "$TIME_SETUP_DELAYED"; then
504 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
505 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
509 if [ -x /sbin/quotaon ]; then
510 run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
513 # Initialize the serial ports
514 if [ -f /etc/rc.d/rc.serial ]; then
515 . /etc/rc.d/rc.serial
518 if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
519 show 'Setting %s seconds for kernel reboot after panic.' "$PANIC_REBOOT_TIME"; busy
520 if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME 2> /dev/null); then ok; else fail; fi
523 # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}
524 rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
529 if ! is_no "$NEED_XFILES" ; then
532 chown root.utmp /var/run/utmpx /var/log/wtmpx
533 chmod 0664 /var/run/utmpx /var/log/wtmpx
537 chown root.utmp /var/run/utmp /var/log/wtmp
538 chmod 0664 /var/run/utmp /var/log/wtmp
542 if is_yes "$CLEAN_TMP"; then
546 # Delete UUCP lock files
549 # Delete stale subsystem files
550 rm -f /var/lock/subsys/*
552 # Delete stale pam_console locks
553 rm -f /var/lock/console/*
554 rm -f /var/lock/console.lock
556 # Delete stale pid files
558 rm -f /var/spool/postoffice/.pid.*
563 # Delete Postgres sockets
564 rm -f /tmp/.s.PGSQL.*
566 # Right, now turn on swap in case we swap to files
567 swapon -a >/dev/null 2>&1
568 run_cmd "Enabling swap space" /bin/true
570 # If a SCSI tape has been detected, load the st module unconditionally
571 # since many SCSI tapes don't deal well with st being loaded and unloaded
572 if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type: Sequential-Access' 2>/dev/null ; then
573 if cat /proc/devices | grep -qv ' 9 st' ; then
574 if [ -n "$USEMODULES" ] ; then
575 # Try to load the module. If it fails, ignore it...
576 insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
581 # There could be a new kernel version. Remove old psdevtab database
584 # Now that we have all of our basic modules loaded and the kernel going,
585 # let's dump the syslog ring somewhere so we can find it later
586 dmesg > /var/log/dmesg
587 chmod 640 /var/log/dmesg
589 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
591 if is_yes "$PROMPT"; then
592 /sbin/getkey i && touch /var/run/confirm
597 # This must be last line !
598 # vi:syntax=sh:tw=78:ts=8:sw=4