Last active
November 2, 2016 21:31
-
-
Save david-cako/e770aef628373938ab8c3b17a7cb7ae9 to your computer and use it in GitHub Desktop.
FreeNAS Minnowboard deployment using FreeBSD's loader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bash | |
FREENAS_ISO=$1 | |
FREEBSD_ISO=$2 | |
DEST=$3 | |
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | |
echo "usage: $0 [FreeNAS ISO file] [FreeBSD skeleton image] [target drive]" | |
exit 1 | |
fi | |
echo | |
gpart show $DEST | |
read -p "Continuing will nuke ${DEST}. Are you sure? " -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
exit 1 | |
fi | |
function cleanup { | |
if mount | grep "/mnt/freenas_iso" > /dev/null; then | |
echo "unmounting /mnt/freenas_iso..." | |
umount /mnt/freenas_iso | |
mdconfig -d -u 1 | |
fi | |
if mount | grep "/mnt/freenas_usb" > /dev/null; then | |
echo "unmounting /mnt/freenas_usb..." | |
umount /mnt/freenas_usb | |
fi | |
if [ -e "/mnt/freenas_iso" ]; then | |
rm -rf /mnt/freenas_iso | |
fi | |
if [ -e "/mnt/freenas_usb" ]; then | |
rm -rf /mnt/freenas_usb | |
fi | |
} | |
cleanup | |
trap cleanup EXIT | |
# mount source freenas ISO | |
echo "mounting FreeNAS ISO..." | |
mkdir /mnt/freenas_iso | |
mdconfig -a -t vnode -f $FREENAS_ISO -u 1 | |
mount -t cd9660 /dev/md1 /mnt/freenas_iso | |
# clone freebsd skeleton image | |
echo "cloning FreeBSD skeleton image to drive..." | |
dd if=$FREEBSD_ISO of=$DEST bs=1m conv=sync | |
# copy root filesystem to target drive | |
mkdir /mnt/freenas_usb | |
mount -t ufs ${DEST}p3 /mnt/freenas_usb | |
echo "copying FreeNAS root filesystem..." | |
cp -a /mnt/freenas_iso/. /mnt/freenas_usb/ | |
rm -rf /mnt/freenas_usb/boot/grub /mnt/freenas_usb/boot/loader.conf /mnt/freenas_usb/boot/device.hints | |
echo "extracting /boot..." | |
tar -xpzvf ./boot.tar.gz -C /mnt/freenas_usb/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment