feat: Add VM control script with libvirt support
Added comprehensive VM management script for testing Football ISO using libvirt/virsh instead of direct QEMU commands. 1. **VM Control Script** (scripts/qvm.sh): - Define VM in libvirt with proper XML - Start/stop VM with virsh commands - Reboot VM with virsh - Check VM status - Open VNC console viewer - Delete VM, disk, and ISO 2. **VM Configuration**: - Name: football-test - Memory: 2GB RAM - CPUs: 2 - Disk: 8GB qcow2 - Display: VNC (auto-port, localhost) - Network: user (NAT) - Boot: ISO (Football installer) - OS: Debian 13 (Trixie) 3. **Integration with virt-manager**: - VM shows in virsh list - Manageable via virt-manager GUI - VNC connection: localhost:5900 - Standard libvirt XML definition 4. **Usage**: ./scripts/qvm.sh define - Define VM in libvirt ./scripts/qvm.sh start - Start VM ./scripts/qvm.sh stop - Stop VM ./scripts/qvm.sh status - Check status ./scripts/qvm.sh console - Open VNC viewer ./scripts/qvm.sh delete - Delete VM and files Files Added: - scripts/qvm.sh (VM control script with libvirt support) Files Created (by VM definition): - output/football-vm-disk.qcow2 (8GB VM disk) - output/football-test.xml (libvirt VM definition) Output: - output/football-installer.iso (940MB, bootable Football ISO) VM Status: - Running in libvirt - Visible in: virsh list - VNC: localhost:5900 - Disk: 8GB qcow2 💘 Generated with Crush Assisted-by: GLM-4.7 via Crush <crush@charm.land>
This commit is contained in:
181
scripts/qvm.sh
Executable file
181
scripts/qvm.sh
Executable file
@@ -0,0 +1,181 @@
|
||||
#!/bin/bash
|
||||
# Football VM Control Script (libvirt/virsh)
|
||||
# Manages QEMU VM for testing Football ISO
|
||||
|
||||
set -e
|
||||
|
||||
BUILD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
ISO_FILE="$BUILD_DIR/output/football-installer.iso"
|
||||
DISK_FILE="$BUILD_DIR/output/football-vm-disk.qcow2"
|
||||
VM_NAME="football-test"
|
||||
XML_FILE="$BUILD_DIR/output/${VM_NAME}.xml"
|
||||
|
||||
# Create directories
|
||||
mkdir -p "$(dirname "$ISO_FILE")"
|
||||
mkdir -p "$(dirname "$DISK_FILE")"
|
||||
mkdir -p "$(dirname "$XML_FILE")"
|
||||
|
||||
case "$1" in
|
||||
define)
|
||||
echo "Defining VM in libvirt..."
|
||||
|
||||
# Create disk if it doesn't exist
|
||||
if [ ! -f "$DISK_FILE" ]; then
|
||||
echo "Creating VM disk (8GB)..."
|
||||
qemu-img create -f qcow2 "$DISK_FILE" 8G
|
||||
fi
|
||||
|
||||
# Create libvirt XML
|
||||
cat > "$XML_FILE" <<EOF
|
||||
<domain type='kvm'>
|
||||
<name>$VM_NAME</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/qemu/libosinfo/1.0">
|
||||
<libosinfo:os id="http://debian.org/debian/13"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit='KiB'>2097152</memory>
|
||||
<currentMemory unit='KiB'>2097152</currentMemory>
|
||||
<vcpu placement='static'>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
</features>
|
||||
<cpu mode='host-passthrough' check='none' migratable='on'/>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='$ISO_FILE'/>
|
||||
<target dev='sda' bus='sata'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='$DISK_FILE'/>
|
||||
<target dev='sdb' bus='sata'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='user'>
|
||||
<mac address='52:54:00:00:00:01'/>
|
||||
<model type='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</interface>
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
|
||||
<listen type='address' address='127.0.0.1'/>
|
||||
</graphics>
|
||||
<video>
|
||||
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
|
||||
</video>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
||||
EOF
|
||||
|
||||
# Define VM in libvirt
|
||||
virsh define "$XML_FILE"
|
||||
|
||||
echo "VM defined in libvirt"
|
||||
echo ""
|
||||
echo "Manage with:"
|
||||
echo " virsh start $VM_NAME"
|
||||
echo " virsh stop $VM_NAME"
|
||||
echo " virt-manager (view in GUI)"
|
||||
;;
|
||||
|
||||
undefine)
|
||||
echo "Undefining VM from libvirt..."
|
||||
virsh shutdown "$VM_NAME" 2>/dev/null || true
|
||||
sleep 2
|
||||
virsh undefine "$VM_NAME" && echo "VM undefined"
|
||||
;;
|
||||
|
||||
start)
|
||||
echo "Starting VM..."
|
||||
virsh start "$VM_NAME"
|
||||
echo ""
|
||||
virsh list
|
||||
echo ""
|
||||
echo "VM is running. View in:"
|
||||
echo " 1. virt-manager"
|
||||
echo " 2. vncviewer localhost:5900"
|
||||
;;
|
||||
|
||||
stop)
|
||||
echo "Stopping VM..."
|
||||
virsh shutdown "$VM_NAME" && echo "VM stopped" || virsh destroy "$VM_NAME" && echo "VM destroyed"
|
||||
;;
|
||||
|
||||
reboot)
|
||||
echo "Rebooting VM..."
|
||||
virsh reboot "$VM_NAME"
|
||||
;;
|
||||
|
||||
status)
|
||||
echo "Checking VM status..."
|
||||
virsh list --all | grep -E "Name|$VM_NAME"
|
||||
;;
|
||||
|
||||
console)
|
||||
echo "Opening VNC console..."
|
||||
if command -v vncviewer &> /dev/null; then
|
||||
vncviewer localhost:5900
|
||||
elif command -v remote-viewer &> /dev/null; then
|
||||
remote-viewer vnc://localhost:5900
|
||||
else
|
||||
echo "Error: No VNC viewer found"
|
||||
echo "Install: sudo apt-get install tigervnc-viewer virt-viewer"
|
||||
fi
|
||||
;;
|
||||
|
||||
delete)
|
||||
echo "WARNING: This will delete VM, disk, and ISO!"
|
||||
echo "Press Ctrl+C to cancel, or Enter to continue..."
|
||||
read
|
||||
|
||||
# Stop VM
|
||||
virsh destroy "$VM_NAME" 2>/dev/null || true
|
||||
virsh undefine "$VM_NAME" 2>/dev/null || true
|
||||
|
||||
# Delete files
|
||||
rm -f "$DISK_FILE"
|
||||
rm -f "$ISO_FILE"
|
||||
rm -f "$XML_FILE"
|
||||
|
||||
echo "VM, disk, and ISO deleted"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Football VM Control Script (libvirt)"
|
||||
echo ""
|
||||
echo "Usage: $0 {define|undefine|start|stop|reboot|status|console|delete}"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " define - Create VM definition in libvirt"
|
||||
echo " undefine - Remove VM from libvirt"
|
||||
echo " start - Start VM"
|
||||
echo " stop - Stop VM"
|
||||
echo " reboot - Reboot VM"
|
||||
echo " status - Check VM status"
|
||||
echo " console - Open VNC console viewer"
|
||||
echo " delete - Delete VM, disk, and ISO (CAUTION!)"
|
||||
echo ""
|
||||
echo "VM Details:"
|
||||
echo " Name: $VM_NAME"
|
||||
echo " Disk: $DISK_FILE"
|
||||
echo " ISO: $ISO_FILE"
|
||||
echo " XML: $XML_FILE"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user