That's the cleanest and easiest to do. It's all doable by hand but there's a lot of ZFS datasets (with specific options) that should be created and the installer does it all automagically for you. And it's always nice to start with a fresh new install every once in a while. Definitely create a backup of the old system, you can selectively restore some items from it, like specific configuration files. Files from your home directory perhaps.Or do I need to install FreeBSD to create a ZFS system on the disk first in the first place?
#!/bin/sh
set -e
DISK="ada0"
POOL="zroot"
HOSTNAME="freebsd"
echo "=== Destroying disk ==="
gpart destroy -F ${DISK} || true
gpart create -s gpt ${DISK}
echo "=== Creating partitions ==="
gpart add -t efi -s 260M ${DISK}
gpart add -t freebsd-zfs ${DISK}
echo "=== Formatting EFI ==="
newfs_msdos -F 32 /dev/${DISK}p1
echo "=== Loading ZFS ==="
kldload zfs || true
echo "=== Creating ZFS pool ==="
zpool create -f -o ashift=12 \
-O atime=off \
-O compression=lz4 \
-O mountpoint=none \
${POOL} /dev/${DISK}p2
echo "=== Creating datasets ==="
zfs create -o mountpoint=none ${POOL}/ROOT
zfs create -o mountpoint=/ ${POOL}/ROOT/default
zfs create -o mountpoint=/tmp ${POOL}/tmp
zfs create -o mountpoint=/usr ${POOL}/usr
zfs create ${POOL}/usr/home
chmod 1777 /tmp
zpool set bootfs=${POOL}/ROOT/default ${POOL}
echo "=== Mounting target ==="
mkdir -p /mnt
mount -t zfs ${POOL}/ROOT/default /mnt
mkdir -p /mnt/boot/efi
mount -t msdosfs /dev/${DISK}p1 /mnt/boot/efi
echo "=== Installing base system ==="
cd /usr/freebsd-dist
tar -xpf base.txz -C /mnt
tar -xpf kernel.txz -C /mnt
echo "=== Configuring system ==="
cat << EOF > /mnt/etc/fstab
/dev/${DISK}p1 /boot/efi msdosfs rw 2 2
EOF
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo "hostname=\"${HOSTNAME}\"" >> /mnt/etc/rc.conf
echo 'ifconfig_DEFAULT="DHCP"' >> /mnt/etc/rc.conf
echo "=== Setting root password ==="
chroot /mnt passwd
echo "=== Installing EFI bootloader ==="
mkdir -p /mnt/boot/efi/EFI/FreeBSD
cp /mnt/boot/loader.efi /mnt/boot/efi/EFI/FreeBSD/bootx64.efi
echo "=== Cleanup ==="
zfs unmount -a
zpool export ${POOL}
echo "=== DONE ==="
echo "Remove install media and reboot."
That's the cleanest and easiest to do. It's all doable by hand but there's a lot of ZFS datasets (with specific options) that should be created and the installer does it all automagically for you. And it's always nice to start with a fresh new install every once in a while. Definitely create a backup of the old system, you can selectively restore some items from it, like specific configuration files. Files from your home directory perhaps.
Keep It Simple, Stupid?Do you mean copy /var/db/pkg/ from the backup?/var/db/pkgYou can copy the pkg files though, so you don’t have to redownload them.
Should I then expectMake sure you restore /var/db/pkg along with /usr/local. And /boot/module for any kernel modules from packages.
pkg list to show all the pkgs installed on the original system?In answer to my own question, that works fine. Sigh of relief..Should I then expectpkg listto show all the pkgs installed on the original system?
Too soon!In answer to my own question, that works fine. Sigh of relief..