diff --git a/README.md b/README.md index 96c43c8..c2dade7 100644 --- a/README.md +++ b/README.md @@ -115,10 +115,6 @@ To build the base vm image: - Windows 10 (multi-edition ISO), English (United States): [Win10_22H2_English_x64v1.iso](https://www.microsoft.com/en-us/software-download/windows10ISO) (sha256 = a6f470ca6d331eb353b815c043e327a347f594f37ff525f17764738fe812852e) - Run the build script: `windows10/build-image.sh` - FIXME: if Windows fails to autologon (stuck at lock screen): `virsh reboot servo-windows10.new` -- Destroy the old base image (if it exists): `zfs destroy -r tank/base/servo-windows10` -- Rename the new base image: `zfs rename tank/base/servo-windows10{.new,}` -- Create the base libvirt guest (if it doesn’t exist): `virt-clone --preserve-data --check path_in_use=off -o servo-windows10.new -n servo-windows10 -f /dev/zvol/tank/base/servo-windows10` -- Undefine the temporary libvirt guest: `virsh undefine servo-windows10.new` To clone and start a new runner: @@ -134,10 +130,6 @@ Runners created from this image preinstall all dependencies (including those spe To build the base vm image: - Run the build script: `ubuntu2204/build-image.sh` -- Destroy the old base image (if it exists): `zfs destroy -r tank/base/servo-ubuntu2204` -- Rename the new base image: `zfs rename tank/base/servo-ubuntu2204{.new,}` -- Create the base libvirt guest (if it doesn’t exist): `virt-clone --preserve-data --check path_in_use=off -o servo-ubuntu2204.new -n servo-ubuntu2204 -f /dev/zvol/tank/base/servo-ubuntu2204` -- Undefine the temporary libvirt guest: `virsh undefine servo-ubuntu2204.new` To clone and start a new runner: diff --git a/monitor/monitor.toml.example b/monitor/monitor.toml.example index 953fcee..08135c6 100644 --- a/monitor/monitor.toml.example +++ b/monitor/monitor.toml.example @@ -8,23 +8,9 @@ base_image_snapshot = "ready" github_runner_label = "self-hosted-image:windows10" target_count = 2 -[profiles."servo-windows10.new"] -configuration_name = "windows10" -base_vm_name = "servo-windows10.new" -base_image_snapshot = "ready" -github_runner_label = "self-hosted-image:windows10.new" -target_count = 0 - [profiles.servo-ubuntu2204] configuration_name = "ubuntu2204" base_vm_name = "servo-ubuntu2204" base_image_snapshot = "ready" github_runner_label = "self-hosted-image:ubuntu2204" target_count = 2 - -[profiles."servo-ubuntu2204.new"] -configuration_name = "ubuntu2204" -base_vm_name = "servo-ubuntu2204.new" -base_image_snapshot = "ready" -github_runner_label = "self-hosted-image:ubuntu2204.new" -target_count = 0 diff --git a/ubuntu2204/build-image.sh b/ubuntu2204/build-image.sh index 39f5c87..63d52d4 100755 --- a/ubuntu2204/build-image.sh +++ b/ubuntu2204/build-image.sh @@ -16,30 +16,40 @@ download "$cache_dir" https://cloud-images.ubuntu.com/jammy/20241217/jammy-serve >&2 echo '[*] Converting qcow2 image to raw image' qemu-img convert -f qcow2 -O raw "$cache_dir/jammy-server-cloudimg-amd64.img" "$cache_dir/jammy-server-cloudimg-amd64.raw" ->&2 echo '[*] Creating zvol and libvirt guest' -zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" ->> $undo_commands echo "zfs destroy '$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new'" +>&2 echo '[*] Creating zvol (if needed)' +zfs list -Ho name "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" || zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" + +>&2 echo '[*] Creating libvirt guest (or recreating it with new config)' +if virsh domstate -- "$image_name"; then + virsh undefine -- "$image_name" +fi virsh define -- "$image_dir/guest.xml" ->> $undo_commands echo "virsh undefine -- '$image_name.init'" -virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name.new" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" ->> $undo_commands echo "virsh undefine -- '$image_name.new'" +virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" virsh undefine -- "$image_name.init" +>&2 echo '[*] Wiping zvol' +dd bs=1M count=1 if=/dev/zero of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" + >&2 echo '[*] Writing disk images' -dd status=progress bs=1M if="$cache_dir/jammy-server-cloudimg-amd64.raw" of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" +dd status=progress bs=1M if="$cache_dir/jammy-server-cloudimg-amd64.raw" of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" genisoimage -V CIDATA -R -o "/var/lib/libvirt/images/$image_name.config.iso" "$image_dir/user-data" "$image_dir/meta-data" >&2 echo '[*] Starting guest, to expand root filesystem' -virsh start "$image_name.new" +virsh start "$image_name" >&2 echo '[*] Waiting for guest to shut down (max 40 seconds)' # normally ~19 seconds -if ! time virsh event --timeout 40 -- "$image_name.new" lifecycle; then +if ! time virsh event --timeout 40 -- "$image_name" lifecycle; then >&2 echo 'virsh event timed out!' exit 1 fi +>&2 echo '[*] Forcing update of partition block device geometry' +# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks) +blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" +sleep 1 + >&2 echo '[*] Waiting for partition block device to appear' -partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new-part1 +partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name-part1 t=0; while ! test -e $partition_block_device; do if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then >&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device @@ -49,24 +59,21 @@ t=0; while ! test -e $partition_block_device; do t=$((t+1)) done ->&2 echo '[*] Forcing update of partition block device geometry' -# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks) -blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" - >&2 echo '[*] Configuring base image' -./mount-runner.sh "$image_name.new" "$image_dir/configure-base.sh" +./mount-runner.sh "$image_name" "$image_dir/configure-base.sh" >&2 echo '[*] Starting guest, to apply changes' -virsh start "$image_name.new" +virsh start "$image_name" >&2 echo '[*] Waiting for guest to shut down (max 2000 seconds)' # normally ~978 seconds -if ! time virsh event --timeout 2000 -- "$image_name.new" lifecycle; then +if ! time virsh event --timeout 2000 -- "$image_name" lifecycle; then >&2 echo 'virsh event timed out!' exit 1 fi ->&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready" -zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready" +snapshot=$(date -u +\%FT\%RZ) +>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot" +zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot" # TODO: check that servo was actually built correctly diff --git a/windows10/build-image.sh b/windows10/build-image.sh index e8c300c..a4b505e 100755 --- a/windows10/build-image.sh +++ b/windows10/build-image.sh @@ -13,30 +13,40 @@ image_name=servo-windows10 >&2 echo '[*] Caching downloads' download "$cache_dir" https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.240-1/virtio-win-0.1.240.iso ebd48258668f7f78e026ed276c28a9d19d83e020ffa080ad69910dc86bbcbcc6 ->&2 echo '[*] Creating zvol and libvirt guest' -zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" ->> $undo_commands echo "zfs destroy '$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new'" +>&2 echo '[*] Creating zvol (if needed)' +zfs list -Ho name "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" || zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" + +>&2 echo '[*] Creating libvirt guest (or recreating it with new config)' +if virsh domstate -- "$image_name"; then + virsh undefine -- "$image_name" +fi virsh define -- "$image_dir/guest.xml" ->> $undo_commands echo "virsh undefine -- '$image_name.init'" -virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name.new" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" ->> $undo_commands echo "virsh undefine -- '$image_name.new'" +virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" virsh undefine -- "$image_name.init" +>&2 echo '[*] Wiping zvol' +dd bs=1M count=1 if=/dev/zero of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" + >&2 echo '[*] Writing disk images' inject /var/lib/libvirt/images "$cache_dir/virtio-win-0.1.240.iso" genisoimage -J -o "/var/lib/libvirt/images/$image_name.config.iso" "$image_dir/autounattend.xml" >&2 echo '[*] Starting guest, to install Windows' -virsh start "$image_name.new" +virsh start "$image_name" >&2 echo '[*] Waiting for guest to shut down (max 640 seconds)' # normally ~313 seconds -if ! time virsh event --timeout 640 -- "$image_name.new" lifecycle; then +if ! time virsh event --timeout 640 -- "$image_name" lifecycle; then >&2 echo 'virsh event timed out!' exit 1 fi +>&2 echo '[*] Forcing update of partition block device geometry' +# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks) +blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" +sleep 1 + >&2 echo '[*] Waiting for partition block device to appear' -partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new-part1 +partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name-part1 t=0; while ! test -e $partition_block_device; do if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then >&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device @@ -46,24 +56,21 @@ t=0; while ! test -e $partition_block_device; do t=$((t+1)) done ->&2 echo '[*] Forcing update of partition block device geometry' -# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks) -blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new" - >&2 echo '[*] Configuring base image' -./mount-runner.sh "$image_name.new" "$image_dir/configure-base.sh" +./mount-runner.sh "$image_name" "$image_dir/configure-base.sh" >&2 echo '[*] Starting guest, to apply changes' -virsh start "$image_name.new" +virsh start "$image_name" >&2 echo '[*] Waiting for guest to shut down (max 2500 seconds)' # normally ~1218 seconds -if ! time virsh event --timeout 2500 -- "$image_name.new" lifecycle; then +if ! time virsh event --timeout 2500 -- "$image_name" lifecycle; then >&2 echo 'virsh event timed out!' exit 1 fi ->&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready" -zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready" +snapshot=$(date -u +\%FT\%RZ) +>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot" +zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot" # TODO: check that servo was actually built correctly