| name | qemu-startup |
| description | Guidance for starting and configuring QEMU virtual machines with proper serial console access. This skill should be used when tasks involve starting QEMU VMs, configuring serial console or telnet access, booting ISO images, or troubleshooting VM startup issues. Covers pre-flight checks, idempotent startup procedures, and intelligent readiness verification. |
QEMU VM Startup Skill
This skill provides procedural guidance for starting QEMU virtual machines with serial console access, particularly for tasks involving ISO boot, telnet connectivity, and headless operation.
Pre-Flight Checks (Critical First Step)
Before attempting any QEMU operations, verify all prerequisites systematically. Skipping this step leads to iterative failures.
Tool Availability Check
Verify available tools before planning the approach:
which qemu-system-x86_64 || which qemu-system-i386
which ps pkill pgrep kill 2>/dev/null
which nc netstat ss lsof 2>/dev/null
which telnet
Adapt the strategy based on which tools are actually available in the environment.
KVM Availability Check
Never assume KVM is available. Check before using -enable-kvm:
ls /dev/kvm 2>/dev/null && echo "KVM available" || echo "KVM not available"
grep -E '(vmx|svm)' /proc/cpuinfo > /dev/null && echo "CPU supports virtualization"
If KVM is not available, omit the -enable-kvm flag entirely rather than letting it fail.
Resource Verification
ls -la /path/to/image.iso
nc -z localhost PORT 2>/dev/null && echo "Port in use"
netstat -tuln | grep PORT
ss -tuln | grep PORT
QEMU Command Construction
Build the correct command from the start by gathering all necessary information first.
Essential Parameters for Serial Console Access
For headless operation with telnet serial console:
qemu-system-x86_64 \
-m 512 \
-cdrom /path/to/image.iso \
-nographic \
-serial telnet:localhost:PORT,server,nowait \
-monitor none
Common Parameter Pitfalls
| Issue | Cause | Solution |
|---|
| QEMU monitor prompt instead of serial console | Missing -monitor none or conflicting -nographic settings | Add -monitor none explicitly |
| "Port already in use" error | Previous QEMU instance still running | Clean up existing processes first |
| VM hangs at boot | KVM flag on system without KVM | Remove -enable-kvm |
| No output visible | Serial console not properly configured | Ensure -serial points to accessible telnet port |
Conditional KVM Usage
if [ -e /dev/kvm ]; then
KVM_FLAG="-enable-kvm"
else
KVM_FLAG=""
fi
qemu-system-x86_64 $KVM_FLAG -m 512 ...
Process Management and Cleanup
Idempotent Startup Procedure
Before starting a new QEMU instance, ensure no conflicting processes exist:
ps aux | grep qemu | grep -v grep
pkill -f "qemu.*PORT" 2>/dev/null
sleep 2
Background Process Tracking
When running QEMU in background:
- Record the process ID immediately after starting
- Store the background job identifier if using shell job control
- Verify the process is actually running after starting
- Keep track of which attempt/process is the active one
Readiness Verification
Intelligent Polling (Preferred over Fixed Sleep)
Instead of arbitrary sleep durations, poll for actual readiness:
MAX_WAIT=60
WAITED=0
while ! nc -z localhost PORT 2>/dev/null; do
sleep 2
WAITED=$((WAITED + 2))
if [ $WAITED -ge $MAX_WAIT ]; then
echo "Timeout waiting for VM"
exit 1
fi
done
echo "Port is listening after ${WAITED}s"
Connection Verification
After port is listening, verify actual service readiness:
timeout 10 telnet localhost PORT
echo "" | timeout 5 telnet localhost PORT 2>&1 | grep -i "login"
Verification Strategies
Layered Verification Approach
- Process verification: Confirm QEMU process is running
- Port verification: Confirm telnet port is listening
- Connection verification: Confirm telnet connection succeeds
- Service verification: Confirm expected output (login prompt, shell, etc.)
Perform each layer before proceeding to avoid false positives.
State Reconciliation
If multiple startup attempts were made, explicitly identify which process is serving connections:
lsof -i :PORT
netstat -tlnp | grep PORT
ss -tlnp | grep PORT
Common Mistakes to Avoid
- Assuming tool availability: Always check for
ps, pkill, ss, nc before using them
- Premature KVM usage: Check
/dev/kvm exists before adding -enable-kvm
- Incomplete cleanup: Verify process termination and port release before restarting
- Arbitrary sleep times: Use polling with readiness checks instead of fixed delays
- Unclear process state: Track which background process is actually running
- Monitor/serial confusion: Understand that
-nographic alone may show QEMU monitor; use -monitor none for clean serial output
- Multiple redundant verifications: Design verification sequence once, execute systematically
Decision Framework
Start
│
├─► Pre-flight checks pass?
│ No ──► Adapt approach based on available tools
│ Yes ──► Continue
│
├─► KVM available?
│ No ──► Omit -enable-kvm flag
│ Yes ──► Include -enable-kvm flag
│
├─► Port already in use?
│ Yes ──► Clean up existing processes, wait for port release
│ No ──► Continue
│
├─► Start QEMU with complete command
│
├─► Poll for port readiness (with timeout)
│
├─► Verify connection and expected output
│
└─► Confirm final state explicitly