Operations

Virtualization

libvirt / KVM guest management with virsh — list, dump, define, resize, bulk-export.

2 tasks

This page is a scrubbed, public-safe version of an internal AI/SI operations runbook — the command cheat-sheet a systems engineer builds up over years of running Linux servers, virtualisation hosts, firewalls, databases, certificates and Raspberry Pi devices.

It is organised into the same sections as the original workbook, one page each — reach any of them from the AI/SI Prompts menu above. Every task on this page shows three things:

The point of the AI-prompt column is to show how a pile of accumulated tribal knowledge can be turned into something an assistant can reproduce and improve on demand: you keep the intent, and let the model rewrite the mechanics for whatever host you are on today. Nothing on this page should be run without reading it first — several snippets are destructive (dd, rm -rf, postsuper -d ALL, firewall reloads).

libvirt / virsh guest management

Uses libvirt's virsh to list, dump, define, undefine, start and resize KVM guest domains, including looping over every guest to export its XML.

Commands
<GUEST>
# List all domains
virsh list --all
# Dump a configuration file
virsh dumpxml <GUEST> > <GUEST>.$HOSTNAME.110410.xml
# Persist a domain
virsh define <GUEST>.$HOSTNAME.110410.xml
# Undefine a domain
virsh undefine <GUEST>
# Just start a domain (does not save)
virsh create <GUEST>.$HOSTNAME.110410.xml
# Increase the size of the VM
truncate --size=+6G <GUEST>
# Get list of raw VM names
virsh list --all | tail -n+3 | cut -f4 -d' '
# Dump all VM configurations
for vm in `virsh list --all | tail -n+3 | cut -f4 -d' '`; do virsh dumpxml $vm > $vm.`date +%y%m%d`.xml; done
# Set SELinux permissions
chcon system_u:object_r:svirt_image_t:s0 <GUEST>.img
# Use an existing SELinux context
chcon --reference=/etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca.crt
AI prompt

Generate a Bash script for the task “libvirt / virsh guest management”. Parameterise the guest name; provide list/dumpxml/define/undefine/create commands and a loop that dumps every domain to <name>.<host>.<date>.xml. Assume CentOS/RHEL or Raspberry Pi OS as appropriate, comment each step, and never hard-code a real credential — read secrets from the environment.

Get just the virtual names

Lists only the domain names from virsh list --all, then dumps each one’s XML to a dated file.

Commands
virsh list --all | sed -n '3,${/./!bz;p;:z}' | cut -f4 -d" "
# To export all VM settings
for vm in `virsh list --all | sed -n '3,${/./!bz;p;:z}' | cut -f4 -d" "`; do virsh dumpxml "$vm" > "$vm.$HOSTNAME.`date +%y%m%d`.xml"; done
AI prompt

Generate a Bash script for the task “Get just the virtual names”. Use virsh list --all --name to get the domain names, skip blank lines, and dump each domain’s XML to <name>.<host>.<date>.xml in a parameterised output directory. Assume CentOS/RHEL or Raspberry Pi OS as appropriate, comment each step, and never hard-code a real credential — read secrets from the environment.