Steps to build a FreeBSD VM image as a non-root user and boot it in QEMU:

export MAKEOBJDIRPREFIX=/tank/emaste/obj

# Build
make -j4 SRCCONF=/dev/null buildworld buildkernel
# Install
make -DNO_ROOT DESTDIR=$ROOTDIR SRCCONF=/dev/null installworld installkernel distribution

# Create fstab, and add it to the METALOG
echo '/dev/ufs/freebsd_root / ufs rw,noatime 1 1' > $ROOTDIR/etc/fstab
s=$(($(cat $ROOTDIR/etc/fstab | wc -c)))
echo "./etc/fstab type=file uname=root gname=wheel mode=0444 size=$s" >> $ROOTDIR/METALOG

makefs -B little -o label=freebsd_root -F $ROOTDIR/METALOG ufs $ROOTDIR
mkimg -s gpt -b $ROOTDIR/boot/pmbr -p efi:=$ROOTDIR/boot/boot1.efifat -p freebsd-boot:=$ROOTDIR/boot/gptboot -p freebsd-ufs:=ufs -p freebsd-swap::1M -o img

# Boot in QEMU (add -bios OVMF.fd for UEFI boot)
qemu-system-x86_64 -snapshot -hda img

(Note that the file system has no extra space and the system will complain about a full / after booting.)

EdMaste/BuildVM (last edited 2014-10-03T13:50:16+0000 by EdMaste)