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
52 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
55 # BOOTP diskless boot. We have to run the rc file early in order to
56 # retarget various config files.
58 if [ -r /etc/rc.diskless1 ]; then
59 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
60 if [ ${dlv:=0} != 0 ]; then
65 # If there is a global system configuration file, suck it in.
67 if [ -r /etc/defaults/rc.conf ]; then
68 . /etc/defaults/rc.conf
70 elif [ -r /etc/rc.conf ]; then
75 if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
76 # echo "Using ${1} as an entropy file"
77 cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
87 eval svc_val=\${$svc_var}
88 eval dep_val=\${$dep_var}
97 echo "DEPENDENCY NOTE: ${dep} will be enabled" \
105 chkdepend amd amd_enable portmap portmap_enable
106 chkdepend NFS nfs_server_enable portmap portmap_enable
107 chkdepend NIS nis_server_enable portmap portmap_enable
108 chkdepend NIS nis_client_enable portmap portmap_enable
110 # Enable harvesting of entropy via devices. The sooner this happens the
111 # better so that we can take advantage of the boot process.
113 echo -n 'Entropy harvesting:'
115 case ${harvest_interrupt} in
119 if [ -w /dev/random ]; then
120 /sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null
121 echo -n ' interrupts'
126 case ${harvest_ethernet} in
130 if [ -w /dev/random ]; then
131 /sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null
137 case ${harvest_p_to_p} in
141 if [ -w /dev/random ]; then
142 /sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null
143 echo -n ' point_to_point'
150 # First pass at reseeding /dev/random.
152 case ${entropy_file} in
156 if [ -w /dev/random ]; then
157 feed_dev_random "${entropy_file}"
162 # XXX temporary until we can get the entropy
164 # Entropy below is not great,
165 # but better than nothing.
166 ( ps -efauxww; sysctl -a; date; df -ib; dmesg; ps -efauxww; ) \
167 | dd of=/dev/random bs=8k 2>/dev/null
168 cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
170 # Configure ccd devices.
172 if [ -r /etc/ccd.conf ]; then
176 case ${start_vinum} in
184 # Last chance to do things before potentially waiting for
185 # operator to do fsck related tasks
186 if [ -r /etc/rc.early ]; then
192 echo 'Automatic boot in progress...'
193 case ${background_fsck} in
209 echo 'Reboot failed... help!'
213 case ${fsck_y_enable} in
215 echo 'File system preen failed, trying fsck -y . . .'
221 echo 'Automatic file system check failed . . . help!'
227 echo 'Automatic file system check failed . . . help!'
233 echo 'Reboot interrupted'
237 # interrupt before catcher installed
241 echo 'Unknown error in reboot'
247 echo 'Skipping disk checks ...'
252 trap "echo 'Reboot interrupted'; exit 1" 3
254 # root normally must be read/write, but if this is a BOOTP NFS
255 # diskless boot it does not have to be.
257 case ${root_rw_mount} in
261 if ! mount -u -o rw / ; then
262 echo 'Mounting root filesystem rw failed, startup aborted'
268 umount -a >/dev/null 2>&1
270 # Set up the list of network filesystem types for which mounting should be
271 # delayed until after network initialization.
272 networkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL'
273 case ${extra_netfs_types} in
277 networkfs_types="${networkfs_types} ${extra_netfs_types}"
281 # Mount everything except nfs filesystems.
283 for i in ${networkfs_types}; do
285 mount_excludes="${mount_excludes}${fstype},"
287 mount_excludes=${mount_excludes%,}
288 mount -a -t ${mount_excludes}
294 echo 'Mounting /etc/fstab filesystems failed, startup aborted'
299 # Run custom disk mounting function here
301 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
305 # Reseed /dev/random with previously stored entropy.
306 case ${entropy_dir} in
310 entropy_dir=${entropy_dir:-/var/db/entropy}
311 if [ -d "${entropy_dir}" ]; then
312 if [ -w /dev/random ]; then
313 for seedfile in ${entropy_dir}/*; do
314 feed_dev_random "${seedfile}"
321 case ${entropy_file} in
325 if [ -w /dev/random ]; then
326 feed_dev_random "${entropy_file}"
336 if [ $# -eq 0 ]; then
342 cd "$dir" && for file in .* *
344 [ ."$file" = .. -o ."$file" = ... ] && continue
345 if [ -d "$file" -a ! -L "$file" ]
358 if [ -d /var/run -a ! -f /var/run/clean_var ]; then
360 # Keep a copy of the boot messages around
361 dmesg >/var/run/dmesg.boot
362 # And an initial utmp file
363 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
366 if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
367 purgedir /var/spool/lock
368 >/var/spool/lock/clean_var
370 rm -rf /var/spool/uucp/.Temp/*
373 # network_pass1() *may* end up writing stuff to /var - we don't want to
374 # remove it immediately afterwards - *nor* do we want to fail to clean
375 # an NFS-mounted /var.
376 rm -f /var/run/clean_var /var/spool/lock/clean_var
379 # Add additional swapfile, if configured.
385 if [ -w "${swapfile}" -a -c /dev/mdctl ]; then
386 echo "Adding ${swapfile} as additional swap"
387 mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
392 # Set sysctl variables as early as we can
394 if [ -r /etc/rc.sysctl ]; then
398 # Configure serial devices
400 if [ -r /etc/rc.serial ]; then
404 # Start up PC-card configuration
406 if [ -r /etc/rc.pccard ]; then
410 # Start up the initial network configuration.
412 if [ -r /etc/rc.network ]; then
413 . /etc/rc.network # We only need to do this once.
417 case ${ipv6_enable} in
419 if [ -r /etc/rc.network6 ]; then
420 . /etc/rc.network6 # We only need to do this once also.
426 # Mount NFS filesystems if present in /etc/fstab
428 # XXX When the vfsload() issues with nfsclient support and related sysctls
429 # have been resolved, this block can be removed, and the condition that
430 # skips nfs in the following block (for "other network filesystems") can
432 case "`mount -d -a -t nfs 2> /dev/null`" in
434 # Handle absent nfs client support
435 nfsclient_in_kernel=0
436 if sysctl vfs.nfs >/dev/null 2>&1; then
437 nfsclient_in_kernel=1
439 kldload nfsclient && nfsclient_in_kernel=1
442 case ${nfsclient_in_kernel} in
444 echo -n 'Mounting NFS file systems:'
449 echo 'Warning: nfs mount requested, but no nfs client in kernel'
455 # Mount other network filesystems if present in /etc/fstab
456 for i in ${networkfs_types}; do
460 if [ "${fstype}" = "nfs" ]; then
463 case "`mount -d -a -t ${fstype}`" in
465 echo -n "Mounting ${fsdecr} file systems:"
466 mount -a -t ${fstype}
472 # Whack the pty perms back into shape.
474 if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
475 chflags 0 /dev/tty[pqrsPQRS]*
476 chmod 666 /dev/tty[pqrsPQRS]*
477 chown root:wheel /dev/tty[pqrsPQRS]*
480 # Clean up left-over files
482 clean_var # If it hasn't already been done
483 rm /var/run/clean_var /var/spool/lock/clean_var
485 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
486 # help in any way for long-living systems, and it might accidentally
487 # clobber files you would rather like to have preserved after a crash
488 # (if not using mfs /tmp anyway).
490 # See also the example of another cleanup policy in /etc/periodic/daily.
492 case ${clear_tmp_enable} in
494 echo -n 'Clearing /tmp:'
495 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
496 # (not needed with mfs /tmp, but doesn't hurt there...)
497 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
498 find -d . ! -name . ! -name lost+found ! -name quota.user \
499 ! -name quota.group -exec rm -rf -- {} \;)
504 # Remove X lock files, since they will prevent you from restarting X11
505 # after a system crash.
507 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
509 # Snapshot any kernel -c changes back to disk here <someday>.
510 # This has changed with ELF and /kernel.config.
512 echo -n 'Additional daemons:'
514 # Start system logging and name service. Named needs to start before syslogd
515 # if you don't have a /etc/resolv.conf.
517 case ${syslogd_enable} in
519 # Transitional symlink (for the next couple of years :) until all
520 # binaries have had a chance to move towards /var/run/log.
521 if [ ! -L /dev/log ]; then
522 # might complain for r/o root f/s
523 ln -sf /var/run/log /dev/log
528 ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
534 # Build device name databases if we are not using DEVFS
536 if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
537 rm -f /var/run/dev.db
542 # Enable dumpdev so that savecore can see it.
543 # /var/crash should be a directory or a symbolic link
544 # to the crash directory if core dumps are to be saved.
556 if [ -e "${dumpdev}" -a -d "${dumpdir}" ]; then
557 /sbin/dumpon -v ${dumpdev}
558 echo -n 'Checking for core dump: '
559 /sbin/savecore ${savecore_flags} "${dumpdir}"
564 if [ -n "${network_pass1_done}" ]; then
568 # Enable/Check the quotas (must be after ypbind if using NIS)
570 case ${enable_quotas} in
572 case ${check_quotas} in
574 echo -n 'Checking quotas:'
580 echo -n 'Enabling quotas:'
586 if [ -n "${network_pass2_done}" ]; then
590 # Check the password temp/lock file
592 if [ -e /etc/ptmp ]; then
593 logger -s -p auth.err \
594 "password file may be incorrect -- /etc/ptmp exists"
597 case ${accounting_enable} in
599 if [ -d /var/account ]; then
600 echo 'Turning on accounting:'
601 if [ ! -e /var/account/acct ]; then
602 touch /var/account/acct
604 accton /var/account/acct
609 # Make shared lib searching a little faster. Leave /usr/lib first if you
610 # add your own entries or you may come to grief.
612 ldconfig="/sbin/ldconfig"
613 case ${ldconfig_insecure} in
615 ldconfig="${ldconfig} -i"
618 if [ -x /sbin/ldconfig ]; then
619 case `/usr/bin/objformat` in
622 for i in ${ldconfig_paths}; do
623 if [ -d "${i}" ]; then
627 echo 'ELF ldconfig path:' ${_LDC}
628 ${ldconfig} -elf ${_LDC}
632 # Legacy aout support for i386 only
633 case `sysctl -n hw.machine` in
635 # Default the a.out ldconfig path.
636 : ${ldconfig_paths_aout=${ldconfig_paths}}
638 for i in ${ldconfig_paths_aout}; do
639 if [ -d "${i}" ]; then
643 echo 'a.out ldconfig path:' ${_LDC}
644 ${ldconfig} -aout ${_LDC}
649 # Now start up miscellaneous daemons that don't belong anywhere else
651 echo -n 'Starting standard daemons:'
652 case ${inetd_enable} in
656 echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
660 case ${cron_enable} in
664 echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags}
668 case ${lpd_enable} in
670 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
674 case ${sshd_enable} in
676 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
678 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
683 case ${usbd_enable} in
685 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
689 if [ -r /etc/mail/sendmail.cf ]; then
690 case ${sendmail_enable} in
693 /usr/sbin/sendmail ${sendmail_flags}
696 case ${sendmail_outbound_enable} in
699 /usr/sbin/sendmail ${sendmail_outbound_flags}
708 # Recover vi editor files.
709 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
710 vibackup=`echo /var/tmp/vi.recover/vi.*`
711 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
712 echo -n 'Recovering vi editor sessions:'
713 for i in /var/tmp/vi.recover/vi.*; do
714 # Only test files that are readable.
715 if [ ! -r "${i}" ]; then
719 # Unmodified nvi editor backup files either have the
720 # execute bit set or are zero length. Delete them.
721 if [ -x "${i}" -o ! -s "${i}" ]; then
726 # It is possible to get incomplete recovery files, if the editor
727 # crashes at the right time.
728 virecovery=`echo /var/tmp/vi.recover/recover.*`
729 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
730 for i in /var/tmp/vi.recover/recover.*; do
731 # Only test files that are readable.
732 if [ ! -r "${i}" ]; then
736 # Delete any recovery files that are zero length,
737 # corrupted, or that have no corresponding backup file.
738 # Else send mail to the user.
739 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
740 if [ -n "${recfile}" -a -s "${recfile}" ]; then
750 # Make a bounds file for msgs(1) if there isn't one already
752 if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
753 echo 0 > /var/msgs/bounds
756 case ${update_motd} in
760 if T=`mktemp /tmp/_motd.XXXXXX`; then
761 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
762 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
763 cmp -s ${T} /etc/motd || {
772 # Run rc.devfs if readable to customize devfs
774 if [ -r /etc/rc.devfs ]; then
778 # Configure implementation specific stuff
781 if [ -r /etc/rc.${arch} ]; then
785 # Configure the system console
787 if [ -r /etc/rc.syscons ]; then
791 echo -n 'Additional ABI support:'
793 # Load the SysV IPC API if requested.
794 case ${sysvipc_enable} in
797 kldload sysvmsg >/dev/null 2>&1
798 kldload sysvsem >/dev/null 2>&1
799 kldload sysvshm >/dev/null 2>&1
803 # Start the Linux binary compatibility if requested.
805 case ${linux_enable} in
808 if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
809 kldload linux > /dev/null 2>&1
811 if [ -x /compat/linux/sbin/ldconfig ]; then
812 /compat/linux/sbin/ldconfig
817 # Start the SysVR4 binary emulation if requested.
819 case ${svr4_enable} in
821 echo -n ' svr4'; kldload svr4 > /dev/null 2>&1
827 # Do traditional (but rather obsolete) rc.local file if it exists. If you
828 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
829 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
830 # shown below. Please do not put local extensions into /etc/rc itself.
834 # if [ -r /etc/defaults/rc.conf ]; then
835 # . /etc/defaults/rc.conf
837 # elif [ -r /etc/rc.conf ]; then
841 # ... additional startup conditionals ...
844 if [ -r /etc/rc.local ]; then
845 echo -n 'Starting local daemons:'
850 # For each valid dir in $local_startup, search for init scripts matching *.sh
852 case ${local_startup} in
856 echo -n 'Local package initialization:'
858 if [ -z "${script_name_sep}" ]; then
861 for dir in ${local_startup}; do
862 if [ -d "${dir}" ]; then
863 for script in ${dir}/*.sh; do
864 slist="${slist}${script_name_sep}${script}"
868 script_save_sep="$IFS"
869 IFS="${script_name_sep}"
870 for script in ${slist}; do
871 if [ -x "${script}" ]; then
875 elif [ -f "${script}" -o -L "${script}" ]; then
876 echo -n " (skipping ${script##*/}, not executable)"
879 IFS="${script_save_sep}"
884 if [ -n "${network_pass3_done}" ]; then
888 # Raise kernel security level. This should be done only after `fsck' has
889 # repaired local file systems if you want the securelevel to be greater than 1.
891 case ${kern_securelevel_enable} in
893 if [ "${kern_securelevel}" -ge 0 ]; then
894 echo 'Raising kernel security level: '
895 sysctl kern.securelevel=${kern_securelevel}
900 # Start background fsck checks if necessary
901 case ${background_fsck} in
903 echo 'Starting background filesystem checks'
904 nice -4 fsck -B -p 2>&1 | logger -p daemon.notice &