|
| 1 | +#!/usr/bin/env zsh |
| 2 | +# usage: macos13/build-image.sh <snapshot_name> |
| 3 | +image_dir=${0:a:h} |
| 4 | +script_dir=${0:a:h}/.. |
| 5 | +. "$script_dir/common.sh" |
| 6 | +trap print_undo_commands EXIT |
| 7 | +cache_dir=$script_dir/cache |
| 8 | +. "$script_dir/download.sh" |
| 9 | +. "$script_dir/inject.sh" |
| 10 | +undo_commands=$(mktemp) |
| 11 | +image_name=servo-macos13 |
| 12 | +snapshot_name=$1; shift |
| 13 | + |
| 14 | +>&2 echo '[*] Caching downloads' |
| 15 | +download "$cache_dir" https://cloud-images.ubuntu.com/jammy/20241217/jammy-server-cloudimg-amd64.img 0d8345a343c2547e55ac815342e6cb4a593aa5556872651eb47e6856a2bb0cdd |
| 16 | + |
| 17 | +>&2 echo '[*] Creating zvol (if needed)' |
| 18 | +# TODO: find a more efficient way to do an idempotent zfs-clone(8) that retains the clone’s old snapshots? |
| 19 | +zfs list -Ho name "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" || zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" |
| 20 | + |
| 21 | +>&2 echo '[*] Creating libvirt guest (or recreating it with new config)' |
| 22 | +if virsh domstate -- "$image_name"; then |
| 23 | + virsh destroy -- "$image_name" || : # FIXME make this idempotent in a less noisy way? |
| 24 | + virsh undefine --nvram -- "$image_name" |
| 25 | +fi |
| 26 | +virt-clone --preserve-data --check path_in_use=off -o "$image_name.clean" -n "$image_name" --nvram /var/lib/libvirt/images/OSX-KVM/OVMF_VARS.$image_name.fd --skip-copy sda -f /dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name --skip-copy sdc |
| 27 | +cp /var/lib/libvirt/images/OSX-KVM/OVMF_VARS.{$image_name.clean,$image_name}.fd |
| 28 | + |
| 29 | +>&2 echo '[*] Writing disk image' |
| 30 | +# TODO: find a more efficient way to do an idempotent zfs-clone(8) that retains the clone’s old snapshots? |
| 31 | +dd status=progress bs=1M if="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.clean@automated" of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" |
| 32 | + |
| 33 | +>&2 echo '[*] Forcing update of partition block device geometry' |
| 34 | +# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks) |
| 35 | +blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" |
| 36 | +sleep 1 |
| 37 | + |
| 38 | +>&2 echo '[*] Waiting for partition block device to appear' |
| 39 | +partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name-part1 |
| 40 | +t=0; while ! test -e $partition_block_device; do |
| 41 | + if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then |
| 42 | + >&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + sleep 1 |
| 46 | + t=$((t+1)) |
| 47 | +done |
| 48 | + |
| 49 | +>&2 echo '[*] Configuring base image' |
| 50 | +./mount-runner.sh "$image_name" "$image_dir/configure-base.sh" |
| 51 | + |
| 52 | +>&2 echo '[*] Starting guest, to apply changes' |
| 53 | +virsh start "$image_name" |
| 54 | + |
| 55 | +>&2 echo '[*] Waiting for guest to shut down (max 2000 seconds)' # normally ~850 seconds |
| 56 | +if ! time virsh event --timeout 2000 -- "$image_name" lifecycle; then |
| 57 | + >&2 echo 'virsh event timed out!' |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | + |
| 61 | +>&2 echo '[*] Checking that Servo was built correctly' |
| 62 | +./mount-runner.sh "$image_name" sh -c 'ls init/built_servo_once_successfully' |
| 63 | + |
| 64 | +>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name@$snapshot_name" |
| 65 | +zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name@$snapshot_name" |
| 66 | + |
| 67 | +>&2 echo '[*] Done!' |
0 commit comments