From d893558687a8cd3f0202fd6d4a2bdac35f0a216e Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 28 May 2018 07:46:34 +0200 Subject: [PATCH] rc: ZFS importer bits For now only trigger on an explicit "zpool" input, because otherwise we have to load ZFS earlier to probe for a particular pool. There is no nice way to list all pools available for input, at least not in a single, script friendly line per pool. PR: https://github.com/opnsense/bsdinstaller/issues/12 --- src/sbin/opnsense-importer | 50 +++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/sbin/opnsense-importer b/src/sbin/opnsense-importer index 8cef835ee..599a34347 100755 --- a/src/sbin/opnsense-importer +++ b/src/sbin/opnsense-importer @@ -52,10 +52,18 @@ bootstrap_and_exit() # clean up after a finished import if [ -d ${MNT} ]; then - umount ${MNT} 2> /dev/null + if [ -n "${PART}" ]; then + umount ${MNT} + elif [ -n "${POOL}" ]; then + zfs export ${POOL} + fi rm -rf ${MNT} fi + if [ -z "${ZFS}" ]; then + kldunload zfs + fi + # error code given or assumed ok (trap) if [ -z "${RET}" ]; then RET=0 @@ -115,6 +123,16 @@ probe_for_part() # GPT layout found export PART="/dev/${DEV}p3" return 0 + elif [ "${DEV}" = "zroot" ]; then + if kldstat -qm zfs; then + export ZFS="yes" + else + kldload zfs + fi + if zpool import | awk '{ print $1 " " $2 }' | grep -q "${DEV} ONLINE"; then + export POOL="${DEV}" + return 0 + fi fi return 1 @@ -144,7 +162,7 @@ else DEVS=$(camcontrol devlist; gmirror status -s; graid status -s) fi -while [ -z "${PART}" ]; do +while [ -z "${PART}" -a -z "${POOL}" ]; do echo echo "${DEVS}" echo @@ -161,18 +179,28 @@ while [ -z "${PART}" ]; do fi done -echo "Starting import for partition '${PART}'." -echo - mkdir -p ${MNT} -echo -n "Running fsck..." -fsck -t ufs -y ${PART} > /dev/null -echo "done." +if [ -n "${PART}" ]; then + echo "Starting import for partition '${PART}'." + echo -if ! mount ${PART} ${MNT} 2> /dev/null; then - echo "The device could not be mounted." - bootstrap_and_exit 1 + echo -n "Running fsck..." + fsck -t ufs -y ${PART} > /dev/null + echo "done." + + if ! mount ${PART} ${MNT}; then + echo "The device could not be mounted." + bootstrap_and_exit 1 + fi +else + echo "Starting import for ZFS pool '${POOL}'." + echo + + if ! zpool import -f -R /tmp/hdrescue ${POOL} && \ + zfs mount ${POOL}/ROOT/default; then + echo "The device could not be mounted." + fi fi if [ -f "${MNT}/conf/config.xml" ]; then