xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/qemu-2-start.sh (revision bd66c1b43e33540205dbc1187c2f2a15c58b57ba)
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-09-16"
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  freebsd13r)
66    OSNAME="FreeBSD 13.4-RELEASE"
67    OSv="freebsd13.0"
68    URLzs="$FREEBSD/amd64-freebsd-13.4-RELEASE.qcow2.zst"
69    BASH="/usr/local/bin/bash"
70    NIC="rtl8139"
71    ;;
72  freebsd13)
73    OSNAME="FreeBSD 13.4-STABLE"
74    OSv="freebsd13.0"
75    URLzs="$FREEBSD/amd64-freebsd-13.4-STABLE.qcow2.zst"
76    BASH="/usr/local/bin/bash"
77    NIC="rtl8139"
78    ;;
79  freebsd14r)
80    OSNAME="FreeBSD 14.1-RELEASE"
81    OSv="freebsd14.0"
82    URLzs="$FREEBSD/amd64-freebsd-14.1-RELEASE.qcow2.zst"
83    BASH="/usr/local/bin/bash"
84    ;;
85  freebsd14)
86    OSNAME="FreeBSD 14.1-STABLE"
87    OSv="freebsd14.0"
88    URLzs="$FREEBSD/amd64-freebsd-14.1-STABLE.qcow2.zst"
89    BASH="/usr/local/bin/bash"
90    ;;
91  freebsd15)
92    OSNAME="FreeBSD 15.0-CURRENT"
93    OSv="freebsd14.0"
94    URLzs="$FREEBSD/amd64-freebsd-15.0-CURRENT.qcow2.zst"
95    BASH="/usr/local/bin/bash"
96    ;;
97  tumbleweed)
98    OSNAME="openSUSE Tumbleweed"
99    OSv="opensusetumbleweed"
100    MIRROR="http://opensuse-mirror-gce-us.susecloud.net"
101    URL="$MIRROR/tumbleweed/appliances/openSUSE-MicroOS.x86_64-OpenStack-Cloud.qcow2"
102    ;;
103  ubuntu20)
104    OSNAME="Ubuntu 20.04"
105    OSv="ubuntu20.04"
106    URL="$UBMIRROR/focal/current/focal-server-cloudimg-amd64.img"
107    ;;
108  ubuntu22)
109    OSNAME="Ubuntu 22.04"
110    OSv="ubuntu22.04"
111    URL="$UBMIRROR/jammy/current/jammy-server-cloudimg-amd64.img"
112    ;;
113  ubuntu24)
114    OSNAME="Ubuntu 24.04"
115    OSv="ubuntu24.04"
116    URL="$UBMIRROR/noble/current/noble-server-cloudimg-amd64.img"
117    ;;
118  *)
119    echo "Wrong value for OS variable!"
120    exit 111
121    ;;
122esac
123
124# environment file
125ENV="/var/tmp/env.txt"
126echo "ENV=$ENV" >> $ENV
127
128# result path
129echo 'RESPATH="/var/tmp/test_results"' >> $ENV
130
131# FreeBSD 13 has problems with: e1000+virtio
132echo "NIC=$NIC" >> $ENV
133
134# freebsd15 -> used in zfs-qemu.yml
135echo "OS=$OS" >> $ENV
136
137# freebsd14.0 -> used for virt-install
138echo "OSv=\"$OSv\"" >> $ENV
139
140# FreeBSD 15 (Current) -> used for summary
141echo "OSNAME=\"$OSNAME\"" >> $ENV
142
143sudo mkdir -p "/mnt/tests"
144sudo chown -R $(whoami) /mnt/tests
145
146# we are downloading via axel, curl and wget are mostly slower and
147# require more return value checking
148IMG="/mnt/tests/cloudimg.qcow2"
149if [ ! -z "$URLzs" ]; then
150  echo "Loading image $URLzs ..."
151  time axel -q -o "$IMG.zst" "$URLzs"
152  zstd -q -d --rm "$IMG.zst"
153else
154  echo "Loading image $URL ..."
155  time axel -q -o "$IMG" "$URL"
156fi
157
158DISK="/dev/zvol/zpool/openzfs"
159FORMAT="raw"
160sudo zfs create -ps -b 64k -V 80g zpool/openzfs
161while true; do test -b $DISK && break; sleep 1; done
162echo "Importing VM image to zvol..."
163sudo qemu-img dd -f qcow2 -O raw if=$IMG of=$DISK bs=4M
164rm -f $IMG
165
166PUBKEY=$(cat ~/.ssh/id_ed25519.pub)
167cat <<EOF > /tmp/user-data
168#cloud-config
169
170fqdn: $OS
171
172users:
173- name: root
174  shell: $BASH
175- name: zfs
176  sudo: ALL=(ALL) NOPASSWD:ALL
177  shell: $BASH
178  ssh_authorized_keys:
179    - $PUBKEY
180
181growpart:
182  mode: auto
183  devices: ['/']
184  ignore_growroot_disabled: false
185EOF
186
187sudo virsh net-update default add ip-dhcp-host \
188  "<host mac='52:54:00:83:79:00' ip='192.168.122.10'/>" --live --config
189
190sudo virt-install \
191  --os-variant $OSv \
192  --name "openzfs" \
193  --cpu host-passthrough \
194  --virt-type=kvm --hvm \
195  --vcpus=4,sockets=1 \
196  --memory $((1024*12)) \
197  --memballoon model=virtio \
198  --graphics none \
199  --network bridge=virbr0,model=$NIC,mac='52:54:00:83:79:00' \
200  --cloud-init user-data=/tmp/user-data \
201  --disk $DISK,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
202  --import --noautoconsole >/dev/null
203
204# in case the directory isn't there already
205mkdir -p $HOME/.ssh
206
207cat <<EOF >> $HOME/.ssh/config
208# no questions please
209StrictHostKeyChecking no
210
211# small timeout, used in while loops later
212ConnectTimeout 1
213EOF
214