To allow /etc to be as minimal as possible in a diskless setup, we need
to run initdiskless before we run rcorder on /etc/rc.d. To allow this, move /etc/rc.d/initdiskless to /etc/rc.initdiskless and run it directly from /etc/rc. Remove /etc/rc.d/preseedrandom as it is no longer necessicary (we start with entropy unblocked) and was only used by initdiskless when it was needed. Discussed on: freebsd-rc Repocopy by: peter
This commit is contained in:
parent
9249fcc4b9
commit
2af94c5d1d
@ -12,7 +12,8 @@ BIN1= amd.map apmd.conf auth.conf \
|
||||
inetd.conf login.access login.conf \
|
||||
mac.conf motd netconfig network.subr networks newsyslog.conf \
|
||||
pf.conf pf.os phones profile protocols \
|
||||
rc rc.bsdextended rc.firewall rc.firewall6 rc.sendmail rc.shutdown \
|
||||
rc rc.bsdextended rc.firewall rc.firewall6 rc.initdiskless \
|
||||
rc.sendmail rc.shutdown \
|
||||
rc.subr remote rpc services shells \
|
||||
snmpd.config sysctl.conf syslog.conf usbd.conf \
|
||||
etc.${MACHINE_ARCH}/ttys \
|
||||
|
5
etc/rc
5
etc/rc
@ -65,6 +65,11 @@ else
|
||||
_boot="start"
|
||||
fi
|
||||
|
||||
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
|
||||
if [ ${dlv:=0} -ne 0 -o -f /etc/diskless ]; then
|
||||
sh /etc/rc.initdiskless
|
||||
fi
|
||||
|
||||
skip="-s nostart"
|
||||
[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && skip="$skip -s nojail"
|
||||
files=`rcorder ${skip} /etc/rc.d/* 2>/dev/null`
|
||||
|
@ -13,7 +13,7 @@ FILES= DAEMON LOGIN NETWORKING SERVERS \
|
||||
gbde gbde_swap \
|
||||
hostname \
|
||||
ike \
|
||||
inetd initdiskless initrandom \
|
||||
inetd initrandom \
|
||||
ip6addrctl ip6fw ipfilter ipfs ipfw ipmon \
|
||||
ipnat ipsec ipxrouted isdnd \
|
||||
jail \
|
||||
@ -26,7 +26,7 @@ FILES= DAEMON LOGIN NETWORKING SERVERS \
|
||||
nfslocking nfsserver nisdomain nsswitch ntpd ntpdate \
|
||||
othermta \
|
||||
pccard pcvt pf pflog \
|
||||
powerd power_profile ppp-user pppoed preseedrandom pwcheck \
|
||||
powerd power_profile ppp-user pppoed pwcheck \
|
||||
quota \
|
||||
ramdisk ramdisk-own random rarpd rcconf.sh resolv root \
|
||||
route6d routed routing rpcbind rtadvd rwho \
|
||||
|
@ -1,323 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 1999 Matt Dillon
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# PROVIDE: initdiskless
|
||||
# REQUIRE: preseedrandom
|
||||
# BEFORE: rcconf
|
||||
# KEYWORD: nojail
|
||||
|
||||
|
||||
# On entry to this script the entire system consists of a read-only root
|
||||
# mounted via NFS. The kernel has run BOOTP and configured an interface
|
||||
# (otherwise it would not have been able to mount the NFS root!)
|
||||
#
|
||||
# We use the contents of /conf to create and populate memory filesystems
|
||||
# that are mounted on top of this root to implement the writable
|
||||
# (and host-specific) parts of the root filesystem, and other volatile
|
||||
# filesystems.
|
||||
#
|
||||
# The hierarchy in /conf has the form /conf/T/M/ where M are directories
|
||||
# for which memory filesystems will be created and filled,
|
||||
# and T is one of the "template" directories below:
|
||||
#
|
||||
# base universal base, typically a replica of the original root;
|
||||
# default secondary universal base, typically overriding some
|
||||
# of the files in the original root;
|
||||
# ${ipba} where ${ipba} is the assigned broadcast IP address
|
||||
# ${class} where ${class} is a list of directories supplied by
|
||||
# bootp/dhcp through the T134 option.
|
||||
# ${ipba} and ${class} are typicall used to configure features
|
||||
# for group of diskless clients, or even individual features;
|
||||
# ${ip} where ${ip} is the machine's assigned IP address, typically
|
||||
# used to set host-specific features;
|
||||
#
|
||||
# Template directories are scanned in the order they are listed above,
|
||||
# with each sucessive directory overriding (merged into) the previous one;
|
||||
# non-existing directories are ignored.
|
||||
#
|
||||
# The existence of a directory /conf/T/M causes this script to create a
|
||||
# memory filesystem mounted as /M on the client.
|
||||
#
|
||||
# Some files in /conf have special meaning, namely:
|
||||
#
|
||||
# Filename Action
|
||||
# ----------------------------------------------------------------
|
||||
# /conf/T/M/remount
|
||||
# The contents of the file is a mount command. E.g. if
|
||||
# /conf/1.2.3.4/foo/remount contains "mount -o ro /dev/ad0s3",
|
||||
# then /dev/ad0s3 will be be mounted on /conf/1.2.3.4/foo/
|
||||
#
|
||||
# /conf/T/M/diskless_remount
|
||||
# The contents of the file points to an NFS filesystem. E.g. if
|
||||
# /conf/base/etc/diskless_remount contains "foo.com:/etc",
|
||||
# then foo.com:/etc will be be mounted on /conf/base/etc/
|
||||
# If the file contains a pathname starting with "/", then
|
||||
# the root path is prepended to it; this allows relocation of
|
||||
# the root filesystem withouth changing configuration files.
|
||||
#
|
||||
# /conf/T/M/md_size
|
||||
# The contents of the file specifies the size of the memory
|
||||
# filesystem to be created, in 512 byte blocks.
|
||||
# The default size is 10240 blocks (5MB). E.g. if
|
||||
# /conf/base/etc/md_size contains "30000" then a 15MB MFS
|
||||
# will be created. In case of multiple entries for the same
|
||||
# directory M, the last one in the scanning order is used.
|
||||
# NOTE: If you only need to create a memory filesystem but not
|
||||
# initialize it from a template, it is preferrable to specify
|
||||
# it in fstab e.g. as "md /tmp mfs -s=30m,rw 0 0"
|
||||
#
|
||||
# /conf/T/SUBDIR.cpio.gz
|
||||
# The file is cpio'd into /SUBDIR (and a memory filesystem is
|
||||
# created for /SUBDIR if necessary). The presence of this file
|
||||
# prevents the copy from /conf/T/SUBDIR/
|
||||
#
|
||||
# /conf/T/SUBDIR.remove
|
||||
# The list of paths contained in the file are rm -rf'd
|
||||
# relative to /SUBDIR.
|
||||
#
|
||||
# You will almost universally want to create the following files under /conf
|
||||
#
|
||||
# File Content
|
||||
# ---------------------------- ------------------------------------------
|
||||
# /conf/base/etc/md_size size of /etc filesystem
|
||||
# /conf/base/diskless_remount "/etc"
|
||||
# /conf/default/etc/rc.conf generic diskless config parameters
|
||||
# /conf/default/etc/fstab generic diskless fstab e.g. like this
|
||||
#
|
||||
# foo:/root_part / nfs ro 0 0
|
||||
# foo:/usr_part /usr nfs ro 0 0
|
||||
# foo:/home_part /home nfs rw 0 0
|
||||
# md /tmp mfs -s=30m,rw 0 0
|
||||
# md /var mfs -s=30m,rw 0 0
|
||||
# proc /proc procfs rw 0 0
|
||||
#
|
||||
# plus, possibly, overrides for password files etc.
|
||||
#
|
||||
# NOTE! /var, /tmp, and /dev will be typically created elsewhere, e.g.
|
||||
# as entries in the fstab as above.
|
||||
# Those filesystems should not be specified in /conf.
|
||||
#
|
||||
# (end of documentation, now get to the real code)
|
||||
|
||||
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
|
||||
[ ${dlv:=0} -eq 0 ] && [ ! -f /etc/diskless ] && exit 0
|
||||
|
||||
# chkerr:
|
||||
#
|
||||
# Routine to check for error
|
||||
#
|
||||
# checks error code and drops into shell on failure.
|
||||
# if shell exits, terminates script as well as /etc/rc.
|
||||
#
|
||||
chkerr() {
|
||||
case $1 in
|
||||
0)
|
||||
;;
|
||||
*)
|
||||
echo "$2 failed: dropping into /bin/sh"
|
||||
/bin/sh
|
||||
# RESUME
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Create a generic memory disk
|
||||
#
|
||||
mount_md() {
|
||||
/sbin/mdmfs -i 4096 -s $1 -M md $2
|
||||
}
|
||||
|
||||
# Create the memory filesystem if it has not already been created
|
||||
#
|
||||
create_md() {
|
||||
if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
|
||||
if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
|
||||
md_size=10240
|
||||
else
|
||||
md_size=`eval echo \\$md_size_$1`
|
||||
fi
|
||||
mount_md $md_size /$1
|
||||
/bin/chmod 755 /$1
|
||||
eval md_created_$1=created
|
||||
fi
|
||||
}
|
||||
|
||||
# DEBUGGING
|
||||
#
|
||||
# set -v
|
||||
|
||||
# Figure out our interface and IP.
|
||||
#
|
||||
bootp_ifc=""
|
||||
bootp_ipa=""
|
||||
bootp_ipbca=""
|
||||
if [ ${dlv:=0} -ne 0 ] ; then
|
||||
iflist=`ifconfig -l`
|
||||
for i in ${iflist} ; do
|
||||
set -- `ifconfig ${i}`
|
||||
while [ $# -ge 1 ] ; do
|
||||
if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
|
||||
bootp_ifc=${i} ; bootp_ipa=${2} ; shift
|
||||
fi
|
||||
if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
|
||||
bootp_ipbca=$2; shift
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if [ "${bootp_ifc}" != "" ] ; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
# Insert the directories passed with the T134 bootp cookie
|
||||
# in the list of paths used for templates.
|
||||
i="`/sbin/sysctl -n kern.bootp_cookie`"
|
||||
[ "${i}" != "" ] && bootp_ipbca="${bootp_ipbca} ${i}"
|
||||
|
||||
echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
|
||||
fi
|
||||
|
||||
# Figure out our NFS root path
|
||||
#
|
||||
set -- `mount -t nfs`
|
||||
while [ $# -ge 1 ] ; do
|
||||
if [ "$2" = "on" -a "$3" = "/" ]; then
|
||||
nfsroot="$1"
|
||||
break
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
# The list of directories with template files
|
||||
templates="base default ${bootp_ipbca} ${bootp_ipa}"
|
||||
|
||||
# The list of filesystems to umount after the copy
|
||||
to_umount=""
|
||||
|
||||
# If /conf/diskless_remount exists, remount all of /conf. This allows
|
||||
# multiple roots to share the same conf files.
|
||||
if [ -d /conf -a -f /conf/diskless_remount ]; then
|
||||
nfspt=`/bin/cat /conf/diskless_remount`
|
||||
if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
|
||||
nfspt="${nfsroot}${nfspt}"
|
||||
fi
|
||||
mount_nfs $nfspt /conf
|
||||
chkerr $? "mount_nfs $nfspt /conf"
|
||||
to_umount="/conf"
|
||||
fi
|
||||
|
||||
# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
|
||||
# and /conf/${bootp_ipa}. For each subdirectory found within these
|
||||
# directories:
|
||||
#
|
||||
# - calculate memory filesystem sizes. If the subdirectory (prior to
|
||||
# NFS remounting) contains the file 'md_size', the contents specified
|
||||
# in 512 byte sectors will be used to size the memory filesystem. Otherwise
|
||||
# 8192 sectors (4MB) is used.
|
||||
#
|
||||
# - handle NFS remounts. If the subdirectory contains the file
|
||||
# diskless_remount, the contents of the file is NFS mounted over
|
||||
# the directory. For example /conf/base/etc/diskless_remount
|
||||
# might contain 'myserver:/etc'. NFS remounts allow you to avoid
|
||||
# having to dup your system directories in /conf. Your server must
|
||||
# be sure to export those filesystems -alldirs, however.
|
||||
# If the diskless_remount file contains a string beginning with a
|
||||
# '/' it is assumed that the local nfsroot should be prepended to
|
||||
# it before attemping to the remount. This allows the root to be
|
||||
# relocated without needing to change the remount files.
|
||||
#
|
||||
for i in ${templates} ; do
|
||||
for j in /conf/$i/* ; do
|
||||
# memory filesystem size specification
|
||||
#
|
||||
subdir=${j##*/}
|
||||
if [ -d $j -a -f $j/md_size ]; then
|
||||
eval md_size_$subdir=`cat $j/md_size`
|
||||
fi
|
||||
|
||||
# remount
|
||||
#
|
||||
if [ -d $j -a -f $j/remount ]; then
|
||||
nfspt=`/bin/cat $j/remount`
|
||||
$nfspt $j
|
||||
chkerr $? "$nfspt $j"
|
||||
to_umount="${to_umount} $j" # XXX hope it is really a mount!
|
||||
fi
|
||||
|
||||
# NFS remount
|
||||
#
|
||||
if [ -d $j -a -f $j/diskless_remount ]; then
|
||||
nfspt=`/bin/cat $j/diskless_remount`
|
||||
if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
|
||||
nfspt="${nfsroot}${nfspt}"
|
||||
fi
|
||||
mount_nfs $nfspt $j
|
||||
chkerr $? "mount_nfs $nfspt $j"
|
||||
to_umount="${to_umount} $j"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# - Create all required MFS filesystems and populate them from
|
||||
# our templates. Support both a direct template and a dir.cpio.gz
|
||||
# archive. Support dir.remove files containing a list of relative
|
||||
# paths to remove.
|
||||
#
|
||||
# The dir.cpio.gz form is there to make the copy process more efficient,
|
||||
# so if the cpio archive is present, it prevents the files from dir/
|
||||
# from being copied.
|
||||
|
||||
for i in ${templates} ; do
|
||||
for j in /conf/$i/* ; do
|
||||
subdir=${j##*/}
|
||||
if [ -d $j -a ! -f $j.cpio.gz ]; then
|
||||
create_md $subdir
|
||||
cp -Rp $j/* /$subdir
|
||||
fi
|
||||
done
|
||||
for j in /conf/$i/*.cpio.gz ; do
|
||||
subdir=${j%*.cpio.gz}
|
||||
subdir=${subdir##*/}
|
||||
if [ -f $j ]; then
|
||||
create_md $subdir
|
||||
echo "Loading /$subdir from cpio archive $j"
|
||||
(cd / ; /rescue/pax -x cpio -r -z -p e -f $j)
|
||||
fi
|
||||
done
|
||||
for j in /conf/$i/*.remove ; do
|
||||
subdir=${j%*.remove}
|
||||
subdir=${subdir##*/}
|
||||
if [ -f $j ]; then
|
||||
# doubly sure it is a memory disk before rm -rf'ing
|
||||
create_md $subdir
|
||||
(cd /$subdir; rm -rf `/bin/cat $j`)
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# umount partitions used to fill the memory filesystems
|
||||
[ -n "${to_umount}" ] && umount $to_umount
|
@ -1,39 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
# PROVIDE: preseedrandom
|
||||
# KEYWORD: nojail
|
||||
|
||||
feed_dev_random()
|
||||
{
|
||||
if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
|
||||
cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
soft_random_generator=`sysctl kern.random 2>/dev/null`
|
||||
|
||||
if [ -n "${soft_random_generator}" ] ; then
|
||||
|
||||
echo -n 'Pre-seeding PRNG:'
|
||||
|
||||
# XXX temporary until we can improve the entropy
|
||||
# harvesting rate.
|
||||
# Entropy below is not great, but better than nothing.
|
||||
# This unblocks the generator at startup
|
||||
( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \
|
||||
| dd of=/dev/random bs=8k 2>/dev/null
|
||||
cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null
|
||||
|
||||
# First pass at reseeding /dev/random.
|
||||
#
|
||||
if [ -w /dev/random ]; then
|
||||
feed_dev_random "/entropy"
|
||||
fi
|
||||
|
||||
echo -n ' kickstart'
|
||||
|
||||
echo '.'
|
||||
fi
|
@ -4,7 +4,6 @@
|
||||
#
|
||||
|
||||
# PROVIDE: rcconf
|
||||
# REQUIRE: initdiskless
|
||||
# BEFORE: disks initrandom
|
||||
|
||||
. /etc/rc.subr
|
||||
|
@ -25,12 +25,6 @@
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# PROVIDE: initdiskless
|
||||
# REQUIRE: preseedrandom
|
||||
# BEFORE: rcconf
|
||||
# KEYWORD: nojail
|
||||
|
||||
|
||||
# On entry to this script the entire system consists of a read-only root
|
||||
# mounted via NFS. The kernel has run BOOTP and configured an interface
|
||||
@ -125,7 +119,6 @@
|
||||
# (end of documentation, now get to the real code)
|
||||
|
||||
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
|
||||
[ ${dlv:=0} -eq 0 ] && [ ! -f /etc/diskless ] && exit 0
|
||||
|
||||
# chkerr:
|
||||
#
|
||||
|
Loading…
x
Reference in New Issue
Block a user