lk/virtualization/xen/xe.md

163 lines
2.6 KiB
Markdown
Raw Normal View History

2022-01-16 18:20:39 +00:00
---
2022-06-18 13:49:30 +00:00
title: "XCP-ng Automation"
2022-02-04 08:24:02 +00:00
tags: [ "documentation", "virtualization", "xen" ]
2022-01-16 18:20:39 +00:00
---
2020-02-24 08:46:06 +00:00
# Basic VM Management
```bash
xe vm-list
```
2020-02-24 08:46:06 +00:00
2023-06-20 13:19:26 +00:00
Start, stop, et c. with `xe`:
2020-02-24 08:46:06 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vm-start vm=$TARGET_VM
```
2020-02-24 08:46:06 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vm-shutdown vm=$TARGET_VM
```
2020-02-24 08:46:06 +00:00
Destruction requires the uuid.
```bash
2023-06-20 13:19:26 +00:00
xe vm-destroy uuid=$TARGET_UUID
```
2020-02-24 08:46:06 +00:00
2023-06-20 13:19:26 +00:00
Autocompletion works well with all of these commands.
2020-01-02 00:04:35 +00:00
# Shut Down VM
List VMs.
```bash
xe host-list
```
2020-01-02 00:04:35 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vm-list resident-on=$HOST_UUID
```
2020-01-02 00:04:35 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vm-shutdown uuid=TARGET_VM force=true
```
2020-01-02 00:04:35 +00:00
If this doesn't work, try:
```bash
2023-06-20 13:19:26 +00:00
xe vm-reset-powerstate uuid=TARGET_VM force=true
```
2020-01-02 00:04:35 +00:00
Get the id:
```bash
list_domains
```
2020-01-02 00:04:35 +00:00
And destroy the domain:
```bash
2023-06-20 13:19:26 +00:00
/opt/xensource/debug/xenops destroy_domain -domid $DOM_ID
```
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
# Problem Solving
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
> Error: `Internal error:xenopsd internal error: Storage_interface.Illegal_transition` in XenServer
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
After a failed “Move VM”, “Copy VM”, or “Export VM” operation, the Virtual Machine (VM) being operated cannot start.
2020-01-02 00:04:35 +00:00
## Solution
To resolve this error, complete the following procedure:
Open the Console to the XenServer that is hosting the VM and run the following command:
```bash
list_domains
```
2020-01-02 00:04:35 +00:00
All the VMs running on that server are displayed.
Copy the UUID corresponding to id=0.
This is the UUID of the Control Domain. The Control Domain is a privileged Virtual Machine that handles all hyper calls received from running VMs to perform all virtual tasks.
Run the following command to obtain the UUID of the VBD (Virtual Block Device) object linking the Control Domain:
```bash
2023-06-20 13:19:26 +00:00
xe vbd-list vm-uuid=$CONTROL_DOMAIN_UUID
```
2020-01-02 00:04:35 +00:00
Run the following commands to unplug and destroy the VBD:
```bash
2023-06-20 13:19:26 +00:00
xe vbd-unplug uuid=$VBD_UUID
```
2020-01-02 00:04:35 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vbd-destroy uuid=$VBD_UUID
```
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
# Make a local iso repository
2020-01-02 00:04:35 +00:00
```bash
xe sr-create name-label=LocalISO type=iso device-config:location=/var/opt/xen/ISO_Store device-config:legacy_mode=true content-type=iso
```
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
This creates a UUID for the new directory, e.g.:
2020-01-02 00:04:35 +00:00
2023-06-20 13:19:26 +00:00
> e94e25bb-bcdc-801b-b62a-b51b686a3bdc
2020-01-02 00:04:35 +00:00
# Import
2023-06-20 13:19:26 +00:00
```bash
xe vm-import filename="$FILENAME".xva
```
2020-01-02 00:04:35 +00:00
# USB
2020-02-24 08:46:06 +00:00
## Attach
2020-01-02 00:04:35 +00:00
Put in the USB.
Get the USB's uuid.
```bash
xe pusb-list
```
2020-01-02 00:04:35 +00:00
Make the USB recognised as a device.
```bash
xe pusb-param-set uuid=*<uuid>*
```
2020-01-02 00:04:35 +00:00
For passthrough, use this:
```bash
xe pusb-param-set uuid=*<uuid>* passthrough-enabled=true
```
2020-01-02 00:04:35 +00:00
## Attach to host
(requires reboot of guest)
[link](https://github.com/xcp-ng/xcp/wiki/USB-Pass-Through)
2020-02-24 08:46:06 +00:00
# Storage Spaces - "SR"
```bash
xe sr-list
```
2020-02-24 08:46:06 +00:00
2020-06-19 13:18:50 +00:00
# Exporting and Exporting VMs
```bash
2023-06-20 13:19:26 +00:00
xe vm-export vm=$VM_NAME filename="$FULL_PATH".xva
```
2020-06-19 13:18:50 +00:00
```bash
2023-06-20 13:19:26 +00:00
xe vm-import vm=*<Name>* filename="$FULL_PATH".xva
```
2020-06-19 13:18:50 +00:00