3 # Copyright (c) 2000 The FreeBSD Project
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # @(#)rc 5.27 (Berkeley) 6/5/91
31 # System startup script run by init on autoboot
32 # or after single-user.
33 # Output and error are redirected to console by init,
34 # and the console is the controlling terminal.
36 # Note that almost all of the user-configurable behavior is no longer in
37 # this file, but rather in /etc/defaults/rc.conf. Please check that file
38 # first before contemplating any changes here. If you do need to change
39 # this file for some reason, we would like to know about it.
43 # Set shell to ignore SIGINT (2), but not children;
44 # shell catches SIGQUIT (3) and returns to single user after fsck.
47 trap : 3 # shouldn't be needed
50 PATH=/sbin:/bin:/usr/sbin:/usr/bin
53 # If there is a global system configuration file, suck it in.
54 # XXX - The only purpose of duplicating it here is to catch rc_ng="YES"
56 if [ -r /etc/defaults/rc.conf ]; then
57 . /etc/defaults/rc.conf
59 elif [ -r /etc/rc.conf ]; then
63 # Diskless setups have to depend on a different mechanism since
64 # their config files haven't been retargeted yet.
66 [ -e /.rcng_yes ] && rc_ng="YES"
72 # Load system configuration files. The 'XXX' is there because
73 # the function requires an argument that we don't need to use.
77 if [ "$1" = autoboot ]; then
80 rc_fast=yes # run_rc_command(): do fast booting
86 os=`eval ${CMD_OSTYPE}`
87 files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null`
89 for _rc_elem in ${files}; do
90 run_rc_script ${_rc_elem} ${_boot}
91 # Local FreeBSD hack to reload the rc.conf on
92 # a return status of 2
96 echo "Reloading rc.conf"
105 # fall-through to the old rc scripts
111 # BOOTP diskless boot. We have to run the rc file early in order to
112 # retarget various config files.
114 if [ -r /etc/rc.diskless1 ]; then
115 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
116 if [ ${dlv:=0} != 0 ]; then
121 # If there is a global system configuration file, suck it in.
123 if [ -r /etc/defaults/rc.conf ]; then
124 . /etc/defaults/rc.conf
126 elif [ -r /etc/rc.conf ]; then
130 # XXX - Deprecated variable name support
131 # for rpcbind and ntpd
133 [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable"
134 [ -n "$portmap_program" ] && rpcbind_program="$portmap_program"
135 [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags"
136 [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable"
137 [ -n "$xntpd_enable" ] && ntpd_enable="$xntpd_enable"
138 [ -n "$xntpd_program" ] && ntpd_program="$xntpd_program"
139 [ -n "$xntpd_flags" ] && ntpd_flags="$xntpd_flags"
142 if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
143 # echo "Using ${1} as an entropy file"
144 cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
154 eval svc_val=\${$svc_var}
155 eval dep_val=\${$dep_var}
163 eval ${dep_var}="YES"
164 echo "DEPENDENCY NOTE: ${dep} will be enabled" \
172 chkdepend amd amd_enable rpcbind rpcbind_enable
173 chkdepend amd amd_enable NFS nfs_client_enable
174 chkdepend NFS nfs_server_enable rpcbind rpcbind_enable
175 chkdepend NIS nis_server_enable rpcbind rpcbind_enable
176 chkdepend NIS nis_client_enable rpcbind rpcbind_enable
178 # Enable dumpdev early so that a crash during the boot process can be caught.
185 /sbin/dumpon -v ${dumpdev}
189 # Enable harvesting of entropy via devices. The sooner this happens the
190 # better so that we can take advantage of the boot process.
192 echo -n 'Entropy harvesting:'
194 case ${harvest_interrupt} in
198 if [ -w /dev/random ]; then
199 /sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null
200 echo -n ' interrupts'
205 case ${harvest_ethernet} in
209 if [ -w /dev/random ]; then
210 /sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null
216 case ${harvest_p_to_p} in
220 if [ -w /dev/random ]; then
221 /sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null
222 echo -n ' point_to_point'
229 # First pass at reseeding /dev/random.
231 case ${entropy_file} in
235 if [ -w /dev/random ]; then
236 feed_dev_random "${entropy_file}"
241 # XXX temporary until we can get the entropy
243 # Entropy below is not great,
244 # but better than nothing.
245 ( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \
246 | dd of=/dev/random bs=8k 2>/dev/null
247 cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
249 # Configure ccd devices.
251 if [ -r /etc/ccd.conf ]; then
255 case ${start_vinum} in
263 # Last chance to do things before potentially waiting for
264 # operator to do fsck related tasks
265 if [ -r /etc/rc.early ]; then
271 echo 'Automatic boot in progress...'
272 case ${background_fsck} in
288 echo 'Reboot failed... help!'
292 case ${fsck_y_enable} in
294 echo 'File system preen failed, trying fsck -y . . .'
300 echo 'Automatic filesystem check failed . . . help!'
306 echo 'Automatic filesystem check failed . . . help!'
312 echo 'Reboot interrupted'
316 # interrupt before catcher installed
320 echo 'Unknown error in reboot'
326 echo 'Skipping disk checks ...'
331 trap "echo 'Reboot interrupted'; exit 1" 3
333 # root normally must be read/write, but if this is a BOOTP NFS
334 # diskless boot it does not have to be.
336 case ${root_rw_mount} in
340 if ! mount -u -o rw / ; then
341 echo 'Mounting root filesystem rw failed, startup aborted'
347 umount -a >/dev/null 2>&1
349 # Set up the list of network filesystem types for which mounting should be
350 # delayed until after network initialization.
351 networkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL'
352 case ${extra_netfs_types} in
356 networkfs_types="${networkfs_types} ${extra_netfs_types}"
360 # Mount everything except nfs filesystems.
362 for i in ${networkfs_types}; do
364 mount_excludes="${mount_excludes}${fstype},"
366 mount_excludes=${mount_excludes%,}
367 mount -a -t ${mount_excludes}
373 echo 'Mounting /etc/fstab filesystems failed, startup aborted'
378 # Run custom disk mounting function here
380 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
384 # If we booted a special kernel remove the record so we will boot
385 # the default kernel next time
386 rm -f /boot/nextboot.conf
388 # Reseed /dev/random with previously stored entropy.
389 case ${entropy_dir} in
393 entropy_dir=${entropy_dir:-/var/db/entropy}
394 if [ -d "${entropy_dir}" ]; then
395 if [ -w /dev/random ]; then
396 for seedfile in ${entropy_dir}/*; do
397 feed_dev_random "${seedfile}"
404 case ${entropy_file} in
408 if [ -w /dev/random ]; then
409 feed_dev_random "${entropy_file}"
419 if [ $# -eq 0 ]; then
425 cd "$dir" && for file in .* *
427 [ ."$file" = .. -o ."$file" = ... ] && continue
428 if [ -d "$file" -a ! -L "$file" ]
441 if [ -d /var/run -a ! -f /var/run/clean_var ]; then
443 # Keep a copy of the boot messages around
444 dmesg >/var/run/dmesg.boot
445 # And an initial utmp file
446 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
449 if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
450 purgedir /var/spool/lock
451 >/var/spool/lock/clean_var
453 rm -rf /var/spool/uucp/.Temp/*
456 # network_pass1() *may* end up writing stuff to /var - we don't want to
457 # remove it immediately afterwards - *nor* do we want to fail to clean
458 # an NFS-mounted /var.
459 rm -f /var/run/clean_var /var/spool/lock/clean_var
462 # Add additional swapfile, if configured.
468 if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
469 echo "Adding ${swapfile} as additional swap"
470 mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
475 # Early pass to set the variables we can
477 if [ -r /etc/rc.sysctl ]; then
478 sh /etc/rc.sysctl first
481 # Configure serial devices
483 if [ -r /etc/rc.serial ]; then
487 # Start up PC-card configuration
489 if [ -r /etc/rc.pccard ]; then
493 # Start up the initial network configuration.
495 if [ -r /etc/rc.network ]; then
496 . /etc/rc.network # We only need to do this once.
500 case ${ipv6_enable} in
502 if [ -r /etc/rc.network6 ]; then
503 . /etc/rc.network6 # We only need to do this once also.
509 # Mount NFS filesystems if present in /etc/fstab
511 # XXX When the vfsload() issues with nfsclient support and related sysctls
512 # have been resolved, this block can be removed, and the condition that
513 # skips nfs in the following block (for "other network filesystems") can
515 case "`mount -d -a -t nfs 2> /dev/null`" in
517 # Handle absent nfs client support
518 nfsclient_in_kernel=0
519 if sysctl vfs.nfs >/dev/null 2>&1; then
520 nfsclient_in_kernel=1
522 kldload nfsclient && nfsclient_in_kernel=1
525 case ${nfsclient_in_kernel} in
527 echo -n 'Mounting NFS filesystem:'
532 echo 'Warning: nfs mount requested, but no nfs client in kernel'
538 # Mount other network filesystems if present in /etc/fstab
539 for i in ${networkfs_types}; do
543 if [ "${fstype}" = "nfs" ]; then
546 case "`mount -d -a -t ${fstype}`" in
548 echo -n "Mounting ${fsdecr} filesystems:"
549 mount -a -t ${fstype}
555 # Whack the pty perms back into shape.
557 if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
558 chflags 0 /dev/tty[pqrsPQRS]*
559 chmod 666 /dev/tty[pqrsPQRS]*
560 chown root:wheel /dev/tty[pqrsPQRS]*
563 # Clean up left-over files
565 clean_var # If it hasn't already been done
566 rm /var/run/clean_var /var/spool/lock/clean_var
568 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
569 # help in any way for long-living systems, and it might accidentally
570 # clobber files you would rather like to have preserved after a crash
571 # (if not using mfs /tmp anyway).
573 # See also the example of another cleanup policy in /etc/periodic/daily.
575 case ${clear_tmp_enable} in
577 echo -n 'Clearing /tmp:'
578 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
579 # (not needed with mfs /tmp, but doesn't hurt there...)
580 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
581 find -d . ! -name . ! -name lost+found ! -name quota.user \
582 ! -name quota.group -exec rm -rf -- {} \;)
587 # Remove X lock files, since they will prevent you from restarting X11
588 # after a system crash.
591 rm -fr /tmp/.X11-unix
592 mkdir -m 1777 /tmp/.X11-unix
594 # Snapshot any kernel -c changes back to disk here <someday>.
595 # This has changed with ELF and /kernel.config.
597 # Load LOMAC(4) security if wanted.
598 case ${lomac_enable} in
600 kldload lomac >/dev/null 2>&1
604 echo -n 'Additional daemons:'
606 # Start system logging and name service. Named needs to start before syslogd
607 # if you don't have a /etc/resolv.conf.
609 case ${syslogd_enable} in
611 # Transitional symlink (for the next couple of years :) until all
612 # binaries have had a chance to move towards /var/run/log.
613 if [ ! -L /dev/log ]; then
614 # might complain for r/o root f/s
615 ln -sf /var/run/log /dev/log
620 ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
626 # Build device name databases if we are not using DEVFS
628 if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
629 rm -f /var/run/dev.db
634 # $dumpdir should be a directory or a symbolic link
635 # to the crash directory if core dumps are to be saved.
637 if [ "${dumpdev}" != 'NO' ]; then
647 if [ "${dumpdir}" != 'NO' ]; then
648 echo -n 'Checking for core dump: '
649 /sbin/savecore ${savecore_flags} "${dumpdir}"
653 if [ -n "${network_pass1_done}" ]; then
657 # Enable/Check the quotas (must be after ypbind if using NIS)
659 case ${enable_quotas} in
661 case ${check_quotas} in
663 echo -n 'Checking quotas:'
669 echo -n 'Enabling quotas:'
675 if [ -n "${network_pass2_done}" ]; then
679 # Check the password temp/lock file
681 if [ -e /etc/ptmp ]; then
682 logger -s -p auth.err \
683 "password file may be incorrect -- /etc/ptmp exists"
686 case ${accounting_enable} in
688 if [ -d /var/account ]; then
689 echo 'Turning on accounting:'
690 if [ ! -e /var/account/acct ]; then
691 touch /var/account/acct
693 accton /var/account/acct
698 # Make shared lib searching a little faster. Leave /usr/lib first if you
699 # add your own entries or you may come to grief.
701 ldconfig="/sbin/ldconfig"
702 case ${ldconfig_insecure} in
704 ldconfig="${ldconfig} -i"
707 if [ -x /sbin/ldconfig ]; then
709 for i in ${ldconfig_paths}; do
710 if [ -d "${i}" ]; then
714 echo 'ELF ldconfig path:' ${_LDC}
717 # Legacy aout support for i386 only
718 case `sysctl -n hw.machine_arch` in
720 # Default the a.out ldconfig path.
721 : ${ldconfig_paths_aout=${ldconfig_paths}}
723 for i in ${ldconfig_paths_aout}; do
724 if [ -d "${i}" ]; then
728 echo 'a.out ldconfig path:' ${_LDC}
729 ${ldconfig} -aout ${_LDC}
734 # Now start up miscellaneous daemons that don't belong anywhere else
736 echo -n 'Starting standard daemons:'
737 case ${inetd_enable} in
741 echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
745 case ${cron_enable} in
749 echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags}
753 case ${lpd_enable} in
755 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
759 case ${sshd_enable} in
761 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
763 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
768 case ${usbd_enable} in
770 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
774 case ${mta_start_script} in
776 if [ -r ${mta_start_script} ]; then
777 sh ${mta_start_script}
784 # Recover vi editor files.
785 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
786 vibackup=`echo /var/tmp/vi.recover/vi.*`
787 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
788 echo -n 'Recovering vi editor sessions:'
789 for i in /var/tmp/vi.recover/vi.*; do
790 # Only test files that are readable.
791 if [ ! -r "${i}" ]; then
795 # Unmodified nvi editor backup files either have the
796 # execute bit set or are zero length. Delete them.
797 if [ -x "${i}" -o ! -s "${i}" ]; then
802 # It is possible to get incomplete recovery files, if the editor
803 # crashes at the right time.
804 virecovery=`echo /var/tmp/vi.recover/recover.*`
805 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
806 for i in /var/tmp/vi.recover/recover.*; do
807 # Only test files that are readable.
808 if [ ! -r "${i}" ]; then
812 # Delete any recovery files that are zero length,
813 # corrupted, or that have no corresponding backup file.
814 # Else send mail to the user.
815 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
816 if [ -n "${recfile}" -a -s "${recfile}" ]; then
826 # Make a bounds file for msgs(1) if there isn't one already
828 if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
829 echo 0 > /var/msgs/bounds
832 case ${update_motd} in
836 if T=`mktemp /tmp/_motd.XXXXXX`; then
837 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
838 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
839 cmp -s ${T} /etc/motd || {
848 # Run rc.devfs if readable to customize devfs
850 if [ -r /etc/rc.devfs ]; then
854 # Configure implementation specific stuff
857 if [ -r /etc/rc.${arch} ]; then
861 # Configure the system console
863 if [ -r /etc/rc.syscons ]; then
867 echo -n 'Additional ABI support:'
869 # Load the SysV IPC API if requested.
870 case ${sysvipc_enable} in
873 kldload sysvmsg >/dev/null 2>&1
874 kldload sysvsem >/dev/null 2>&1
875 kldload sysvshm >/dev/null 2>&1
879 # Start the Linux binary compatibility if requested.
881 case ${linux_enable} in
884 if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
885 kldload linux > /dev/null 2>&1
887 if [ -x /compat/linux/sbin/ldconfig ]; then
888 /compat/linux/sbin/ldconfig
893 # Start the SysVR4 binary emulation if requested.
895 case ${svr4_enable} in
897 echo -n ' svr4'; kldload svr4 > /dev/null 2>&1
903 # Do traditional (but rather obsolete) rc.local file if it exists. If you
904 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
905 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
906 # shown below. Please do not put local extensions into /etc/rc itself.
910 # if [ -r /etc/defaults/rc.conf ]; then
911 # . /etc/defaults/rc.conf
913 # elif [ -r /etc/rc.conf ]; then
917 # ... additional startup conditionals ...
920 if [ -r /etc/rc.local ]; then
921 echo -n 'Starting local daemons:'
926 # For each valid dir in $local_startup, search for init scripts matching *.sh
928 case ${local_startup} in
932 echo -n 'Local package initialization:'
934 if [ -z "${script_name_sep}" ]; then
937 for dir in ${local_startup}; do
938 if [ -d "${dir}" ]; then
939 for script in ${dir}/*.sh; do
940 slist="${slist}${script_name_sep}${script}"
944 script_save_sep="$IFS"
945 IFS="${script_name_sep}"
946 for script in ${slist}; do
947 if [ -x "${script}" ]; then
951 elif [ -f "${script}" -o -L "${script}" ]; then
952 echo -n " (skipping ${script##*/}, not executable)"
955 IFS="${script_save_sep}"
960 if [ -n "${network_pass3_done}" ]; then
964 # Late pass to set variables we missed the first time
966 if [ -r /etc/rc.sysctl ]; then
967 sh /etc/rc.sysctl last
970 # Raise kernel security level. This should be done only after `fsck' has
971 # repaired local filesystems if you want the securelevel to be greater than 1.
973 case ${kern_securelevel_enable} in
975 if [ "${kern_securelevel}" -ge 0 ]; then
976 echo 'Raising kernel security level: '
977 sysctl kern.securelevel=${kern_securelevel}
982 # Start background fsck checks if necessary
983 case ${background_fsck} in
985 echo 'Starting background filesystem checks'
986 nice -4 fsck -B -p 2>&1 | logger -p daemon.notice &