20.27. Host Machine Management
20.27.1. Displaying Host Information
virsh nodeinfocommand displays basic information about the host, including the model number, number of CPUs, type of CPU, and size of the physical memory. The output corresponds to the
virNodeInfostructure. Specifically, the "CPU socket(s)" field indicates the number of CPU sockets per NUMA cell.
Example 20.54. How to display information about your host machine
virsh nodeinfoCPU model: x86_64 CPU(s): 4 CPU frequency: 1199 MHz CPU socket(s): 1 Core(s) per socket: 2 Thread(s) per core: 2 NUMA cell(s): 1 Memory size: 3715908 KiB
20.27.2. Setting NUMA Parameters
virsh numatunecommand can either set or retrieve the NUMA parameters for a specified guest virtual machine. Within the guest virtual machine's configuration XML file these parameters are nested within the
<numatune>element. Without using flags, only the current settings are displayed. The
numatune domaincommand requires a specified guest virtual machine name and can take the following arguments:
--mode- The mode can be set to either
preferred. Running domains cannot have their mode changed while live unless the guest virtual machine was started within
--nodesetcontains a list of NUMA nodes that are used by the host physical machine for running the guest virtual machine. The list contains nodes, each separated by a comma, with a dash
-used for node ranges and a caret
^used for excluding a node.
- Only one of the three following flags can be used per instance
--configwill effect the next boot of a persistent guest virtual machine
--livewill set the scheduler information of a running guest virtual machine.
--currentwill effect the current state of the guest virtual machine.
Example 20.55. How to set the NUMA parameters for the guest virtual machine
strictfor nodes 0, 2, and 3 for the running guest1 virtual machine:
virsh numatune guest1
<numatune> <memory mode='strict' nodeset='0,2-3'/> </numatune>
20.27.3. Displaying the Amount of Free Memory in a NUMA Cell
virsh freecellcommand displays the available amount of memory on the machine within a specified NUMA cell. This command can provide one of three different displays of available memory on the machine depending on the options specified. specified cell.
Example 20.56. How to display memory properties for virtual machines and NUMA cells
virsh freecellTotal: 684096 KiB
virsh freecell0: 804676 KiB -------------------- Total: 804676 KiB
virsh freecell0: 772496 KiB
20.27.4. Displaying a CPU List
virsh nodecpumapcommand displays the number of CPUs that are available to the host machine, and it also lists how many are currently online.
Example 20.57. How to display number of CPUs that available to the host
virsh nodecpumapCPUs present: 4 CPUs online: 1 CPU map: y
20.27.5. Displaying CPU Statistics
virsh nodecpustatscommand displays statistical information about the CPUs load status of the host. If a CPU is specified, the statistics are only for the specified CPU. If the
percentoption is specified, the command displays the percentage of each type of CPU statistics that were recorded over an one (1) second interval.
Example 20.58. How to display statistical information about CPU usage
virsh nodecpustatsuser: 1056442260000000 system: 401675280000000 idle: 7549613380000000 iowait: 94593570000000
virsh nodecpustats 2 --percentusage: 2.0% user: 1.0% system: 1.0% idle: 98.0% iowait: 0.0%
20.27.6. Managing Devices
22.214.171.124. Attaching and updating a device with virsh
Procedure 20.4. Hot plugging USB devices for use by the guest virtual machine
- Locate the USB device you want to attach by running the following command:
lsusb -vidVendor 0x17ef Lenovo idProduct 0x480f Integrated Webcam [R5U877]
- Create an XML file and give it a logical name (
usb_device.xml, for example). Copy the vendor and product ID number (a hexidecimal number) exactly as was displayed in your search. Add this information to the XML file as shown in Figure 20.2, “USB devices XML snippet”. Remember the name of this file as you will need it in the next step.
<hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x17ef'/> <product id='0x480f'/> </source> </hostdev>
Figure 20.2. USB devices XML snippet
- Attach the device by running the following command. When you run the command, replace guest1 with the name of your virtual machine and usb_device.xml with the name of your XML file that contains the vendor and product ID of your device, which you created in the previous step. For the change take effect at the next reboot, use the
--configargument. For the change to take effect on the current guest virtual machine, use the
--currentargument. See the virsh man page for additional arguments.
virsh attach-device guest1
Example 20.59. How to hot unplug devices from a guest virtual machine
virsh detach-device guest1
126.96.36.199. Attaching interface devices
virsh attach-interface domain type sourcecommand can take the following arguments:
--type- allows you to set the interface type
--source- allows you to set the source of the network interface
--live- gets its value from running guest virtual machine configuration settings
--config- takes effect at next boot
--current- gets its value according to the current configuration settings
--target- indicates the target device in the guest virtual machine.
--mac- use this option to specify the MAC address of the network interface
--script- use this option to specify a path to a script file handling a bridge instead of the default one.
--model- use this option to specify the model type.
--inbound- controls the inbound bandwidth of the interface. Acceptable values are
--outbound- controls the outbound bandwidth of the interface. Acceptable values are
NoteValues for average and peak are expressed in kilobytes per second, while burst is expressed in kilobytes in a single burst at peak speed as described in the Network XML upstream documentation.
networkto indicate a physical network device, or
bridgeto indicate a bridge to a device. source is the source of the device. To remove the attached device, use the
Example 20.60. How to attach a device to the guest virtual machine
virsh attach-interface guest1 networkw
188.8.131.52. Changing the media of a CDROM
virsh change-mediacommand changes the media of a CDROM to another source or format. The command takes the following arguments. More examples and explanation for these arguments can also be found in the man page.
--path- A string containing a fully-qualified path or target of disk device
--source- A string containing the source of the media
--eject- Ejects the media
--insert- Inserts the media
--update- Updates the media
--current- Can be either or both of
--config, which depends on implementation of hypervisor driver
--live- Alters the live configuration of running guest virtual machine
--config- Alters the persistent configuration, effect observed on next boot
--force- Forces media to change
20.27.7. Setting and Displaying the Node Memory Parameters
virsh node-memory-tunecommand displays and allows you to set the node memory parameters. The following parameters may be set with this command:
[shm-pages-to-scan] [shm-sleep-milisecs] [shm-merge-across-nodes]
--shm-pages-to-scan- sets the number of pages to scan before the kernel samepage merging (KSM) service goes to sleep.
--shm-sleep-milisecs- sets the number of miliseconds that KSM will sleep before the next scan
--shm-merge-across-nodes- specifies if pages from different NUMA nodes can be merged
Example 20.61. How to merge memory pages across NUMA nodes
20.27.8. Listing Devices on a Host
virsh nodedev-list --capcommand lists all the devices available on the host that are known to the libvirt service. --cap is used to filter the list by capability types, each separated by a comma, and cannot be used with
--tree. Using the argument
--tree, puts the output into a tree structure.
Example 20.62. How to display the devices available on a host
virsh nodedev-listcomputer | +- net_lo_00_00_00_00_00_00 +- net_macvtap0_52_54_00_12_fe_50 +- net_tun0 +- net_virbr0_nic_52_54_00_03_7d_cb +- pci_0000_00_00_0 +- pci_0000_00_02_0 +- pci_0000_00_16_0 +- pci_0000_00_19_0 | | | +- net_eth0_f0_de_f1_3a_35_4f [...]
virsh nodedev-list --cap scsiscsi_0_0_0_0
20.27.9. Creating Devices on Host Machines
virsh nodedev-create filecommand allows you to create a device on a host physical machine and then assign it to a guest virtual machine. Although libvirt automatically detects which host nodes are available for use, this command allows you to register hardware that libvirt did not detect. The specified file should contain the XML description for the top level
<device>description of the host device. For an example of such file, see Example 20.65, “How to retrieve the XML file for a device”.
Example 20.63. How to create a device from an XML file
scsi_host2.xml. The following command enables you to attach this device to your guests:
virsh nodedev-create scsi_host2.xml
20.27.10. Removing a Device
virsh nodedev-destroycommand removes the device from the host. Note that the virsh node device driver does not support persistent configurations, so rebooting the host machine makes the device usable again.
--driverargument allows you to specify the intended back-end driver.
Example 20.64. How to remove a device from a host physical machine
virsh nodedev-destroy scsi_host2
20.27.11. Collect Device Configuration Settings
virsh nodedev-dumpxml devicecommand outputs the XML representation for the specified host device, including information such as the device name, the bus to which the device is connected, the vendor, product ID, capabilities, as well as any information usable by
libvirt. The argument device can either be a device name or WWN pair in WWNN, WWPN format (HBA only).
Example 20.65. How to retrieve the XML file for a device
virsh nodedev-dumpxml scsi_host2<device> <name>scsi_host2</name> <parent>scsi_host1</parent> <capability type='scsi_host'> <capability type='fc_host'> <wwnn>2001001b32a9da5b</wwnn> <wwpn>2101001b32a9da5b</wwpn> </capability> </capability> </device>
20.27.12. Triggering a Reset for a Device
virsh nodedev-reset devicecommand triggers a device reset for the specified device. Running this command is useful prior to transferring a node device between guest virtual machine pass through or the host physical machine.
libvirtwill do this action automatically, when required, but this command allows an explicit reset when needed.
Example 20.66. How to reset a device on a guest virtual machine
virsh nodedev-reset scsi_host2