Skip to content

Instantly share code, notes, and snippets.

@dch
Forked from johnko/instructions.md
Created January 9, 2017 07:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dch/6e67929be4b34d29c898f97588cf6167 to your computer and use it in GitHub Desktop.
Installing FreeBSD on a USB drive with ZFS using bsdinstall unattended

Installing FreeBSD on a USB drive with ZFS using bsdinstall unattended

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

1. Plug in USB to exsting FreeBSD system.

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 )


2. Wipe the USB drive partition table

dd if=/dev/zero of=/dev/YourDriveHere bs=1m count=5

3. Switch to /bin/sh

/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

4. BSDInstall to create the partition table

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

5. BSDInstall to fetch and checksum

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.


6. BSDInstall to extract

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

7. Copy tmp fstab to new fstab

cat ${BSDINSTALL_TMPETC}/fstab >> /mnt/etc/fstab

chmod 600 /mnt/etc/fstab

8. Now would be a good time to perform a ZFS snapshot of your clean system

zfs snap -r $ZFSBOOT_POOL_NAME@new_install

9. Set the DNS in the new system

(or however you want)

cat /etc/resolv.conf > /mnt/etc/resolv.conf

10. Try a chrooted freebsd-update

chroot /mnt freebsd-update fetch install

11. Set the root password on the new system

chroot /mnt passwd

12. Do anything else on the new installation before rebooting

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

13. Reboot or power off

Do NOT export the ZFS pool.

To reboot use the reboot command. OR to power off, use the poweroff command.


14. Now see if you can boot from this new USB

Plug it into your target system. Power on, and make sure it attempts to boot from the USB device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment