#!/bin/bash # Build the installer USB as a disk image FILE with build-usb.sh image mode, # then upload it into the libvirt 'default' pool as volume pxetest-usb.img. # # Usage: tests/vm/build-image.sh [--with-enrollment] [--with-boot-tools] # [--with-site-content] [--pick-nic] [--size SIZE] # Default skips enrollment/, bios-staging/, drivers-staging/, boot-tools/ # and site-content/ to keep the image small; SIZE defaults to "auto". # --pick-nic leaves both MACs out of site-vars: the first boot picks the # imaging NIC by its link and every other port is a DHCP client (start the # server with its GE NIC unplugged: virsh domif-setlink pxetest-server # 52:54:00:9e:10:01 down --config). # Env: PXETEST_PAYLOAD_ROOT (where offline-packages/, boot-files/... live) source "$(dirname "$0")/common.sh" SIZE=auto SKIPS=(--skip-enrollment --skip-bios --skip-drivers --skip-boot-tools --skip-site-content) PICK_NIC=0 while [ $# -gt 0 ]; do case "$1" in --with-enrollment) SKIPS=("${SKIPS[@]/--skip-enrollment}"); shift ;; --with-boot-tools) SKIPS=("${SKIPS[@]/--skip-boot-tools}"); shift ;; --with-site-content) SKIPS=("${SKIPS[@]/--skip-site-content}"); shift ;; --pick-nic) PICK_NIC=1; shift ;; --size) SIZE="$2"; shift 2 ;; *) die "unknown option $1" ;; esac done ARGS=() for s in "${SKIPS[@]}"; do [ -n "$s" ] && ARGS+=("$s"); done [ -f "$UBUNTU_ISO" ] || die "no ISO at $UBUNTU_ISO; run tests/vm/fetch-iso.sh" ensure_image_tools # Report what the payload root has and lacks (do not invent content). log "payload root: $PXETEST_PAYLOAD_ROOT" for d in offline-packages pip-wheels boot-files boot-tools enrollment bios-staging drivers-staging; do if [ -d "$PXETEST_PAYLOAD_ROOT/$d" ]; then printf ' %-17s %s\n' "$d" "$(du -shL "$PXETEST_PAYLOAD_ROOT/$d" 2>/dev/null | cut -f1)" else printf ' %-17s MISSING\n' "$d" fi done for f in ipxe-shimx64.efi ipxeboot.tar.gz wimboot boot.wim BCD boot.sdi bootx64.efi undionly.kpxe; do [ -f "$PXETEST_PAYLOAD_ROOT/boot-files/$f" ] || log " boot-files/$f MISSING" done if [ -e "$USB_IMAGE" ] && [ ! -f "$USB_IMAGE" ]; then die "$USB_IMAGE is not a regular file" fi # Site vars for the VM "site": pin the NICs by the fixed MACs from common.sh. SITE_VARS="$PXETEST_CACHE/site-vars.yml" if [ "$PICK_NIC" -eq 1 ]; then cat >"$SITE_VARS" <"$SITE_VARS" </dev/null fi log "uploading $USB_IMAGE ($((BYTES / 1048576)) MiB) to pool $POOL as $USB_VOL" virsh vol-create-as "$POOL" "$USB_VOL" "$BYTES" --format raw >/dev/null virsh vol-upload --pool "$POOL" --sparse "$USB_VOL" "$USB_IMAGE" log "done"