mkvm: Add script to create FCOS VM
Fedora CoreOS can be provisioned on a QEMU virtual machine by providing the Ignition configuration via `fw_cfg` value. Unfortunately, the `string` method does not work with JSON values, so we have to use `file`. The configuration file has to be uploaded via SFTP, rather than `virsh vol-import`, since the latter would create the file with the wrong permissions, and QEMU does not automatically adjust the permissions of files used this way (like it does for disks).master
parent
bdf31d7d1f
commit
fd7778c01a
7
Makefile
7
Makefile
|
@ -1,7 +1,8 @@
|
|||
.PHONY: \
|
||||
all \
|
||||
clean \
|
||||
publish
|
||||
publish \
|
||||
vm
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
|
@ -26,3 +27,7 @@ $(foreach t,$(wildcard *.yaml),$(eval $(call genrules,$(t))))
|
|||
publish: \
|
||||
nvr1.ign
|
||||
rsync -rti $^ files.pyrocufflink.blue:public_html/
|
||||
|
||||
vm: \
|
||||
$(VMNAME).ign
|
||||
sh mkvm.sh $(VMNAME)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
: "${POOL:=default}"
|
||||
: "${VCPUS:=2}"
|
||||
: "${MEMORY:=2048}"
|
||||
: "${DISK_SIZE:=10}"
|
||||
: "${NETWORK=network=prod}"
|
||||
|
||||
VMNAME="$1"
|
||||
|
||||
pooldir=$(virsh pool-dumpxml "${POOL}" | xmllint --xpath '//path/text()' -)
|
||||
|
||||
vmhost=$(virsh uri | cut -d/ -f3)
|
||||
ign="${pooldir}/${VMNAME}.ign"
|
||||
if [ -n "${vmhost}" ]; then
|
||||
scp -s "${VMNAME}".ign "${vmhost}:${ign}"
|
||||
else
|
||||
cp "${VMNAME}".ign "${ign}"
|
||||
fi
|
||||
|
||||
image=$(virsh vol-list "${POOL}" \
|
||||
| awk '/fedora-coreos-.*-qemu/{print $2}' \
|
||||
| sort -V \
|
||||
| tail -n1)
|
||||
|
||||
virt-install \
|
||||
--name "${VMNAME}" \
|
||||
--vcpus "${VCPUS}" \
|
||||
--memory "${MEMORY}" \
|
||||
--os-variant fedora-coreos-stable \
|
||||
--graphics none \
|
||||
--sound none \
|
||||
--disk size="${DISK_SIZE},backing_store=${image}" \
|
||||
${DISK:+--disk "${DISK}"} \
|
||||
--network "${NETWORK}" \
|
||||
--qemu-commandline="--fw_cfg name=opt/com.coreos/config,file=${ign}" \
|
||||
--import
|
||||
|
Loading…
Reference in New Issue