Because ZFS boot code was very fragile in the past and real PITA to debug,
introduce zfsboottest.sh script that will verify if it will be possible to boot from the given pool. # zfsboottest.sh system Where "system" is pool name of the pool we want to boot from. What is being verified by the script: - Does the pool exist? - Does it have bootfs property configured? - Is mountpoint property of the boot dataset set to 'legacy'? Dataset configured in bootfs property has to be mounted to perform more checks: - Does the /boot directory in boot dataset exist? - Is this dataset configured as root file system in /etc/fstab or set in vfs.root.mountfrom variable in /boot/loader.conf? By using zfsboottest tool the script will read all the files in /boot directory using ZFS boot code and calculate their checksums. Then, it will walk /boot directory using find(1) though regular file sytem and also read all the files in /boot directory and calculate their checksums. If any of the files cannot be looked up, read or checksum is invalid it will be reported and booting off of this pool is probably not possible. Some additional checks may be interesting as well. For example if the disks contain proper pmbr and gptzfsboot code or if all expected files in /boot/ are present. When upgrading FreeBSD, one should snapshot datasets that contain operating system, upgrade (install new world and kernel) and use zfsboottest.sh to verify if it will be possible to boot from new configuration. If all is good one should upgrade boot blocks, by eg.: # gpart -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1 If something is wrong, one should rollback datasets and report the problems. MFC after: 3 days
This commit is contained in:
parent
cf43b453ec
commit
1ae7ff8ba6
@ -2,7 +2,12 @@
|
||||
|
||||
.PATH: ${.CURDIR}/../../../sys/boot/zfs ${.CURDIR}/../../../sys/cddl/boot/zfs
|
||||
|
||||
BINDIR?= /usr/bin
|
||||
SCRIPTSDIR?= /usr/bin
|
||||
|
||||
PROG= zfsboottest
|
||||
SCRIPTS= zfsboottest.sh
|
||||
SCRIPTSNAME= zfsboottest.sh
|
||||
NO_MAN=
|
||||
|
||||
CFLAGS= -O1 \
|
||||
|
130
tools/tools/zfsboottest/zfsboottest.sh
Executable file
130
tools/tools/zfsboottest/zfsboottest.sh
Executable file
@ -0,0 +1,130 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>
|
||||
# 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 AUTHORS 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 AUTHORS 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$
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "usage: zfsboottest.sh <pool>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
which -s zfsboottest
|
||||
if [ $? -eq 0 ]; then
|
||||
zfsboottest="zfsboottest"
|
||||
else
|
||||
if [ ! -x "/usr/src/tools/tools/zfsboottest/zfsboottest" ]; then
|
||||
echo "Unable to find \"zfsboottest\" utility." >&2
|
||||
exit 1
|
||||
fi
|
||||
zfsboottest="/usr/src/tools/tools/zfsboottest/zfsboottest"
|
||||
fi
|
||||
|
||||
startdir="/boot"
|
||||
|
||||
pool="${1}"
|
||||
zpool list "${pool}" >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such pool \"${pool}\"." >&2
|
||||
exit 1
|
||||
fi
|
||||
bootfs=`zpool get bootfs "${pool}" | tail -1 | awk '{print $3}'`
|
||||
if [ "${bootfs}" = "-" ]; then
|
||||
echo "The \"bootfs\" property is not configured for pool \"${pool}\"." >&2
|
||||
exit 1
|
||||
fi
|
||||
# Dataset's mountpoint property should be set to 'legacy'.
|
||||
if [ "`zfs get -H -o value mountpoint ${bootfs}`" != "legacy" ]; then
|
||||
echo "The \"mountpoint\" property of dataset \"${bootfs}\" should be set to \"legacy\"." >&2
|
||||
exit 1
|
||||
fi
|
||||
mountpoint=`df -t zfs "${bootfs}" 2>/dev/null | tail -1 | awk '{print $6}'`
|
||||
if [ -z "${mountpoint}" ]; then
|
||||
echo "The \"${bootfs}\" dataset is not mounted." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "${mountpoint}${startdir}" ]; then
|
||||
echo "The \"${mountpoint}${startdir}\" directory doesn't exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
# To be able to mount root ZFS file system we need either /etc/fstab entry
|
||||
# or vfs.root.mountfrom variable set in /boot/loader.conf.
|
||||
egrep -q '^'"${bootfs}"'[[:space:]]+/[[:space:]]+zfs[[:space:]]+' "${mountpoint}/etc/fstab" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
egrep -q 'vfs.root.mountfrom="?'"${bootfs}"'"?[[:space:]]*$' "${mountpoint}/boot/loader.conf" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "To be able to boot from \"${bootfs}\", you need to declare" >&2
|
||||
echo "\"${bootfs}\" as being root file system in ${mountpoint}/etc/fstab" >&2
|
||||
echo "or add \"vfs.root.mountfrom\" variable set to \"${bootfs}\" to" >&2
|
||||
echo "${mountpoint}/boot/loader.conf." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
vdevs=""
|
||||
for vdev in `zpool status "${pool}" | grep ONLINE | awk '{print $1}'`; do
|
||||
vdev="/dev/${vdev#/dev/}"
|
||||
if [ -c "${vdev}" ]; then
|
||||
if [ -z "${vdevs}" ]; then
|
||||
vdevs="${vdev}"
|
||||
else
|
||||
vdevs="${vdevs} ${vdev}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
list0=`mktemp /tmp/zfsboottest.XXXXXXXXXX`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Unable to create temporary file." >&2
|
||||
exit 1
|
||||
fi
|
||||
list1=`mktemp /tmp/zfsboottest.XXXXXXXXXX`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Unable to create temporary file." >&2
|
||||
rm -f "${list0}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "zfsboottest.sh is reading all the files in ${mountpoint}${startdir} using"
|
||||
echo "boot code and using file system code."
|
||||
echo "It calculates MD5 checksums for all the files and will compare them."
|
||||
echo "If all files can be properly read using boot code, it is very likely you"
|
||||
echo "will be able to boot from \"${pool}\" pool>:> Good luck!"
|
||||
echo
|
||||
|
||||
"${zfsboottest}" ${vdevs} - `find "${mountpoint}${startdir}" -type f | sed "s@^${mountpoint}@@"` | egrep '^[0-9a-z]{32} /' | sort -k 2 >"${list0}"
|
||||
find "${mountpoint}${startdir}" -type f | xargs md5 -r | sed "s@ ${mountpoint}@ @" | egrep '^[0-9a-z]{32} /' | sort -k 2 >"${list1}"
|
||||
|
||||
diff -u "${list0}" "${list1}"
|
||||
ec=$?
|
||||
|
||||
rm -f "${list0}" "${list1}"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo >&2
|
||||
echo "You may not be able to boot." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK"
|
Loading…
Reference in New Issue
Block a user