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