Skip to content

Instantly share code, notes, and snippets.

@euank
Last active July 31, 2017 04:54
Show Gist options
  • Save euank/7c030ce123fc35d71361c25b69abe3d0 to your computer and use it in GitHub Desktop.
Save euank/7c030ce123fc35d71361c25b69abe3d0 to your computer and use it in GitHub Desktop.
ignition example
function libvirt::domain::add_ignition() {
file=${1:?must set domain xml file}
ignition=${2:?must set ignition file path}
xmlstarlet ed -P -L -i "//domain" -t attr -n "xmlns:qemu" --value "http://libvirt.org/schemas/domain/qemu/1.0" "${file}"
xmlstarlet ed -P -L -s "//domain" -t elem -n "qemu:commandline" "${file}"
xmlstarlet ed -P -L -s "//domain/qemu:commandline" -t elem -n "qemu:arg" "${file}"
xmlstarlet ed -P -L -s "(//domain/qemu:commandline/qemu:arg)[1]" -t attr -n "value" -v "-fw_cfg" "${file}"
xmlstarlet ed -P -L -s "//domain/qemu:commandline" -t elem -n "qemu:arg" "${file}"
xmlstarlet ed -P -L -s "(//domain/qemu:commandline/qemu:arg)[2]" -t attr -n "value" -v "name=opt/com.coreos/config,file=${ignition}" "${file}"
}
#!/bin/bash
set -ex
source libvirt_ignition.sh
domain_file="${DISK}.domain.xml"
virt-install --virt-type=kvm --connect \
"qemu:///system" --memory ${MEMORY} -n "${NAME}" \
--vcpus 8 -v --os-variant=virtio26 --os-type linux \
--disk path="${DISK}",device=disk,bus=virtio,format=qcow2,cache="writeback" \
--boot=hd --network type=direct,source=enp3s0,source_mode=bridge,mac="${mac}",model=virtio \
--graphics=none --noautoconsole --network bridge=virbr1,model=virtio,mac="${internal_mac}" \
--print-xml > "${domain_file}"
./bin/ct < "${ignition_file}.yaml" > "${ignition_file}"
libvirt::domain::add_ignition "${domain_file}" "${ignition_file}"
virsh define "${domain_file}"
virsh start "${NAME}"
@funwun
Copy link

funwun commented Jul 31, 2017

I get this error when I start vm

QEMU emulator version 2.8.1.1

-rwxrwxrwx 1 libvirt-qemu kvm 262 Jul 31 12:49 config.ign

error: internal error: process exited while connecting to monitor: 2017-07-31T04:52:22.223191Z qemu-system-x86_64: -fw_cfg name=opt/com.coreos/config,file=/var/lib/libvirt/images/config.ign: can't load /var/lib/libvirt/images/config.ign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment