XCP-ng CLI Reference

1. Initial Setup

Install XCP-ng from the ISO, configure networking, and set up storage during installation. Access the host via SSH or directly at the terminal for CLI management.

2. Storage Repository (SR) Management

List Existing SRs

xe sr-list

Create an ISO SR

mkdir -p /var/opt/iso_repository
chmod 755 /var/opt/iso_repository
xe sr-create name-label="ISO Repository" type=iso device-config:location=/var/opt/iso_repository device-config:legacy_mode=true content-type=iso

Upload an ISO

scp my_iso_file.iso root@<XCP-ng_IP>:/var/opt/iso_repository/

Rescan the SR

xe sr-scan uuid=<SR_UUID>

3. Virtual Machine Management

List All VMs

xe vm-list

Create a New VM

xe vm-install template="Other install media" new-name-label="MyNewVM"

Start a VM

xe vm-start vm=<VM_UUID>

Shut Down a VM

xe vm-shutdown vm=<VM_UUID>

Attach an ISO to a VM

xe vbd-create vm-uuid=<VM_UUID> device=3 type=CD mode=RO sr-uuid=<SR_UUID>

Delete a VM

xe vm-uninstall vm=<VM_UUID> force=true

4. Console Access

Connect to a VM Console (Paravirtualized VMs)

Use this command to access the console of a VM:

xe console vm=<VM_NAME_OR_UUID>

Exit the console with Ctrl + ].

Enable VNC for HVM Guests

If the VM uses HVM (e.g., Windows), enable VNC and retrieve the port:

xe vm-param-set uuid=<VM_UUID> other-config:vnc=1
xe vm-param-get uuid=<VM_UUID> param-name=other-config param-key=vnc-port

Connect with a VNC viewer to <XCP-ng_IP>:<VNC_PORT>.

5. Network Management

List Networks

xe network-list

Create a New Network

xe network-create name-label="MyNetwork"

Attach a VM to a Network

xe vif-create vm-uuid=<VM_UUID> network-uuid=<NETWORK_UUID> device=0

6. Host Management

Reboot the Host

xe host-reboot

Check Host Parameters

xe host-param-list uuid=<HOST_UUID>

View CPU Details

xe host-cpu-info

7. Patching and Updates

Upload a Patch

xe patch-upload file-name=/path/to/patch.xsupdate

Apply a Patch

xe patch-apply uuid=<PATCH_UUID>

8. Monitoring and Logs

View VM Performance Data

xe vm-data-source-list uuid=<VM_UUID>

Monitor Logs

tail -f /var/log/xensource.log

9. Automate Tasks with Scripts

Start All VMs

#!/bin/bash
for vm in $(xe vm-list is-control-domain=false --minimal | tr ',' '\n'); do
  xe vm-start uuid=$vm
done

10. Backup and Recovery

Export a VM

xe vm-export vm=<VM_NAME_OR_UUID> filename=/path/to/backup.xva

Import a VM

xe vm-import filename=/path/to/backup.xva

11. Troubleshooting

View VM State

xe vm-list name-label=<VM_NAME>

Check Disk Usage

df -h

Check Network Interfaces

ip a