|
|
@ -28,7 +28,13 @@ trap cleanup EXIT |
|
|
|
|
|
|
|
|
# Create a temporary directory to hold the VM image and copy the base image there |
|
|
# Create a temporary directory to hold the VM image and copy the base image there |
|
|
install -m 0710 -o root -g qemu --context=system_u:object_r:virt_image_t:s0 -d "$temp_dir" |
|
|
install -m 0710 -o root -g qemu --context=system_u:object_r:virt_image_t:s0 -d "$temp_dir" |
|
|
install -m 0770 -o root -g qemu --context=system_u:object_r:virt_image_t:s0 "/usr/local/libvirt/images/${VM}/qcow2/disk.qcow2" "$temp_dir/root.qcow2" |
|
|
|
|
|
|
|
|
# Pull the base image defined in the environment file |
|
|
|
|
|
podman artifact pull "${DOMAIN_DISK_SOURCE}" |
|
|
|
|
|
podman artifact extract "${DOMAIN_DISK_SOURCE}" "$temp_dir/root.qcow2" |
|
|
|
|
|
chown root:qemu "$temp_dir/root.qcow2" |
|
|
|
|
|
chmod 0660 "$temp_dir/root.qcow2" |
|
|
|
|
|
chcon system_u:object_r:virt_image_t:s0 "$temp_dir/root.qcow2" |
|
|
|
|
|
|
|
|
# Inject the Flightctl configuration file (w/ enrollment certificates) into the VM image |
|
|
# Inject the Flightctl configuration file (w/ enrollment certificates) into the VM image |
|
|
# Note: The injected config file will be moved to the right place in the VM by a systemd override in the base image |
|
|
# Note: The injected config file will be moved to the right place in the VM by a systemd override in the base image |
|
|
@ -39,6 +45,7 @@ if [ -f /etc/flightctl/config.yaml ]; then |
|
|
else |
|
|
else |
|
|
cp /etc/flightctl/config.yaml "$temp_dir/config.yaml" |
|
|
cp /etc/flightctl/config.yaml "$temp_dir/config.yaml" |
|
|
fi |
|
|
fi |
|
|
|
|
|
echo "Injecting Flightctl configuration into the VM image..." |
|
|
guestfish --add "$temp_dir/root.qcow2" -m /dev/sda4 <<EOF |
|
|
guestfish --add "$temp_dir/root.qcow2" -m /dev/sda4 <<EOF |
|
|
copy-in $temp_dir/config.yaml /ostree/deploy/default/var/lib/private/flightctl/ |
|
|
copy-in $temp_dir/config.yaml /ostree/deploy/default/var/lib/private/flightctl/ |
|
|
EOF |
|
|
EOF |
|
|
@ -47,16 +54,19 @@ fi |
|
|
# Inject the OSTree auth.json file into the VM image if it exists on the host |
|
|
# Inject the OSTree auth.json file into the VM image if it exists on the host |
|
|
# Note: The injected config file will be moved to the right place in the VM by a systemd override in the base image |
|
|
# Note: The injected config file will be moved to the right place in the VM by a systemd override in the base image |
|
|
if [ -f /etc/ostree/auth.json ]; then |
|
|
if [ -f /etc/ostree/auth.json ]; then |
|
|
|
|
|
echo "Injecting OSTree auth.json into the VM image..." |
|
|
guestfish --add "$temp_dir/root.qcow2" -m /dev/sda4 <<'EOF' |
|
|
guestfish --add "$temp_dir/root.qcow2" -m /dev/sda4 <<'EOF' |
|
|
copy-in /etc/ostree/auth.json /ostree/deploy/default/var/lib/private/flightctl/ |
|
|
copy-in /etc/ostree/auth.json /ostree/deploy/default/var/lib/private/flightctl/ |
|
|
EOF |
|
|
EOF |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
# Copy the VM image to the libvirt images directory |
|
|
# Copy the VM image to the libvirt images directory |
|
|
|
|
|
echo "Copying the VM disk to the libvirt images directory..." |
|
|
install -m 0710 -o root -g qemu -Z -d "/var/lib/libvirt/images/${VM}" |
|
|
install -m 0710 -o root -g qemu -Z -d "/var/lib/libvirt/images/${VM}" |
|
|
install -m 0660 -o root -g qemu -Z "$temp_dir/root.qcow2" "/var/lib/libvirt/images/${VM}/root.qcow2" |
|
|
install -m 0660 -o root -g qemu -Z "$temp_dir/root.qcow2" "/var/lib/libvirt/images/${VM}/root.qcow2" |
|
|
|
|
|
|
|
|
# Create and start the VM using virt-install |
|
|
# Create and start the VM using virt-install |
|
|
|
|
|
echo "Creating and starting the VM ${VM}..." |
|
|
virt-install --name "${VM}" \ |
|
|
virt-install --name "${VM}" \ |
|
|
--autostart \ |
|
|
--autostart \ |
|
|
--cpu=host-passthrough \ |
|
|
--cpu=host-passthrough \ |
|
|
@ -72,4 +82,8 @@ virt-install --name "${VM}" \ |
|
|
--noautoconsole |
|
|
--noautoconsole |
|
|
|
|
|
|
|
|
echo "VM ${VM} has been created and started." |
|
|
echo "VM ${VM} has been created and started." |
|
|
|
|
|
|
|
|
|
|
|
# Cleanup the pulled image |
|
|
|
|
|
podman artifact rm "${DOMAIN_DISK_SOURCE}" || true |
|
|
|
|
|
|
|
|
exit 0 |
|
|
exit 0 |
|
|
|