Xen Commands Reference
The xl Toolstack
The xl (Xen Light) toolstack is the primary command-line interface for managing Xen virtual machines. It replaced the older xm toolstack and provides comprehensive control over domains, resources, networking, and storage. This reference covers all essential xl commands with practical examples and use cases.
All xl commands must be run as root or with sudo privileges. Configuration files are typically stored in /etc/xen/ directory.
System Information Commands
xl info
Shows detailed information about the Xen hypervisor including version, number of CPUs, total memory, and various capabilities.
xl list
Displays all domains (both running and paused) with their ID, name, memory, VCPUs, state, and CPU time consumed.
xl list -l domainname
Outputs complete domain configuration in JSON format, including all settings and current state.
xl list -v
Shows extended information including UUID, security label, and additional state details for all domains.
xl dmesg
Displays the Xen hypervisor console log, useful for troubleshooting boot issues and hardware problems.
xl dmesg -c
Clears the hypervisor message buffer after displaying current contents.
xl info -n
Displays NUMA topology information, showing CPU and memory node relationships for optimization.
Domain Lifecycle Management
xl create /etc/xen/myvm.cfg
Creates and starts a new domain using the specified configuration file.
xl create -c /etc/xen/myvm.cfg
Creates domain and immediately attaches to its console for monitoring the boot process.
xl create -p /etc/xen/myvm.cfg
Creates domain but leaves it paused, useful for debugging or preparing pre-start operations.
xl shutdown domainname
Sends ACPI shutdown signal to the domain, allowing it to shut down cleanly.
xl shutdown --all
Gracefully shuts down all running domains (except Dom0).
xl shutdown -w domainname
Waits for domain to shutdown completely before returning. Useful in scripts.
xl reboot domainname
Sends reboot signal to domain, causing it to restart.
xl destroy domainname
Immediately terminates domain without graceful shutdown. Use only when shutdown fails.
xl pause domainname
Suspends domain execution, freezing its state. Domain remains in memory but doesn't consume CPU.
xl unpause domainname
Resumes execution of a paused domain from exactly where it stopped.
Domain Save and Restore
xl save domainname /save/path/domain.save
Saves complete domain state to disk and destroys the running instance. Can be restored later.
xl save -c domainname /save/path/domain.save
Saves domain state but keeps domain running (checkpoint). Useful for backup purposes.
xl restore /save/path/domain.save
Restores a previously saved domain, resuming exactly where it left off.
xl restore -c /save/path/domain.save
Restores domain and immediately attaches to console.
xl restore -p /save/path/domain.save
Restores domain but leaves it paused for inspection before resuming.
Live Migration
xl migrate domainname host2.example.com
Live migrates running domain to another physical host with minimal downtime.
xl migrate -s ssh://host2.example.com domainname
Uses SSH for secure migration channel. Recommended for untrusted networks.
xl migrate --debug domainname host2.example.com
Enables verbose output showing migration progress and performance statistics.
Console and Monitoring
xl console domainname
Connects to domain's console for direct interaction. Press Ctrl+] to detach.
xl top
Real-time display of domain CPU, memory, and network/disk I/O usage (similar to Linux 'top').
xl uptime
Shows how long each domain has been running.
xl uptime -s domainname
Displays exact start time for specified domain.
Memory Management
xl mem-max domainname 2048
Sets maximum memory limit (in MB) that domain can use. Must be done while domain is paused.
xl mem-set domainname 1024
Adjusts current memory allocation using balloon driver. Can be done while domain runs.
xl list -m
Shows detailed memory statistics for all domains including current, maximum, and shared memory.
xl sharing domainname
Displays memory sharing statistics showing deduplicated pages.
CPU Management
xl vcpu-list
Shows all VCPUs across all domains with their affinity and current physical CPU assignment.
xl vcpu-list domainname
Displays VCPU information only for the specified domain.
xl vcpu-set domainname 4
Changes number of active VCPUs for running domain (hot-plug/unplug).
xl vcpu-pin domainname 0 2
Pins VCPU 0 of domain to physical CPU 2, reducing cache misses and improving performance.
xl vcpu-pin domainname 0 2-5
Pins VCPU 0 to physical CPUs 2, 3, 4, and 5, allowing scheduler to choose among them.
xl vcpu-pin domainname all 2-5
Pins all VCPUs of domain to specified physical CPU range.
Scheduler Configuration
xl sched-credit
Displays Credit scheduler parameters for all domains.
xl sched-credit -d domainname -w 512
Sets CPU weight (default 256). Domain with weight 512 gets 2x CPU compared to weight 256.
xl sched-credit -d domainname -c 50
Caps domain CPU usage at 50% of one physical CPU (50 = 50%, 200 = 2 full CPUs).
xl sched-credit2
Displays Credit2 scheduler parameters if Credit2 scheduler is active.
xl sched-credit2 -d domainname -w 512
Sets CPU weight for domain under Credit2 scheduler.
xl sched-rtds -v
Displays real-time scheduler parameters including period and budget for all domains.
xl sched-rtds -d domainname -v 0 -p 10000 -b 5000
Sets VCPU 0 to 10ms period with 5ms budget (50% CPU guaranteed).
Network Management
xl network-list domainname
Shows all virtual network interfaces attached to domain with their configurations.
xl network-attach domainname bridge=xenbr0
Hot-plugs new network interface to running domain connected to specified bridge.
xl network-attach domainname bridge=xenbr0 mac=00:16:3e:xx:xx:xx
Attaches network interface with specific MAC address.
xl network-detach domainname 0
Hot-unplugs network interface 0 from running domain.
xl network-attach domainname bridge=xenbr0 rate=100Mb/s
Attaches interface with bandwidth rate limit of 100 Mbps.
Block Device Management
xl block-list domainname
Shows all virtual block devices attached to domain with backend information.
xl block-attach domainname /dev/vg0/disk2 xvdb w
Hot-plugs block device to running domain as xvdb in read-write mode.
xl block-attach domainname /path/to/image.img xvdc r
Attaches disk image as read-only device xvdc.
xl block-detach domainname xvdb
Hot-unplugs specified block device from running domain.
xl block-attach domainname /dev/vg0/disk backend=dom0 format=raw
Attaches device with explicit backend domain and format specification.
PCI Device Passthrough
xl pci-list domainname
Shows all PCI devices assigned to domain.
xl pci-attach domainname 01:00.0
Assigns PCI device (by bus address) directly to domain for exclusive access.
xl pci-detach domainname 01:00.0
Removes PCI device assignment from domain, returning it to Dom0.
xl pci-attach domainname 01:00.0 permissive=1
Attaches PCI device in permissive mode (allows some unsafe operations, use carefully).
USB Device Management
xl usbctrl-list domainname
Shows USB controllers attached to domain.
xl usbctrl-attach domainname version=2 ports=4
Attaches virtual USB 2.0 controller with 4 ports to domain.
xl usbdev-list domainname
Shows USB devices passed through to domain.
xl usbdev-attach domainname 1-2
Passes through USB device at bus 1, port 2 to domain.
NUMA and CPU Pools
xl info -n
Displays NUMA node topology with CPU and memory distribution.
xl vcpu-list -n
Shows VCPU placement across NUMA nodes.
xl numa-pin domainname 0
Pins domain to NUMA node 0 for optimal memory locality.
xl cpupool-list
Shows defined CPU pools and their CPU assignments.
xl cpupool-create name="rtpool" sched="rtds"
Creates new CPU pool with specified scheduler.
xl cpupool-cpu-add rtpool 4
Adds physical CPU 4 to specified CPU pool.
xl cpupool-migrate domainname rtpool
Migrates domain to different CPU pool (and its scheduler).
Power Management
xl info | grep -i power
Displays power management capabilities and current state.
xenpm get-cpufreq-para
Shows CPU frequency scaling parameters for all physical CPUs.
xenpm set-scaling-governor performance
Sets CPU frequency scaling governor (performance, powersave, ondemand, etc.).
xenpm get-cpuidle-states
Displays CPU idle states (C-states) and their usage statistics.
Debug and Troubleshooting
xl debug-keys h
Sends debug key 'h' (help) to hypervisor, output appears in xl dmesg.
xl debug-keys d
Dumps detailed information about all domains to hypervisor console.
xl debug-keys r
Displays scheduler run queues showing which VCPUs are runnable.
xl debug-keys m
Shows detailed memory allocation information in hypervisor log.
xentrace -D -e all trace.dat
Captures hypervisor execution traces for performance analysis.
xentrace_format trace.dat
Converts binary trace file to human-readable format.
xl -vvv create -n /etc/xen/test.cfg
Dry-run domain creation with maximum verbosity, useful for config file testing.
Configuration File Examples
Basic PV Linux Guest
# /etc/xen/pvlinux.cfg
name = "pvlinux"
type = "pv"
kernel = "/boot/vmlinuz-xen"
ramdisk = "/boot/initrd-xen.img"
memory = 1024
vcpus = 2
disk = ['phy:/dev/vg0/pvlinux,xvda,w']
vif = ['bridge=xenbr0']
bootloader = "pygrub"
on_reboot = 'restart'
on_crash = 'restart'
HVM Windows Guest
# /etc/xen/windows.cfg
name = "windows"
type = "hvm"
memory = 4096
vcpus = 4
disk = ['file:/vm/windows.img,hda,w']
vif = ['bridge=xenbr0,model=e1000']
vnc = 1
vnclisten = "0.0.0.0"
vncpasswd = "changeme"
acpi = 1
apic = 1
pae = 1
on_poweroff = 'destroy'
on_reboot = 'restart'
Advanced Configuration with Resource Controls
# /etc/xen/production.cfg
name = "production"
type = "pv"
memory = 2048
maxmem = 4096
vcpus = 4
cpus = "2-5"
disk = ['phy:/dev/vg0/prod_root,xvda,w',
'phy:/dev/vg0/prod_data,xvdb,w']
vif = ['bridge=xenbr0,rate=1000Mb/s']
sched_credit_weight = 512
sched_credit_cap = 0
on_reboot = 'restart'
on_crash = 'coredump-restart'
localtime = 0
Note: All xl commands require root privileges. Use 'sudo' if not running as root. Command availability may vary depending on Xen version and hypervisor configuration.
Command Quick Reference
| Category | Common Commands | Purpose |
|---|---|---|
| Lifecycle | create, shutdown, destroy, reboot | Start, stop, and control domains |
| Information | list, info, top, uptime | View system and domain status |
| Resources | mem-set, vcpu-set, vcpu-pin | Manage CPU and memory |
| Devices | block-attach, network-attach, pci-attach | Hot-plug devices |
| Migration | migrate, save, restore | Move or backup domains |
| Debug | dmesg, debug-keys, console | Troubleshoot issues |