1#!/usr/bin/env bash 2 3###################################################################### 4# 2) start qemu with some operating system, init via cloud-init 5###################################################################### 6 7set -eu 8 9# short name used in zfs-qemu.yml 10OS="$1" 11 12# OS variant (virt-install --os-variant list) 13OSv=$OS 14 15# compressed with .zst extension 16REPO="https://github.com/mcmilk/openzfs-freebsd-images" 17FREEBSD="$REPO/releases/download/v2024-10-05" 18URLzs="" 19 20# Ubuntu mirrors 21#UBMIRROR="https://cloud-images.ubuntu.com" 22#UBMIRROR="https://mirrors.cloud.tencent.com/ubuntu-cloud-images" 23UBMIRROR="https://mirror.citrahost.com/ubuntu-cloud-images" 24 25# default nic model for vm's 26NIC="virtio" 27 28case "$OS" in 29 almalinux8) 30 OSNAME="AlmaLinux 8" 31 URL="https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2" 32 ;; 33 almalinux9) 34 OSNAME="AlmaLinux 9" 35 URL="https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2" 36 ;; 37 archlinux) 38 OSNAME="Archlinux" 39 URL="https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2" 40 # dns sometimes fails with that url :/ 41 echo "89.187.191.12 geo.mirror.pkgbuild.com" | sudo tee /etc/hosts > /dev/null 42 ;; 43 centos-stream9) 44 OSNAME="CentOS Stream 9" 45 URL="https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2" 46 ;; 47 debian11) 48 OSNAME="Debian 11" 49 URL="https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2" 50 ;; 51 debian12) 52 OSNAME="Debian 12" 53 URL="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2" 54 ;; 55 fedora39) 56 OSNAME="Fedora 39" 57 OSv="fedora39" 58 URL="https://download.fedoraproject.org/pub/fedora/linux/releases/39/Cloud/x86_64/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2" 59 ;; 60 fedora40) 61 OSNAME="Fedora 40" 62 OSv="fedora39" 63 URL="https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2" 64 ;; 65 freebsd13-3r) 66 OSNAME="FreeBSD 13.3-RELEASE" 67 OSv="freebsd13.0" 68 URLzs="$FREEBSD/amd64-freebsd-13.3-RELEASE.qcow2.zst" 69 BASH="/usr/local/bin/bash" 70 NIC="rtl8139" 71 ;; 72 freebsd13-4r) 73 OSNAME="FreeBSD 13.4-RELEASE" 74 OSv="freebsd13.0" 75 URLzs="$FREEBSD/amd64-freebsd-13.4-RELEASE.qcow2.zst" 76 BASH="/usr/local/bin/bash" 77 NIC="rtl8139" 78 ;; 79 freebsd14-0r) 80 OSNAME="FreeBSD 14.0-RELEASE" 81 OSv="freebsd14.0" 82 URLzs="$FREEBSD/amd64-freebsd-14.0-RELEASE.qcow2.zst" 83 BASH="/usr/local/bin/bash" 84 ;; 85 freebsd14-1r) 86 OSNAME="FreeBSD 14.1-RELEASE" 87 OSv="freebsd14.0" 88 URLzs="$FREEBSD/amd64-freebsd-14.1-RELEASE.qcow2.zst" 89 BASH="/usr/local/bin/bash" 90 ;; 91 freebsd13-4s) 92 OSNAME="FreeBSD 13.4-STABLE" 93 OSv="freebsd13.0" 94 URLzs="$FREEBSD/amd64-freebsd-13.4-STABLE.qcow2.zst" 95 BASH="/usr/local/bin/bash" 96 ;; 97 freebsd14-1s) 98 OSNAME="FreeBSD 14.1-STABLE" 99 OSv="freebsd14.0" 100 URLzs="$FREEBSD/amd64-freebsd-14.1-STABLE.qcow2.zst" 101 BASH="/usr/local/bin/bash" 102 ;; 103 freebsd15-0c) 104 OSNAME="FreeBSD 15.0-CURRENT" 105 OSv="freebsd14.0" 106 URLzs="$FREEBSD/amd64-freebsd-15.0-CURRENT.qcow2.zst" 107 BASH="/usr/local/bin/bash" 108 ;; 109 tumbleweed) 110 OSNAME="openSUSE Tumbleweed" 111 OSv="opensusetumbleweed" 112 MIRROR="http://opensuse-mirror-gce-us.susecloud.net" 113 URL="$MIRROR/tumbleweed/appliances/openSUSE-MicroOS.x86_64-OpenStack-Cloud.qcow2" 114 ;; 115 ubuntu20) 116 OSNAME="Ubuntu 20.04" 117 OSv="ubuntu20.04" 118 URL="$UBMIRROR/focal/current/focal-server-cloudimg-amd64.img" 119 ;; 120 ubuntu22) 121 OSNAME="Ubuntu 22.04" 122 OSv="ubuntu22.04" 123 URL="$UBMIRROR/jammy/current/jammy-server-cloudimg-amd64.img" 124 ;; 125 ubuntu24) 126 OSNAME="Ubuntu 24.04" 127 OSv="ubuntu24.04" 128 URL="$UBMIRROR/noble/current/noble-server-cloudimg-amd64.img" 129 ;; 130 *) 131 echo "Wrong value for OS variable!" 132 exit 111 133 ;; 134esac 135 136# environment file 137ENV="/var/tmp/env.txt" 138echo "ENV=$ENV" >> $ENV 139 140# result path 141echo 'RESPATH="/var/tmp/test_results"' >> $ENV 142 143# FreeBSD 13 has problems with: e1000+virtio 144echo "NIC=$NIC" >> $ENV 145 146# freebsd15 -> used in zfs-qemu.yml 147echo "OS=$OS" >> $ENV 148 149# freebsd14.0 -> used for virt-install 150echo "OSv=\"$OSv\"" >> $ENV 151 152# FreeBSD 15 (Current) -> used for summary 153echo "OSNAME=\"$OSNAME\"" >> $ENV 154 155sudo mkdir -p "/mnt/tests" 156sudo chown -R $(whoami) /mnt/tests 157 158# we are downloading via axel, curl and wget are mostly slower and 159# require more return value checking 160IMG="/mnt/tests/cloudimg.qcow2" 161if [ ! -z "$URLzs" ]; then 162 echo "Loading image $URLzs ..." 163 time axel -q -o "$IMG.zst" "$URLzs" 164 zstd -q -d --rm "$IMG.zst" 165else 166 echo "Loading image $URL ..." 167 time axel -q -o "$IMG" "$URL" 168fi 169 170DISK="/dev/zvol/zpool/openzfs" 171FORMAT="raw" 172sudo zfs create -ps -b 64k -V 80g zpool/openzfs 173while true; do test -b $DISK && break; sleep 1; done 174echo "Importing VM image to zvol..." 175sudo qemu-img dd -f qcow2 -O raw if=$IMG of=$DISK bs=4M 176rm -f $IMG 177 178PUBKEY=$(cat ~/.ssh/id_ed25519.pub) 179cat <<EOF > /tmp/user-data 180#cloud-config 181 182fqdn: $OS 183 184users: 185- name: root 186 shell: $BASH 187- name: zfs 188 sudo: ALL=(ALL) NOPASSWD:ALL 189 shell: $BASH 190 ssh_authorized_keys: 191 - $PUBKEY 192 193growpart: 194 mode: auto 195 devices: ['/'] 196 ignore_growroot_disabled: false 197EOF 198 199sudo virsh net-update default add ip-dhcp-host \ 200 "<host mac='52:54:00:83:79:00' ip='192.168.122.10'/>" --live --config 201 202sudo virt-install \ 203 --os-variant $OSv \ 204 --name "openzfs" \ 205 --cpu host-passthrough \ 206 --virt-type=kvm --hvm \ 207 --vcpus=4,sockets=1 \ 208 --memory $((1024*12)) \ 209 --memballoon model=virtio \ 210 --graphics none \ 211 --network bridge=virbr0,model=$NIC,mac='52:54:00:83:79:00' \ 212 --cloud-init user-data=/tmp/user-data \ 213 --disk $DISK,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \ 214 --import --noautoconsole >/dev/null 215 216# in case the directory isn't there already 217mkdir -p $HOME/.ssh 218 219cat <<EOF >> $HOME/.ssh/config 220# no questions please 221StrictHostKeyChecking no 222 223# small timeout, used in while loops later 224ConnectTimeout 1 225EOF 226