- Table of Contents
- Related Documents
-
Title | Size | Download |
---|---|---|
01-VM commands (SR6602) | 205.49 KB |
Contents
VM commands
VM commands are supported only by the SR6602-I and SR6602-IE routers. By default, VM capability is disabled.
Make sure the disks used to deploy VMs have sufficient storage space and their file system format is EXT4.
To obtain help information for standard Linux commands, use the --help keyword. For example, to obtain help information for the virsh commands, enter virsh --help.
The virsh, ip, and ifconfig commands are standard Linux commands. Required parameters are enclosed into a pair of angle brackets (<>). Optional parameters are enclosed into a pair of brackets.
display domain-sriov-vf
Use display domain-sriov-vf to display VM SR-IOV VF NIC information.
Syntax
display domain-sriov-vf domain-name
Views
Any view
Predefined user roles
network-admin
network-operator
Parameters
domain-name: Specifies a VM by its name, a case-sensitive string of 1 to 256 characters.
Examples
# Display SR-IOV VF NIC information for VM vm0.
<Sysname> display domain-sriov-vf vm0
enp182s0f2:
vf 00 pci-addr 0000:b6:0a.0
enp182s0f3:
Table 1 Command output
Field |
Description |
enp182s0f2/enp182s0f3: |
Name of the physical NIC. |
vf 0 pci-addr 0000:b6:0a.0 |
SR-IOV VF NIC number and PCIe address. A physical NIC can be virtualized into 16 SR-IOV VF NICs. |
display ict mode
Use display ict mode to display VM capability information.
Syntax
display ict mode
Views
Any view
Predefined user roles
network-admin
network-operator
Examples
# Display VM capability information.
<Sysname> display ict mode
Current ICT mode: Enabled
ICT mode on next boot: Enabled
Current vcpu pool for vmm is 6.
Next vcpu pool for vmm is 6.
Current vmem pool for vmm is 29GB.
Next vmem pool for vmm is 29GB.
Table 2 Command output
Field |
Description |
Current ICT mode |
VM capability state: · Enabled. · Disabled. |
ICT mode on next boot |
VM capability state at the next startup: · Enabled. · Disabled. |
Current vcpu pool for vmm is 6 |
Current number of vCPU cores allocated to the VM plane. This field is available only when the value for the Current ICT mode field is Enabled. |
Next vcpu pool for vmm is 6 |
Number of vCPU cores allocated to the VM plane at the next startup. This field is available only when the value for the ICT mode on next boot field is Enabled. |
Current vmem pool for vmm is 29GB |
Current amount of memory allocated to the VM plane. This field is available only when the value for the Current ICT mode field is Enabled. |
Next vmem pool for vmm is 29GB |
Amount of memory allocated to the VM plane at the next startup. This field is available only when the value for the ICT mode on next boot field is Enabled. |
Related commands
ict mode enable
undo ict mode enable
display mac-for-vmminterface
Use display mac-for-vmminterface to display the MAC addresses reserved for MACVtap NICs.
Syntax
display mac-for-vmminterface
Views
Any view
Predefined user roles
network-admin
network-operator
Usage guidelines
When attaching a MACVtap NIC to a VM, you can bind one of the reserved MAC addresses to the MACVtap NIC. A reserved MAC address can be bound only to one MACVtap NIC.
Examples
# Display the MAC addresses reserved for MACVtap NICs.
<Sysname> display mac-for-vmminterface
80:48:80:62:10:3a
80:48:80:62:10:3b
80:48:80:62:10:3c
80:48:80:62:10:3d
80:48:80:62:10:3e
80:48:80:62:10:3f
80:48:80:62:10:40
80:48:80:62:10:41
display sriov-vf-pciaddr
Use display sriov-vf-pciaddr to display the PCIe addresses of SR-IOV VF NICs.
Syntax
display sriov-vf-pciaddr
Views
Any view
Predefined user roles
network-admin
network-operator
Usage guidelines
To attach an SR-IOV VF NIC to a VM, you can bind the PCIe address of that NIC to the VM. An SR-IOV VF NIC can be bound only to one VM.
Examples
# Display the PCIe addresses of SR-IOV VF NICs.
<Sysname> display sriov-vf-pciaddr
enp182s0f2:
vf 00 pci-addr 0000:b6:0a.0
vf 01 pci-addr 0000:b6:0a.1
vf 02 pci-addr 0000:b6:0a.2
vf 03 pci-addr 0000:b6:0a.3
vf 04 pci-addr 0000:b6:0a.4
vf 05 pci-addr 0000:b6:0a.5
vf 06 pci-addr 0000:b6:0a.6
vf 07 pci-addr 0000:b6:0a.7
vf 08 pci-addr 0000:b6:0b.0
vf 09 pci-addr 0000:b6:0b.1
vf 10 pci-addr 0000:b6:0b.2
vf 11 pci-addr 0000:b6:0b.3
vf 12 pci-addr 0000:b6:0b.4
vf 13 pci-addr 0000:b6:0b.5
vf 14 pci-addr 0000:b6:0b.6
vf 15 pci-addr 0000:b6:0b.7
enp182s0f3:
vf 00 pci-addr 0000:b6:0e.0
vf 01 pci-addr 0000:b6:0e.1
vf 02 pci-addr 0000:b6:0e.2
vf 03 pci-addr 0000:b6:0e.3
vf 04 pci-addr 0000:b6:0e.4
vf 05 pci-addr 0000:b6:0e.5
vf 06 pci-addr 0000:b6:0e.6
vf 07 pci-addr 0000:b6:0e.7
vf 08 pci-addr 0000:b6:0f.0
vf 09 pci-addr 0000:b6:0f.1
vf 10 pci-addr 0000:b6:0f.2
vf 11 pci-addr 0000:b6:0f.3
vf 12 pci-addr 0000:b6:0f.4
vf 13 pci-addr 0000:b6:0f.5
vf 14 pci-addr 0000:b6:0f.6
vf 15 pci-addr 0000:b6:0f.7
Table 3 Command output
Field |
Description |
enp182s0f2/enp182s0f3: |
Physical NIC name. |
vf 0 pci-addr 0000:b6:0a.0 |
Number of an SR-IOV VF NIC and its PCI address. A physical NIC can be virtualized into 16 SR-IOV VF NICs. |
display vcpu-pool
Use display vcpu-pool to display the number of CPU cores allocated to VMs.
Syntax
display vcpu-pool
Views
Any view
Predefined user roles
network-admin
network-operator
Examples
# Display the number of CPU cores allocated to VMs.
<Sysname> display vcpu-pool
Current vcpu pool for vmm is 6.
Next vcpu pool for vmm is 6.
Table 4 Command output
Field |
Description |
Current vcpu pool for vmm is 6 |
Current number of CPU cores allocated to the VM plane. |
Next vcpu pool for vmm is 6 |
Number of CPU cores allocated to the VM plane at the next startup. |
display vmem-pool
Use display vmem-pool to display the amount of memory allocated to the VM plane.
Syntax
display vmem-pool
Views
Any view
Predefined user roles
network-admin
network-operator
Examples
# Display the amount of memory allocated to the VM plane.
<Sysname> display vmem-pool
Current vmem pool for vmm is 29GB.
Next vmem pool for vmm is 29GB.
Table 5 Command output
Field |
Description |
Current vmem pool for vmm is 29GB |
Current amount of memory allocated to the VM plane. |
Next vmem pool for vmm is 29GB |
Amount of memory allocated to the VM plane at the next startup. |
export
Use export to export the images of a VM to a .pkg file.
Syntax
export domain-name pkg-path
Views
VMM view
Predefined user roles
network-admin
Parameters
domain-name: Specifies a VM by its name, a case-sensitive string of 1 to 256 characters.
pkg-path: Specifies the path that saves the exported .pkg file. The file path is a case-sensitive string of 1 to 63 characters.
Usage guidelines
Make sure the storage medium has sufficient storage space to save the .pkg file. If a USB flash drive is used, make sure the file system format of the USB flash drive is EXT4.
Make sure the VM has been shut down before you use this command.
Examples
# Export the images of VM vm0 to a .pkg file and save the file on disk sda1.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] export vm0 /mnt/sda1:/vm0.pkg
Ensure the destination has enough space?(if not, the pkg file may be unavailable.)[Y/N]:Y
Exporting domain vm0...
ict mode enable
Use ict mode enable to enable VM capability.
Use undo ict mode enable to disable VM capability.
Syntax
ict mode enable [ vcpu-pool cpu-count vmem-pool memory-size ]
Default
VM capability is disabled.
Views
System view
Predefined user roles
network-admin
Parameters
vcpu-pool cpu-count: Sets the number of CPU cores allocated to the VM plane. The value range for the cpu-count argument is 0 to the total number of CPU cores on the device minus 2. By default, the number of CPU cores allocated to the VM plane is the total number of CPU cores on the device minus 2.
vmem-pool memory-size: Sets the amount of memory allocated to the VM plane, in GB. The value range for the memory-size argument is 0 to the total amount of memory on the device minus 8 GB. By default, the amount of memory allocated to the VM plane is the total amount of memory on the device minus 8 GB.
Usage guidelines
Reboot the device for this command to take effect.
With VM capability, the device supports both routing and VM virtualization.
If you do not specify the vcpu-pool cpu-count or vmem-pool memory-size option, the default settings of the option apply.
Examples
# Enable VM capability.
<Sysname> system-view
[Sysname] ict mode enable
ifconfig
Use ifconfig to configure an IP address for a physical NIC or display physical NIC information.
Syntax
Configure an IP address for a physical NIC:
ifconfig < interface > [ < address > ] [ netmask < address > ] [ [ - ] promisc ]
Display physical NIC information:
ifconfig [ -a ] [ -v ] [ -s ] < interface >
Views
VMM view
Predefined user roles
network-admin
Parameters
-a: Specifies all physical NICs. If you do not specify this keyword, the command displays information only for active physical NICs.
-v: Displays detailed information about physical NICs. If you do not specify this keyword or the -s keyword, the command displays detailed information about physical NICs.
-s: Displays brief information about physical NICs. If you do not specify this keyword or the -v keyword, the command displays detailed information about physical NICs.
interface: Specifies a physical NIC by its name.
address: Specifies an IP address for the physical NIC.
netmask < address >: Specifies a mask for the IP address of the physical NIC. The value range for the address argument is 0.0.0.0 to 255.255.255.255 or 0 to 32.
[ - ] promisc: Configures the promiscuous mode of the physical NIC. If you do not specify the hyphen (-) keyword, this command enables promiscuous mode for the physical NIC. If you specify the hyphen (-) keyword, this command disables promiscuous mode for the physical NIC.
Usage guidelines
In promiscuous mode, the SR-IOV VF NICs of the physical NIC can receive all packets that pass through the physical NIC regardless of the destination address of the packets. If promiscuous mode is disabled, the SR-IOV VF NICs can receive only broadcast IP packets and packets whose destination IP address is an IP address of the SR-IOV VF NICs. Use promiscuous mode in a scenario that requires network analysis.
You can use VNC remote terminal software to log in to the GUI of a VM after the VM is installed. For this purpose, specify the VNC server address and VNC port number. The IP address specified by using this command is used as the VNC server address.
Examples
# Configure the IP address of physical NIC enp182s0f2 as 192.168.1.1 and set the mask of the IP address to 255.255.255.0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] ifconfig enp182s0f2 192.168.1.1 netmask 255.255.255.0
# Display information for physical NIC enp182s0f2.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] ifconfig enp182s0f2
enp182s0f2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::200:ff:fe00:8062 prefixlen 64 scopeid 0x20<link>
ether 00:00:00:00:80:62 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Table 6 Command output
Field |
Description |
flags |
NIC flags: · UP—The NIC is enabled. · DOWN—The NIC is disabled. · BROADCAST—The NIC supports broadcast. · RUNNING—The NIC has network connectivity. · SHUTOFF—The NIC does not have network connectivity. · MULTICAST—The NIC supports multicast. |
mtu |
Maximum transmission unit. |
inet |
IPv4 address. |
netmask |
IPv4 mask. |
broadcast |
Broadcast address. |
inet6 |
IPv6 address. |
prefixlen |
IPv6 prefix length. |
scopeid |
NIC scope ID. Value link indicates that the configuration information takes effect only on the physical NIC. |
ether |
NIC type and MAC address. |
txqueuelen |
Storage length of the buffer for transmitting data. |
RX packets |
Total number of correctly received packets. |
RX bytes |
Total number of received bytes. |
RX errors |
Total number of received packets with errors. |
RX dropped |
Total number of dropped incoming packets. |
RX overruns |
Total number of lost incoming packets because of too fast speed. |
RX frame |
Number of received frames with collisions. |
TX packets |
Total number of sent packets. |
TX errors |
Total number of sent packets with errors. |
TX dropped |
Total number of dropped outgoing packets |
TX overruns |
Total number of lost outgoing packets because of too fast speed. |
TX carrier |
Total number of packets dropped because of overloading. |
TX collisions |
Total number of sent packets with collisions. |
import
Use import to import a VM by using a .pkg file.
Syntax
import pkg-path
Views
VMM view
Predefined user roles
network-admin
Parameters
pkg-path: Specifies the absolute path of a .pkg file. The file path is a case-sensitive string of 1 to 63 characters. Make sure the .pkg file exists.
Usage guidelines
To generate a .pkg file, use the export command.
Examples
# Import a VM by using file vm0.pkg.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] import /mnt/sda1:/vm0.pkg
Import domain package vm0.pkg...(Please reconfig vcpus and vcpupin accroding to the current environment after import, or the domain may not work properly)
Related commands
export
ip link set
Use ip link set to specify the VLAN to which an SR-IOV VF NIC belongs.
Syntax
ip link set DEVICE vf NUM vlan VLANID
Views
VMM view
Predefined user roles
network-admin
Parameters
DEVICE: Specifies an SR-IOV-capable physical NIC.
vf NUM: Specifies an SR-IOV VF NIC by its number, in the range of 0 to 15. To obtain the number of the SR-IOV VF NIC, use the display sriov-vf-pciaddr command.
vlan VLANID: Specifies a VLAN by its ID, in the range of 1 to 4094.
Usage guidelines
If you set the VLAN ID of an SR-IOV VF NIC to 0, the SR-IOV VF NIC does not belong to any VLAN.
To change the VLAN of an SR-IOV VF NIC, you must first remove the original VLAN of that SR-IOV VF NIC.
Examples
# Specify VLAN 2 for SR-IOV VF NIC 0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] ip link set enp182s0f2 vf 0 vlan 2
Related commands
display sriov-vf-pciaddr
virsh attach-sriov
ip link show
Use ip link show to display detailed physical NIC information.
Syntax
ip link show [ DEVICE ]
Views
VMM view
Predefined user roles
network-admin
Parameters
DEVICE: Specifies an SR-IOV-capable physical NIC.
Examples
# Display detailed information about physical NIC enp182s0f2.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] ip link show enp182s0f2
9: enp182s0f2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq portid 000000
000316 state UP mode DEFAULT qlen 1000
link/ether 80:48:80:62:10:42 brd ff:ff:ff:ff:ff:ff
vf 0 MAC 80:48:80:62:10:44, spoof checking on, link-state auto, trust off
vf 1 MAC 80:48:80:62:10:45, spoof checking on, link-state auto, trust off
vf 2 MAC 80:48:80:62:10:46, spoof checking on, link-state auto, trust off
vf 3 MAC 80:48:80:62:10:47, vlan 100, spoof checking on, link-state auto, tr
ust off
vf 4 MAC 80:48:80:62:10:48, spoof checking on, link-state auto, trust off
vf 5 MAC 80:48:80:62:10:49, spoof checking on, link-state auto, trust off
vf 6 MAC 80:48:80:62:10:4a, spoof checking on, link-state auto, trust off
vf 7 MAC 80:48:80:62:10:4b, spoof checking on, link-state auto, trust off
vf 8 MAC 80:48:80:62:10:4c, spoof checking on, link-state auto, trust off
vf 9 MAC 80:48:80:62:10:4d, spoof checking on, link-state auto, trust off
vf 10 MAC 80:48:80:62:10:4e, spoof checking on, link-state auto, trust off
vf 11 MAC 80:48:80:62:10:4f, spoof checking on, link-state auto, trust off
vf 12 MAC 80:48:80:62:10:50, spoof checking on, link-state auto, trust off
vf 13 MAC 80:48:80:62:10:51, spoof checking on, link-state auto, trust off
vf 14 MAC 80:48:80:62:10:52, spoof checking on, link-state auto, trust off
vf 15 MAC 80:48:80:62:10:53, spoof checking on, link-state auto, trust off
Table 7 Command output
Field |
Description |
9: enp182s0f2 |
Physical NIC index and name. |
<BROADCAST,MULTICAST,UP,LOWER_UP> |
NIC flags: · BROADCAST—The NIC supports broadcast. · MULTICAST—The NIC supports multicast. · UP—The NIC is enabled. · DOWN—The NIC is disabled. · LOWER_UP—The NIC has network connectivity. · LOWER_DOWN—The NIC does not have network connectivity. |
mtu |
Maximum transmission unit. |
disc mq portid |
Qdisc MQ port number. |
state |
State of the physical NIC. |
mode |
Network mode of the physical NIC. |
qlen |
Storage length of the buffer for transmitting data. |
link/ether |
Interface type and physical address. |
brd |
Broadcast address. |
vf 0 |
Number of the SR-IOV VF NIC. |
MAC 80:48:80:62:10:47 |
MAC address of the SR-IOV VF NIC. |
vlan 100 |
VLAN ID of the SR-IOV VF NIC. |
spoof checking on |
Whether spoof checking is enabled for the SR-IOV VF NIC: · spoof checking on—Spoof checking is enabled. · spoof checking off—Spoof checking is disabled. |
Link-state auto |
Link state of the SR-IOV VF NIV. |
trust off |
Whether trust mode is enabled for the SR-IOV VF NIC: · trust on—Trust mode is enabled for the SR-IOV VF NIC. · trust off—Trust mode is disabled for the SR-IOV VF NIC. |
qemu-img create
Use qemu-img create to create a disk image.
Syntax
qemu-img create [ -f fmt ] filename [ size ]
Views
VMM view
Predefined user roles
network-admin
Parameters
-f fmt: Specifies the file system format of the disk image. The format can be QCOW2 or RAW.
filename: Specifies the absolute path of the disk image.
size: Specifies the disk size. The size must be smaller than the physical disk where the disk image is installed.
Usage guidelines
Specify a measurement unit (for example, KB, MB, or GB) for the size argument, depending on the VM requirements.
The disk space is 0 for a disk image in QCOW2 format when the disk image is created. The space will gradually extend when the disk is in use. However, it will not exceed the disk size specified when the disk image is created. To ensure correct VM operation, make sure each disk has sufficient storage space.
Examples
# Create a disk image. Set the file system format to QCOW2, file name to vm0.qcow2, and disk size to 30 GB.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] qemu-img create -f qcow2 /mnt/sda1:/vm0.qcow2 30G
qemu-img info
Use qemu-img info to display detailed information about a disk image.
Syntax
qemu-img info filename
Views
VMM view
Predefined user roles
network-admin
Parameters
filename: Specifies a disk image by its absolute path.
Examples
# Display detailed information about disk image vm0.qcow2.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] qemu-img info /mnt/sda1:/vm0.qcow2
image: /mnt/sda1:/vm0.qcow2
file format: qcow2
virtual size: 30 GiB (32212254720 bytes)
disk size: 196 KiB
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
Table 8 Command output
Field |
Description |
image |
Absolute path of the VM disk image. |
file format |
File system format. |
virtual size |
Total size of the disk. |
disk size |
Used size of the disk. |
cluster_size |
Cluster size. |
Format specific information |
File system format information. |
compat |
Compatible version. |
lazy refcounts |
Whether deferred reference counting is used: · true—Deferred reference counting is used. · false—Deferred reference counting is not used. |
refcount bits |
Reference counting bits. |
corrupt |
Whether the disk image is corrupt: · true—The disk image is corrupt. · false—The disk image is not corrupt. |
set vcpu-pool
Use set vcpu-pool to set the total number of CPU cores allocated to the VM plane.
Syntax
set vcpu-pool cpu-count
Default
The number of CPU cores allocated to the VM plane is the total number of CPU cores on the device minus 2.
Views
VMM view
Predefined user roles
network-admin
Parameters
cpu-count: Sets the total number of CPU cores allocated to the VM plane. The value range for this argument is 0 to the total number of CPU cores on the device minus 2.
Usage guidelines
An SR6602-I router has eight CPU cores and an SR6602-IE router has 12 CPU cores.
Among all CPU cores, the device allocates CPU cores to the VM plane in descending order of CPU core numbers. For example, the device has eight CPU cores numbered 0 to 7. If you allocate five CPU cores allocated to the VM plane, the device allocates the CPU cores numbered 3 to 7 to the VM plane. When binding vCPU cores to physical CPU cores, you must specify the correct physical CPU core numbers.
Reboot the device for this command to take effect. If you allocate zero CPU cores to the VM plane, the VM plane is not accessible after the device reboots.
Examples
# Allocate six CPU cores to the VM plane.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] set vcpu-pool 6
Vcpu pool changed, please reboot the router to make it effective.
set vmem-pool
Use set vmem-pool to set the amount of memory allocated to the VM plane.
Syntax
set vmem-pool memory-size
Default
The amount of memory allocated to the VM plane is the total amount of memory on the device minus 8 GB.
Views
VMM view
Predefined user roles
network-admin
Parameters
memory-size: Sets the amount of memory allocated to the VM plane, in GB. The value range for this argument is 0 to the total amount of memory on the device minus 8 GB.
Usage guidelines
Reboot the device for this command to take effect. If you allocate zero GB of memory to the VM plane, the VM plane is not accessible after the device reboots.
Examples
# Allocate 5 GB of memory to the VM plane.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] set vmem-pool 5
Vmem pool changed, please reboot the router to make it effective.
virsh attach-disk
Use virsh attach-disk to attach a drive to a VM.
Syntax
virsh attach-disk < domain > < source > < target > [ --targetbus < string > ] [ --subdriver < string > ] [ --cache < string > ] [ --type < string > ] [ --config ] [ --live ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
source: Specifies the absolute path of a drive image.
target: Specifies the drive name. The value can be hdxxx or vdxxx.
--targetbus < string >: Specifies the drive bus type. The bus type can be IDE (low-speed disk bus type) or virtio (high-speed disk bus type).
--subdriver < string >: Specifies the file system format of the drive. The format can be QCOW2 or RAW.
--cache < string >: Specifies the read-write cache mode. The mode can be writethrough, wirteback, or none.
--type < string >: Specifies a drive type. The value for the string argument can be disk or CDROM.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
You can specify the --targetbus < string >, --subdriver < string >, or --cache < string > option only when the drive type is disk.
If the drive bus type is set to virtio, you must install a virtio driver for the operating system. Operating systems that support a virtio driver include Windows Server 2008/2012 and FreeBsd.
Before you use this command to attach a drive to a VM, make sure the drive image has been created by using the qemu-img create command.
If you use the virsh attach-disk command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Some earlier operating systems do not support the --live keyword. With such an operating system, you cannot attach drives to a VM when the VM is running. Centos 7.4 and later support the --live keyword. With such an operating system, you can attach drives to a VM when the VM is running.
Examples
# Attach a drive to VM vm0. The drive image is vm0.qcow2, the drive name is vda, the drive bus type is virtio, the file system format is QCOW2, and the drive type is disk.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh attach-disk vm0 /mnt/sda1:/vm0.qcow2 vdb --targetbus virtio --subdriver qcow2 --type disk --config
Disk attached successfully
Related commands
qemu-img create
virsh domblklist
virsh attach-interface
Use virsh attach-interface to attach a MACVtap NIC to a VM.
Syntax
virsh attach-interface < domain > < type > < source > [ --mac < string > ] [ --model < string > ][ --config ] [ --live ]
Default
No MACVtap NICs are attached to a VM.
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
type: Specifies a NIC network type. The value is direct, which represents the MACVtap type.
source: Specifies the source NIC of the MACVtap NIC. The device supports only SR-IOV-capable physical NICs for this argument in the current software version.
--mac < string >: Specifies the MAC address of the MACVtap NIC. The device reserves eight MAC addresses for MACVtap NICs. A MAC address can be bound only to one MACVtap NIC. If you do not specify a MAC address for the MACVtap NIC, the device randomly assigns one of the reserved MAC addresses to the MACVtap NIC.
--model < string >: Specifies the NIC type, which can be virtio, E1000, or RTL8139.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
If you use this command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
A MACVtap NIC supports the following network modes:
· VEPA—In this mode, the MACVtap NICs of the same physical NIC can communicate with each other through an external switch.
· Bridge—In this mode, the MACVtap NICs of the same physical NIC can directly communicate with each other.
· Private—In this mode, the MACVtap NICs of the same physical NIC cannot communicate with each other.
By default, a MACVtap NIC operates in VEPA mode. However, the device supports only the bridge mode in the current software version. After you attach a MACVtap NIC to a VM, you must use the virsh edit command to change the NIC network mode to bridge.
If the NIC type is set to virtio, you must install a virtio driver for the operating system. Operating systems that support a virtio driver include Windows Server 2008/2012 and FreeBsd.
Examples
# Attach a MACVtap NIC to VM vm0 when the VM is running. The NIC network type is direct, the source physical NIC is enp182s0f2, the MAC address is 80:48:80:62:10:3a, and the NIC model is E1000.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh attach-interface vm0 direct enp182s0f2 –-mac 80:48:80:62:10:3a –-model e1000 --live
Interface attached successfully
Related commands
display mac-for-vmminterface
virsh edit
virsh attach-sriov
Use virsh attach-sriov to attach an SR-IOV VF NIC to a VM.
Syntax
virsh attach-sriov < domain > < pciaddr >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
pciaddr: Specifies an SR-IOV VF NIC by its PCIe address. To obtain the PCIe address, use the display sriov-vf-pciaddr command.
Usage guidelines
An SR6602-I or SR6602-IE router is installed with two SR-IOV physical NICs. Each physical NIC can be virtualized into 16 VF NICs.
Examples
# Attach the SR-IOV VF NIC with PCIe address 0000:b6:0a.0 to VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh attach-sriov vm0 0000:b6:0a.0
Hostdev attached successfully
Related commands
display sriov-vf-pciaddr
virsh autostart
Use virsh autostart to configure VM auto-startup.
Syntax
virsh autostart < domain > [ --disable ]
Default
VM auto-startup is disabled.
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--disable: Disables VM auto-startup. If you do not specify this keyword, the command enables VM auto-startup.
Examples
# Enable VM auto-startup for VM VM0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh autostart vm0
Domain vm0 marked as autostarted
virsh define
Use virsh define to use a VM XML file to create a VM.
Syntax
virsh define < file >
Views
VMM view
Predefined user roles
network-admin
Parameters
file: Specifies a VM .xml file path, a case-sensitive string.
Examples
# Use file vm0.xml to create VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh define /mnt/sda1:/vm0.xml
Domain vm0 defined from /mnt/sda1:/vm0.xml
virsh define-by-cmd
Use virsh define-by-cmd to manually create a VM.
Syntax
virsh define-by-cmd < domname > < vcpucount > < memsize > < vncport > < disksource > < disksubdriver > < disktargetbus > [ --cdromsource < string > ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domname: Specifies a name for the VM, a case-sensitive string of 1 to 64 characters.
vcpucount: Sets the number of vCPU cores allocated to the VM. The value range for this argument is 1 to the maximum number of CPU cores allocated to the VM plane.
memsize: Sets the amount of memory allocated to the VM, in KB. The value range for this argument is 512000 to the maximum amount of memory allocated to the VM plane.
vncport: Specifies a VNC port number in the range of 0 to 99.
disksource: Specifies the absolute path of a disk image.
disksubdriver: Specifies the file system format of the disk. The format can be QCOW2 or RAW.
disktargetbus: Specifies the disk bus type, which can be IDE (low-speed disk bus type) or virtio (high-speed disk bus type).
--cdromsource < string >: Specifies the absolute path of the OS image. If you do not specify this option, the command creates a VM without an operating system. You can use the virsh attach-disk command to add an OS image to the VM.
Usage guidelines
If the disk bus type is set to virtio, you must install a virtio driver for the operating system. Operating systems that support a virtio driver include Windows Server 2008/2012 and FreeBsd.
Examples
# Create VM vm0. Allocate 2 CPU cores and 512 MB of memory to the VM and set the VNC port number to 1. Specify disk image vm0.qcow2 for the VM, set the disk file system format to QCOW2, and set the disk bus type to virtio. Specify OS image centos7.iso for the VM.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh define-by-cmd vm0 2 512000 1 /mnt/sda1:/vm0.qcow2 qcow2 virtio /mnt/sda1:/centos7.iso
Domain example defined successfully
virsh destroy
Use virsh destroy to forcibly shut down a VM.
Syntax
virsh destroy < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Usage guidelines
Use this command with caution. This command might cause data loss on the VM.
You must forcibly shut down a VM if the VM does not have an operating system.
Examples
# Forcibly shut down VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh destroy vm0
Domain vm0 destroyed
virsh detach-disk
Use virsh detach-disk to detach a drive from a VM.
Syntax
virsh detach-disk < domain > < target > [ --config ] [ --live ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
target: Specifies a drive by its name. The value can be hdxxx or vdxxx.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
This command does not delete the image file of a detached drive. To delete the image file, execute the delete command in user view. For more information about this command, see file system management commands in Fundamentals Command Reference.
If you use the virsh detach-disk command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Some earlier operating systems do not support the --live keyword. With such an operating system, you cannot detach drives from a VM when the VM is running. Centos 7.4 and later support the --live keyword. With such an operating system, you can detach drives from a VM when the VM is running.
Examples
# Detach drive vdb from VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh detach-disk vm0 vdb --config
Disk detached successfully
Related commands
virsh attach-disk
qemu-img create
delete (Fundamentals Command Reference)
virsh detach-interface
Use virsh detach-interface to detach MACVtap NICs from a VM.
Syntax
virsh detach-interface < domain > < type > [ --mac < string > ] [ --config ] [ --live ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
type: Specifies the MACVtap NIC network type. The value is direct.
--mac < string >: Specifies a MACVtap NIC by its MAC address. If you do not specify this option, this command detaches all MACVtap NICs from the VM.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
If you use this command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Examples
# Detach a MACVtap NIC from VM vm0. The network type of the NIC is direct and the MAC address of the NIC is 80:48:80:62:10:3b.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh detach-interface vm0 direct --mac 80:48:80:62:10:3b --live
Interface detached successfully
Related commands
virsh attach-interface
virsh detach-sriov
Use virsh detach-sriov to detach an SR-IOV VF NIC from a VM.
Syntax
virsh detach-sriov < domain > < pciaddr >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
pciaddr: Specifies an SR-IOV VF NIC by its PCIe address.
Examples
# Detach the SR-IOV VF NIC with PCIe address 0000:b6:0a.1 from VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh detach-sriov vm0 0000:b6:0a.1
Hostdev detached successfully
Related commands
virsh attach-sriov
virsh dominfo
Use virsh dominfo to display detailed information about a VM.
Syntax
virsh dominfo < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Examples
# Display detailed information about VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh dominfo vm0
Id: 30
Name: vm0
UUID: e605fa0d-9d58-4551-a9a6-dbc0388c1191
OS Type: hvm
State: running
CPU(s): 6
CPU time: 125.1s
Max memory: 4096000 KiB
Used memory: 4096000 KiB
Persistent: yes
Autostart: enable
Managed save: no
Security model: none
Security DOI: 0
Table 9 Command output
Field |
Description |
Id |
VM ID. |
Name |
VM name. |
UUID |
UUID of the VM, which uniquely identifies the VM. |
OS Type |
VM OS type. If the VM is a hardware VM, this field displays hvm. |
State |
VM state: · running—Running. · shutoff—Shut down. · paused—Suspended. |
CPU |
Number of vCPU cores allocated to the VM. |
CPU time |
vCPU time of the VM. |
Max memory |
Maximum amount of memory allocated to the VM. |
Used memory |
Maximum amount of memory that can be used by the VM. |
Persistent |
Whether the VM is permanent: · yes. · no. |
Autostart |
State of VM auto-startup: · enable—VM auto-startup is enabled. · disable—VM auto-startup is disabled. |
Managed save |
Whether to save the running configuration of the VM: · yes. · no. |
Security model |
Security model. |
Security DOI |
Security digital object identifier (DOI) |
virsh domblklist
Use virsh domblklist to display disk image information for a VM.
Syntax
virsh domblklist < domain > [ --inactive ] [ --details ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--inactive: Displays disk images that will be activated at the next VM startup. If you do not specify this keyword, the command displays the currently activated disk images.
--details: Displays detailed information about disk images. If you do not specify this keyword, the command displays only brief information about disk images.
Examples
# Display disk image information for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh domblklist vm0 --inactive
Target Source
--------------------------------
hda /mnt/sda1:/vm0.qcow2
vda /mnt/sda1:/vm1.qcow2
Table 10 Command output
Field |
Description |
Target |
Disk name. |
Source |
Path and name of the disk image. |
virsh domiflist
Use virsh domiflist to display NIC information for a VM.
Syntax
virsh domiflist < domain > [ --inactive ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--inactive: Displays NICs that will be activated at the next VM startup. If you do not specify this keyword, the command displays the currently activated NICs.
Examples
# Display NIC information for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh domiflist vm0
Interface Type Source Model MAC
-----------------------------------------------------------
macvtap0 direct enp182s0f2 e1000 80:48:80:62:10:3a
Table 11 Command output
Field |
Description |
Interface |
NIC name. |
Type |
NIC network type. |
Source |
Physical interface of the NIC. |
Model |
NIC model: · Virtio. · E1000. · RTL8139. |
MAC |
MAC address of the NIC. |
virsh edit
Use virsh edit to enter the view to edit the .xml file of a VM.
Syntax
virsh edit < domain > [ --skip-validate ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--skip-validate: Skips validation. If you do not specify this keyword, editing the .xml file of the VM requires validation. As a best practice, specify this keyword.
Usage guidelines
Execute this command to change VM parameters, including changing the boot order of drives, the VNC port number, and the network mode of MACVtap NICs.
Enter /parameter to search for the specified parameter. Enter n to search for the next. Enter i to enter the view to edit the parameter and press Esc to quit the parameter editing view. Enter :wq to save the configuration when quitting the parameter editing view, and enter :q! to not save the configuration when quitting the parameter editing view.
Examples
# Enter the view to edit the .xml file of VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh edit vm0 --skip-validate
virsh list
Use virsh list to display VMs.
Syntax
virsh list [ --all ] [ --autostart ] [ --inactive ] [ --no-autostart ]
Views
VMM view
Predefined user roles
network-admin
Parameters
--all: Displays all VMs.
--autostart: Displays all VMs with VM auto-startup enabled.
--inactive: Displays all inactive VMs. A VM is inactive if it is in shutoff or paused state.
--no-autostart: Displays all VMs with VM auto-startup disabled.
Usage guidelines
If you do not specify any parameters, this command displays all VMs that are running.
Examples
# Display all VMs with VM auto-startup enabled.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh list --all --autostart
Id Name State
----------------------
1 vm0 running
Table 12 Command output
Field |
Description |
Id |
VM ID. |
Name |
VM name. |
State |
VM state: · running—The VM is running. · shutoff—The VM is shut down. · paused—The VM is suspended. |
virsh resume
Use virsh resume to resume a suspended VM.
Syntax
virsh resume < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Examples
# Resume VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh resume vm0
Domain vm0 resumed
Related commands
virsh suspend
virsh setmaxmem
Use virsh setmaxmem to set the maximum amount of memory that can be allocated to a VM.
Syntax
virsh setmaxmem < domain > < size > [ --config ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
size: Sets the maximum amount of memory that can be allocated to the VM, in KB. The value range for this argument is 0 to the total amount of physical memory on the device minus 8 GB.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
Usage guidelines
The --config keyword is required for this command.
Examples
# Allocate a maximum of 4 GB of memory to VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh setmaxmem vm0 4096000 --config
virsh setmem
Use virsh setmem to allocate memory to a VM.
Syntax
virsh setmem < domain > < size > [ --config ] [ --live ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
size: Sets the amount of memory allocated to the VM, in KB. The value range for this argument is 512000 to the maximum amount of memory that can be allocated to the VM plane.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
If you use this command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Examples
# Allocate 2 GB of memory to VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh setmem vm0 2048000 --config
virsh setvcpus
Use virsh setvcpus to set the number of CPU cores allocated to a VM.
Syntax
virsh setvcpus < domain > < count > [ --maximum ] [ --config ] [ --live ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
count: Sets the number of CPU cores allocated to the VM. The value range for this argument is 1 to the maximum number of CPU cores allocated to the VM plane.
---maximum: Sets the maximum number of CPU cores that can be used by the VM. You must use this keyword in conjunction with the --config keyword.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
If you use this command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Some earlier operating systems do not support the --live keyword. With such an operating system, you cannot immediately allocate more CPU cores to a VM when the VM is running. Centos 7.4 and later support the --live keyword. With such an operating system, you can immediately allocate more CPU cores to a VM when the VM is running.
You cannot immediately reduce the number of CPU cores allocated to a VM when the VM is running.
Examples
# Allocate a maximum of six CPU cores to VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh setvcpus vm0 6 --maximum --config
virsh shutdown
Use virsh shutdown to shut down a VM.
Syntax
virsh shutdown < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Usage guidelines
Typically, shutting down a VM takes less than 2 minutes. If the system fails to shut down a VM within 2 minutes, you can forcibly shut down that VM.
Examples
# Shut down VM VM0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh shutdown vm0
Domain vm0 is being shutdown
Related commands
virsh start
virsh destroy
virsh snapshot-create-as
Use virsh snapshot-create-as to create a snapshot for a VM.
Syntax
virsh snapshot-create-as < domain > [ --name < string > ] [ --description < string > ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--name < string >: Specifies a name for the VM snapshot, a case-sensitive string.
--description < string >: Specifies a description for the VM snapshot, a case-sensitive string.
Usage guidelines
Make sure the VM has been shut down before you use this command.
The system cannot create a snapshot for a VM if the VM contains drives whose file system format is RAW. Before you use this command, make sure the file system format of all drives on the VM is QCOW2.
This command adds a mark to the running configuration of the VM each time you use this command. If you have created a snapshot for a VM, the subsequent snapshots you created for the VM are the child snapshots of the first snapshot. The first snapshot is also called the current snapshot.
Examples
# Create snapshot vm0.bak.1 for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh snapshot-create-as vm0 --name vm0.bak.1 --description excemple
Domain snapshot vm0.bak.1 created
Related commands
virsh snapshot-current
virsh snapshot-delete
virsh snapshot-current
Use virsh snapshot-current to display the current snapshot of a VM.
Syntax
virsh snapshot-current < domain > [ --name ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--name: Displays only the VM snapshot name. If you do not specify this keyword, the command displays detailed information about the VM snapshot.
Examples
# Display the current snapshot of VM wm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh snapshot-current vm0 --name
vm0.bak.1
Table 13 Command output
Field |
Description |
vm0.bak.1 |
Name of the current VM snapshot. |
virsh snapshot-delete
Use virsh snapshot-delete to delete VM snapshots.
Syntax
virsh snapshot-delete < domain > [ --snapshotname < string > ] [ --current ] [ --children ] [ --children-only ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
--snapshotname < string >: Specifies a VM snapshot by its name.
--current: Specifies the current snapshot of the VM.
--children: Specifies VM snapshots and their child snapshots.
--children-only: Specifies only child snapshots.
Usage guidelines
If you do not specify any parameters, this command deletes all VM snapshots.
Examples
# Delete snapshot vm0.bak.1 for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh snapshot-delete vm0 --snapshotname vm0.bak.1
Domain snapshot vm0.bak.1 deleted
Related commands
virsh snapshot-create-as
virsh snapshot-list
Use virsh snapshot-list to display all snapshots for a VM.
Syntax
virsh snapshot-list < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
Examples
# Display all snapshots for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh snapshot-list vm0
Name Creation Time State
------------------------------------------------------
vm0.bak.1 2017-05-26 03:29:35 +0000 shutoff
Table 14 Command output
Field |
Description |
Name |
Snapshot name. |
Creation Time |
Time when the snapshot was created. |
State |
Snapshot state: · shutoff—Shut down. · running—Running. |
virsh snapshot-revert
Use virsh snapshot-revert to use a VM snapshot to roll back a VM.
Syntax
virsh snapshot-revert < domain > [ --snapshotname < string > ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--snapshotname < string >: Specifies a VM snapshot by its name, a case-sensitive string.
Usage guidelines
Make sure the VM has been shut down before you use this command.
Examples
# Use snapshot vm0.bak.1 to roll back VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh snapshot-revert generic vm0.bak.1
virsh start
Use virsh start to start a VM.
Syntax
virsh start < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
Examples
# Start VM VM0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh start vm0
Domain vm0 started
Related commands
virsh shutdown
virsh suspend
Use virsh suspend to suspend a VM.
Syntax
virsh suspend < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Examples
# Suspend VM VM0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh suspend vm0
Domain vm0 suspended
virsh undefine
Use virsh undefine to uninstall a VM.
Syntax
virsh undefined < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
Usage guidelines
Use this command only when the VM is shut down.
After you uninstall a VM, the disk files attached to the VM are not deleted. To release storage space, use the delete command to manually delete the disk files. For more information about the delete command, see file system management commands in Fundamentals Command Reference.
Examples
# Uninstall VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh undefine vm0
Domain vm0 has been undefined
virsh vcpucount
Use virsh vcpucount to display the number of CPU cores allocated to a VM.
Syntax
virsh vcpucount < domain > [ --maximum ] [ --active ] [ --live ] [ --config ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
--maximum: Displays only the maximum number of CPU cores that can be used by the VM.
--active: Displays only the number of CPU cores currently used by the VM.
--config: Displays only the number of CPU cores allocated to the VM in the .xml file of the VM.
--live: Displays only the number of CPU cores allocated to the VM at the current running of the VM. The number might be different from the number in the .xml file of the VM.
Usage guidelines
If you do not specify the --maximum, --active, --config, or --live keyword, this command displays the number of CPU cores allocated to a VM in each scenario.
Examples
# Display the number of CPU cores allocated to VM vm0 in each scenario.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh vcpucount vm0
maximum config 6
maximum live 6
current config 6
current live 6
Table 15 Command output
Field |
Description |
maximum |
Maximum number of CPU cores that can be used by the VM. |
current |
Number of CPU cores currently used by the VM. |
config |
Number of CPU cores used by the VM at next startup. |
live |
Number of CPU cores that can be used by the VM at the current running of the VM. |
virsh vcpuinfo
Use virsh vcpuinfo to display detailed information about vCPU cores for a VM.
Syntax
virsh vcpuinfo < domain > [ --pretty ]
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-insensitive string.
--pretty: Displays CPU affinity information intuitively.
Usage guidelines
The CPU Affinity field displays the value range for the numbers of physical CPU cores that can be bound to vCPUs and the total number of physical CPU cores. With the --pretty keyword, this command displays the number value range and the total number intuitively, for example, 3-7 (out of 8). Without the --pretty keyword, this command displays the number value range and the total number in code, for example, ---yyyyy.
Examples
# Display detailed information about CPU cores for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh vcpuinfo vm0 --pretty
VCPU: 0
CPU: 2
State: running
CPU time: 2.2s
CPU Affinity: 3-7 (out of 8)
...
Table 16 Command output
Field |
Description |
VCPU |
vCPU core number. |
CPU |
Physical CPU core number. |
State |
State of the vCPU core. |
CPU time |
vCPU time. |
CPU Affinity |
Value range for the numbers of physical CPU cores that can be bound to vCPUs and the total number of physical CPU cores. For example, this field displays 3-7 (out of 8) if the number value range is 3 to 7 and the total number is 8. |
virsh vcpupin
Use virsh vcpupin to bind a vCPU core and a physical CPU core for a VM or display the bindings between vCPU cores and physical CPU cores for a VM.
Syntax
Bind a vCPU core and a physical CPU core for a VM:
virsh vcpupin < domain > [ --vcpu < number > ] [ --cpulist < string > ] [ --config ] [ --live ]
Display the bindings between vCPU cores and physical CPU cores for a VM:
virsh vcpupin < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
--vcpu < number >: Specifies a vCPU core by its number.
--cpulist < string >: Specifies a physical CPU core by its number.
--config: Applies the configuration to the .xml file of the VM. The configuration will take effect at the next VM startup.
--live: Activates the configuration immediately when the VM is running. The configuration will lose effect at the next VM startup.
Usage guidelines
If you use this command without specifying the --config or --live keyword when the VM is running, the --live keyword applies.
Examples
# Bind vCPU core 0 and physical CPU core 2 for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh vcpupin vm0 --vcpu 0 --cpulist 2 --config
# Display the bindings between vCPU cores and physical CPU cores for VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh vcpupin vm0
VCPU CPU Affinity
----------------------
0 2
1 3
2 4
3 5
4 6
5 7
Table 17 Command output
Field |
Description |
VCPU |
VM vCPU core number. |
CPU Affinity |
Physical CPU core number. |
Related commands
set vcpu-pool
virsh vncdisplay
Use virsh vncdisplay to display the VNC port number of a VM.
Syntax
virsh vncdisplay < domain >
Views
VMM view
Predefined user roles
network-admin
Parameters
domain: Specifies a VM by its name, ID, or UUID, a case-sensitive string.
Usage guidelines
The VNC port number is used to log in to the GUI of the VM.
Examples
# Display the VNC port number of VM vm0.
<Sysname> system-view
[Sysname] vmm
[Sysname-vmm] virsh vncdisplay vm0
:1
vmm
Use vmm to enter virtual machine management (VMM) view from system view.
Syntax
vmm
Views
System view
Predefined user roles
network-admin
Usage guidelines
Enable the device virtualization feature before you use this command.
Examples
# Enter VMM view.
<Sysname> system-view
[Sysname] vmm