From 4b846bcb2af67273510995b8e524c1a2a67680dc Mon Sep 17 00:00:00 2001 From: David Marec Date: Sun, 4 Nov 2018 21:09:34 +0100 Subject: [PATCH] bugfix: disks within a strip have the same partitioning or at least, a zfs compliant bootcode onto each drive --- zfsinstall.sh | 62 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/zfsinstall.sh b/zfsinstall.sh index 71a781d..b900465 100644 --- a/zfsinstall.sh +++ b/zfsinstall.sh @@ -1,6 +1,6 @@ #!/bin/sh -DESTDISK="ada0" +DESTDISKS="ada0 ada1" DESTDIR="/mnt/zfs" ZPOOL="zroot" @@ -17,38 +17,44 @@ fi # check if the disk is ok for writing -echo checking sanity ${DESTDISK} -echo ============= -gpart show ${DESTDISK} 1>/dev/null -if [ "${?}" -eq 0 ]; then - gpart destroy -F ${DESTDISK} - if [ "${?}" -ne 0 ]; then - echo unable to reset ${DESTDISK} - exit 1 - fi -fi -echo partitioning ${DESTDISK} -echo ============= +for D in ${DESTDISKS}; do + if [ -z "${DESTDISK_1}" ]; then + DESTDISK_1=${D} + fi -gpart create -s gpt ${DESTDISK} -gpart add -a 4k -t efi -s 200M -l efiboot0 ${DESTDISK} -gpart bootcode -p /boot/boot1.efifat -i 1 ${DESTDISK} -gpart add -a 4k -t freebsd-boot -s 512k -l gptboot0 ${DESTDISK} -gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ${DESTDISK} -gpart add -a 1m -s 32G -t freebsd-swap -l swap0 ${DESTDISK} -gpart add -a 1m -t freebsd-zfs -l zfs0 ${DESTDISK} -gpart set -a active ${DESTDISK} + echo checking sanity ${D} + echo ============= + gpart show ${D} 1>/dev/null + if [ "${?}" -eq 0 ]; then -gpart show ${DESTDISK} + gpart destroy -F ${D} + if [ "${?}" -ne 0 ]; then + echo unable to reset ${D} + exit 1 + fi + fi + echo partitioning ${D} + echo ============= + N=$( echo ${D} | tr -c -d '0-9' ) + gpart create -s gpt ${D} + gpart add -a 4k -t efi -s 200M -l efiboot${N} ${D} + gpart bootcode -p /boot/boot1.efifat -i 1 ${D} + gpart add -a 4k -t freebsd-boot -s 512k -l gptboot${N} ${D} + gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ${D} + gpart add -a 1m -s 32G -t freebsd-swap -l swap${N} ${D} + gpart add -a 1m -t freebsd-zfs -l zfs${N} ${D} + gpart set -a active ${D} + gpart show ${D} +done sysctl vfs.zfs.min_auto_ashift=12 echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR} echo ================= -zpool create -m none -f -R ${DESTDIR} ${ZPOOL} ${DESTDISK}p4 ada1 +zpool create -m none -f -R ${DESTDIR} ${ZPOOL} /dev/gpt/zfs* if [ "${?}" -ne 0 ]; then echo "unable to create zpool" exit 1 @@ -107,7 +113,7 @@ echo writing configuration files echo ========================== cat << EOF >> ${DESTDIR}/etc/fstab -/dev/${DESTDISK}p3 none swap sw 0 0 +/dev/${DESTDISK_1}p3 none swap sw 0 0 tmpfs /tmp tmpfs rw,mode=1777 0 0 EOF @@ -130,9 +136,13 @@ for I in *.conf*; do done COPYCAT="/etc/rc.conf.d" cd ${SCRIPTBASE}${COPYCAT} || exit 1 -install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1 echo installing files into ${COPYCAT} -install -o root -g wheel -m 0644 * ${DESTDIR}${COPYCAT}/ +install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1 +for I in *; do + if [ -r "${I}" -a -f ${I} ]; then + install -o root -g wheel -m 0644 * ${DESTDIR}${COPYCAT}/ + fi +done COPYCAT="/etc/rc.conf.d/network" cd ${SCRIPTBASE}${COPYCAT} || exit 1 install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1 -- 2.47.0