3 # Install loader, kernel, and enough of userland to boot in QEMU and echo
4 # "Hello world." from init, as a very quick smoke test for CI. Uses QEMU's
5 # virtual FAT filesystem to avoid the need to create a disk image. While
6 # designed for CI automated testing, this script can also be run by hand as
7 # a quick smoke-test. The rootgen.sh and related scripts generate much more
8 # extensive tests for many combinations of boot env (ufs, zfs, geli, etc).
22 trap - EXIT SIGINT SIGHUP SIGTERM SIGQUIT
28 # Create minimal directory structure and populate it.
29 # Caller must cd ${SRCTOP} before calling this function.
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.
37 make -DNO_ROOT DESTDIR=${ROOTDIR} \
39 WITHOUT_DEBUG_FILES=yes \
40 WITHOUT_KERNEL_SYMBOLS=yes \
43 lib/libc lib/libedit lib/ncurses \
45 bin/sh sbin/init sbin/shutdown sbin/sysctl; do
46 make -DNO_ROOT DESTDIR=${ROOTDIR} INSTALL="install -U" \
47 WITHOUT_DEBUG_FILES= \
55 # Put loader in standard EFI location.
56 mv ${ROOTDIR}/boot/loader.efi ${ROOTDIR}/efi/boot/BOOTx64.EFI
58 # Configuration files.
59 cat > ${ROOTDIR}/boot/loader.conf <<EOF
60 vfs.root.mountfrom="msdosfs:/dev/ada0s1"
64 cat > ${ROOTDIR}/etc/rc <<EOF
68 /sbin/sysctl vm.stats.vm.v_wire_count
72 # Entropy needed to boot, see r346250 and followup commits/discussion.
73 dd if=/dev/random of=${ROOTDIR}/boot/entropy bs=4k count=1
75 # Remove unnecessary files to keep FAT filesystem size down.
76 rm -rf ${ROOTDIR}/METALOG ${ROOTDIR}/usr/lib
79 # Locate the top of the source tree, to run make install from.
80 : ${SRCTOP:=$(make -V SRCTOP)}
81 if [ -z "${SRCTOP}" ]; then
82 die "Cannot locate top of source tree"
85 # Locate the uefi firmware file used by qemu.
86 : ${OVMF:=/usr/local/share/uefi-edk2-qemu/QEMU_UEFI_CODE-x86_64.fd}
87 if [ ! -r "${OVMF}" ]; then
88 echo "NOTE: UEFI firmware available in the uefi-edk2-qemu-x86_64 package" >&2
89 die "Cannot read UEFI firmware file ${OVMF}"
92 # Create a temp dir to hold the boot image.
93 ROOTDIR=$(mktemp -d -t ci-qemu-test-fat-root)
94 trap tempdir_cleanup EXIT SIGINT SIGHUP SIGTERM SIGQUIT
96 # Populate the boot image in a temp dir.
97 ( cd ${SRCTOP} && tempdir_setup )
100 : ${BOOTLOG:=${TMPDIR:-/tmp}/ci-qemu-test-boot.log}
102 qemu-system-x86_64 -m 256M -nodefaults \
103 -drive if=pflash,format=raw,readonly,file=${OVMF} \
104 -serial stdio -vga none -nographic -monitor none \
105 -snapshot -hda fat:${ROOTDIR} 2>&1 | tee ${BOOTLOG}
107 # Check whether we succesfully booted...
108 if grep -q 'Hello world.' ${BOOTLOG}; then
111 die "Did not boot successfully, see ${BOOTLOG}"