I typically wrap all these commands into a shell script that I can reuse, but here they are in steps.
Please read through all the instructions before actually performing the commands, just to avoid any surprises
Requirements:
- careful typing and copy/paste skills
- USB drive (8 GB+ ?) Make sure you don't need anything on that drive
- Existing FreeBSD system
- you are willing to reboot
- /mnt is empty or not mounted
- Internet connection (to bsdinstall fetch the FreeBSD release files )
- root access (we're performing all these commands as root)
- /bin/sh
Take note which device in /dev/ is your USB drive, you don't want to wipe anything else accidentally!
I will use "YourDriveHere" to note where you should replace with your device (example: if your drive is da0, replace YourDriveHere with da0 )
dd if=/dev/zero of=/dev/YourDriveHere bs=1m count=5
/bin/sh
Then setup some variable that bsdinstall will use for unattended setup:
export ZFSBOOT_DISKS=YourDriveHere
Variables for ZFS options
export ZFSBOOT_POOL_NAME=usbzfssystem
export ZFSBOOT_SWAP_SIZE=2g
export ZFSBOOT_SWAP_ENCRYPTION=1
export ZFSBOOT_VDEV_TYPE=stripe
Variables for Temp folders
export BSDINSTALL_TMPBOOT=/tmp/bsdinstall_boot
export BSDINSTALL_TMPETC=/tmp/bsdinstall_etc
Variables for where and what to download
export DISTRIBUTIONS="MANIFEST kernel.txz base.txz lib32.txz doc.txz src.txz"
export BSDINSTALL_DISTSITE_BASE="http://ftp.freebsd.org/pub/FreeBSD/releases"
export BSDINSTALL_DISTSITE="${BSDINSTALL_DISTSITE_BASE}/`uname -m`/`uname -p`/10.2-RELEASE"
export BSDINSTALL_DISTDIR=/mnt/10.2-RELEASE
This should create the partition table for you on your drive based on the variables we set above. (2g for SWAP, and the rest for ZFS)
env nonInteractive=0 bsdinstall zfsboot
If it seems to take more than 5 minutes, something is wrong. But don't be fooled by the nice screen, your prompt may be returned to you at the bottom.
If complete, BSDInstall should have mounted the new pool at /mnt, so we can create our new system's /mnt/boot/loader.conf
zpool status $ZFSBOOT_POOL_NAME
cat ${BSDINSTALL_TMPBOOT}/loader.conf.* >>/mnt/boot/loader.conf
echo zfs_load=YES >> /mnt/boot/loader.conf
chmod 600 /mnt/boot/loader.conf
This fetches the FreeBSD release files and checks it against the MANIFEST file that will be downloaded.
mkdir -p $BSDINSTALL_DISTDIR
bsdinstall distfetch
bsdinstall checksum || echo "Error: checksum mismatch."
Again, don't be fooled by the nice screen, your prompt may be returned to you at the bottom.
If there is a checksum mismatch, you'll have to run the 2 steps in this command again.
Now we change the variable so that it extracts the release files only.
After this command is run, the release files should be extracted to /mnt
export DISTRIBUTIONS="kernel.txz base.txz lib32.txz doc.txz src.txz"
bsdinstall distextract
cat ${BSDINSTALL_TMPETC}/fstab >> /mnt/etc/fstab
chmod 600 /mnt/etc/fstab
zfs snap -r $ZFSBOOT_POOL_NAME@new_install
(or however you want)
cat /etc/resolv.conf > /mnt/etc/resolv.conf
chroot /mnt freebsd-update fetch install
chroot /mnt passwd
If the network is different on the system you are going to use the USB in, adjust as necessary.
NOTE: The new system files are in /mnt, don't accidentally trash your existing system!!!!!!!!!!!!!
echo zfs_enable=YES >> /mnt/etc/rc.conf
echo sshd_enable=YES >> /mnt/etc/rc.conf
echo ifconfig_em0="inet 192.168.0.10/24" >> /mnt/etc/rc.conf
echo hostname=usbzfs >> /mnt/etc/rc.conf
Do NOT export the ZFS pool.
To reboot use the reboot
command. OR to power off, use the poweroff
command.
Plug it into your target system. Power on, and make sure it attempts to boot from the USB device.