mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-16 10:20:30 +00:00
2822c33f8c
FILESYSTEMS (the default early_late_divider): 1. Move sysctl to run first 2. Move as many BEFOREs to REQUIREs as possible. 3. Minor effect, move hostid_save from right before mdconfig to right after. A lot of the early scripts make use of sysctl one way or another so running this first makes a lot of sense given that system-critical values are often placed in sysctl.conf. My original purpose for working on this was that while doing some debugging on other stuff I noticed that the order of execution was different in the first pass through the early scripts and the second. In practice that doesn't matter because the scripts are not executed the second time. However this _can_ result in problems if the difference in the rcorder moves a script from the late section to the early section in the second pass (which would mean the script would not get executed). So, I wanted to make the order of execution of the scripts in the early section more deterministic. In the course of debugging the ordering problems I noticed that moving the BEFOREs to REQUIREs prevented the changes in order from the first pass to the second pass without having to make any substantial changes. (Of course it's no secret that I think BEFORE should be avoided as much as possible, but this is a good example of why.) Reviewed by: silence on freebsd-rc@ MFC after: 8.1-RELEASE
198 lines
4.9 KiB
Bash
Executable File
198 lines
4.9 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2006 The FreeBSD Project
|
|
# 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: mdconfig
|
|
# REQUIRE: localswap root
|
|
|
|
. /etc/rc.subr
|
|
|
|
name="mdconfig"
|
|
stop_cmd="mdconfig_stop"
|
|
start_cmd="mdconfig_start"
|
|
start_precmd='[ -n "${_mdconfig_list}" ]'
|
|
required_modules="geom_md:g_md"
|
|
|
|
is_readonly()
|
|
{
|
|
local _mp _ret
|
|
|
|
_mp=$1
|
|
_ret=`mount | while read _line; do
|
|
case ${_line} in
|
|
*" ${_mp} "*read-only*)
|
|
echo "yes"
|
|
;;
|
|
|
|
*)
|
|
;;
|
|
esac;
|
|
done`
|
|
|
|
if [ -n "${_ret}" ]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
init_variables()
|
|
{
|
|
local _i
|
|
|
|
_fs=""
|
|
_mp=""
|
|
_dev="/dev/${_md}"
|
|
eval _config=\$mdconfig_${_md}
|
|
eval _newfs=\$mdconfig_${_md}_newfs
|
|
|
|
_type=${_config##*-t\ }
|
|
_type=${_type%%\ *}
|
|
if [ -z "${_type}" ]; then
|
|
err 1 "You need to specify \"-t <type>\" in mdconfig_${_md}"
|
|
fi
|
|
|
|
if [ "${_type}" = "vnode" ]; then
|
|
_file=${_config##*-f\ }
|
|
_file=${_file%%\ *}
|
|
if [ -z "${_file}" ]; then
|
|
err 2 "You need to specify \"-f <file>\" in mdconfig_${_md} for vnode devices"
|
|
fi
|
|
if [ "${_file}" != "${_file%.uzip}" ]; then
|
|
_dev="/dev/${_md}.uzip"
|
|
fi
|
|
for _i in `df ${_file} 2>/dev/null`; do _fs=${_i}; done
|
|
fi
|
|
|
|
# Debugging help.
|
|
debug "${_md} config: ${_config}"
|
|
debug "${_md} type: ${_type}"
|
|
debug "${_md} dev: ${_dev}"
|
|
debug "${_md} file: ${_file}"
|
|
debug "${_md} fs: ${_fs}"
|
|
debug "${_md} newfs flags: ${_newfs}"
|
|
}
|
|
|
|
mdconfig_start()
|
|
{
|
|
local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd
|
|
|
|
for _md in ${_mdconfig_list}; do
|
|
init_variables ${_md}
|
|
# Create md(4) devices of types swap, malloc and vnode if the
|
|
# file is on the root partition.
|
|
if [ "${_type}" != "vnode" -o "${_fs}" = "/" ]; then
|
|
if [ "${_type}" = "vnode" ]; then
|
|
if is_readonly ${_fs}; then
|
|
warn "${_fs} is mounted read-only, skipping ${_md}."
|
|
continue
|
|
fi
|
|
if [ "${_file}" != "${_file%.uzip}" ]; then
|
|
load_kld -m g_uzip geom_uzip || return 3
|
|
# sleep a bit to allow creation of /dev/mdX.uzip
|
|
sleep 2
|
|
fi
|
|
fi
|
|
if mdconfig -l -u ${_md} >/dev/null 2>&1; then
|
|
err 3 "${_md} already exists"
|
|
fi
|
|
echo "Creating ${_md} device (${_type})."
|
|
if ! mdconfig -a ${_config} -u ${_md}; then
|
|
echo "Creating ${_md} device failed, moving on."
|
|
continue
|
|
fi
|
|
# Skip fsck for uzip devices.
|
|
if [ "${_type}" = "vnode" ]; then
|
|
if [ "${_file}" != "${_file%.uzip}" ]; then
|
|
_fsck_cmd=":"
|
|
elif checkyesno background_fsck; then
|
|
_fsck_cmd="fsck -F"
|
|
else
|
|
_fsck_cmd="fsck"
|
|
fi
|
|
if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then
|
|
echo "Fsck failed on ${_dev}, not mounting the filesystem."
|
|
continue
|
|
|
|
fi
|
|
else
|
|
newfs ${_newfs} ${_dev} >/dev/null
|
|
fi
|
|
if mount -d ${_dev} 2>&1 >/dev/null; then
|
|
echo "Mounting ${_dev}."
|
|
mount ${_dev}
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
mdconfig_stop()
|
|
{
|
|
local _md _mp _config _type _dev _file _fs _newfs _i
|
|
|
|
for _md in ${_mdconfig_list}; do
|
|
init_variables ${_md}
|
|
if [ "${_type}" != "vnode" -o "${_fs}" = "/" ]; then
|
|
for _i in `df ${_dev} 2>/dev/null`; do _mp=${_i}; done
|
|
if [ -z "${_mp}" -o "${_mp}" != "${_mp%%%}" ]; then
|
|
echo "Device ${_dev} isn't mounted."
|
|
else
|
|
echo "Umounting ${_dev}."
|
|
umount ${_dev}
|
|
fi
|
|
if mdconfig -l -u ${_md} >/dev/null 2>&1; then
|
|
echo "Destroying ${_md}."
|
|
mdconfig -d -u ${_md}
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
_mdconfig_cmd="$1"
|
|
if [ $# -gt 0 ]; then
|
|
shift
|
|
fi
|
|
[ -n "$*" ] && _mdconfig_list="$*"
|
|
|
|
load_rc_config $name
|
|
|
|
_mdconfig_unit=0
|
|
if [ -z "${_mdconfig_list}" ]; then
|
|
while :; do
|
|
eval _mdconfig_config=\$mdconfig_md${_mdconfig_unit}
|
|
if [ -z "${_mdconfig_config}" ]; then
|
|
break
|
|
else
|
|
_mdconfig_list="${_mdconfig_list}${_mdconfig_list:+ }md${_mdconfig_unit}"
|
|
_mdconfig_unit=$((${_mdconfig_unit} + 1))
|
|
fi
|
|
done
|
|
fi
|
|
|
|
run_rc_command "${_mdconfig_cmd}"
|