3 # Install pkgbase packages for loader, kernel, and enough of userland to boot
4 # in QEMU and echo "Hello world." from init, as a very quick smoke test for CI.
5 # Uses QEMU's virtual FAT filesystem to avoid the need to create a disk image.
6 # While designed for CI automated testing, this script can also be run by hand
7 # as a quick smoke-test as long as pkgbase packages have been built. The
8 # rootgen.sh and related scripts generate much more extensive tests for many
9 # combinations of boot env (ufs, zfs, geli, etc).
23 trap - EXIT SIGINT SIGHUP SIGTERM SIGQUIT
29 # Create minimal directory structure and populate it.
31 for dir in dev bin efi/boot etc lib libexec sbin usr/lib usr/libexec; do
32 mkdir -p ${ROOTDIR}/${dir}
35 # Install kernel, loader and minimal userland.
36 cat<<EOF >${ROOTDIR}/pkg.conf
38 repositories={local {url = file://$(dirname $OBJTOP)/repo/\${ABI}/latest}}
40 ASSUME_ALWAYS_YES=true INSTALL_AS_USER=true pkg \
41 -o ABI_FILE=$OBJTOP/bin/sh/sh \
42 -C ${ROOTDIR}/pkg.conf -r ${ROOTDIR} install \
43 FreeBSD-kernel-generic FreeBSD-bootloader \
44 FreeBSD-clibs FreeBSD-runtime
46 # Put loader in standard EFI location.
47 mv ${ROOTDIR}/boot/loader.efi ${ROOTDIR}/efi/boot/BOOTx64.EFI
49 # Configuration files.
50 cat > ${ROOTDIR}/boot/loader.conf <<EOF
51 vfs.root.mountfrom="msdosfs:/dev/ada0s1"
55 cat > ${ROOTDIR}/etc/rc <<EOF
59 /sbin/sysctl vm.stats.vm.v_wire_count
63 # Entropy needed to boot, see r346250 and followup commits/discussion.
64 dd if=/dev/random of=${ROOTDIR}/boot/entropy bs=4k count=1
66 # Remove unnecessary files to keep FAT filesystem size down.
67 rm -rf ${ROOTDIR}/METALOG ${ROOTDIR}/usr/lib
70 # Locate the top of the source tree, to run make install from.
71 : ${SRCTOP:=$(make -V SRCTOP)}
72 if [ -z "${SRCTOP}" ]; then
73 die "Cannot locate top of source tree"
75 : ${OBJTOP:=$(make -V OBJTOP)}
76 if [ -z "${OBJTOP}" ]; then
77 die "Cannot locate top of object tree"
80 # Locate the uefi firmware file used by qemu.
81 : ${OVMF:=/usr/local/share/uefi-edk2-qemu/QEMU_UEFI_CODE-x86_64.fd}
82 if [ ! -r "${OVMF}" ]; then
83 echo "NOTE: UEFI firmware available in the uefi-edk2-qemu-x86_64 package" >&2
84 die "Cannot read UEFI firmware file ${OVMF}"
87 # Create a temp dir to hold the boot image.
88 ROOTDIR=$(mktemp -d -t ci-qemu-test-fat-root)
89 trap tempdir_cleanup EXIT SIGINT SIGHUP SIGTERM SIGQUIT
91 # Populate the boot image in a temp dir.
92 ( cd ${SRCTOP} && tempdir_setup )
95 : ${BOOTLOG:=${TMPDIR:-/tmp}/ci-qemu-test-boot.log}
97 qemu-system-x86_64 -m 256M -nodefaults \
98 -drive if=pflash,format=raw,readonly,file=${OVMF} \
99 -serial stdio -vga none -nographic -monitor none \
100 -snapshot -hda fat:${ROOTDIR} 2>&1 | tee ${BOOTLOG}
102 # Check whether we succesfully booted...
103 if grep -q 'Hello world.' ${BOOTLOG}; then
106 die "Did not boot successfully, see ${BOOTLOG}"