Table 19.2. Resource management options
These are miscellaneous
virsh options:
Table 19.3. Miscellaneous optionsConnecting to the hypervisorConnect to a hypervisor session withvirsh :
# virsh connect
Where
<name> is the machine name of the hypervisor. To initiate a read-only connection, append the above command with -readonly .
Creating a virtual machine XML dump(configuration file)Output a guest's XML configuration file withvirsh :
virsh dumpxml
This command outputs the domain information (in XML) to
stdout . You save the data by piping the output to a file.
virsh dumpxmlThe file guest.xml can then be used to recreate the guest (refer to Creating a guest from a configuration file. You can edit this XML configuration file to configure additional devices or to deploy additional guests. Refer to Section 26.1, “Using XML configuration files with virsh” for more information on modifying files created with virsh dumpxml .
An example of
virsh dumpxml output:
# virsh dumpxml r5b2-mySQL01 <domain type='xen' id='13'> <name>r5b2-mySQL01</name> <uuid>4a4c59a7ee3fc78196e4288f2862f011</uuid> <bootloader>/usr/bin/pygrub</bootloader> <os> <type>linux</type> <kernel>/var/lib/xen/vmlinuz.2dgnU_</kernel> <initrd>/var/lib/xen/initrd.UQafMw</initrd> <cmdline>ro root=/dev/VolGroup00/LogVol00 rhgb quiet</cmdline> </os> <memory>512000</memory> <vcpu>1</vcpu> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <interface type='bridge'> <source bridge='xenbr0'/> <mac address='00:16:3e:49:1d:11'/> <script path='vif-bridge'/> </interface> <graphics type='vnc' port='5900'/> <console tty='/dev/pts/4'/> </devices> Creating a guest from a configuration fileGuests can be created from XML configuration files. You can copy existing XML from previously created guests or use thedumpxml option(refer to Creating a virtual machine XML dump(configuration file)). To create a guest with virsh from an XML file:
# virsh create
Suspending a guestSuspend a guest withvirsh :
virsh suspend
When a domain is in a suspended state, it consumes system RAM but not processor resources. Disk and network I/O does not occur while the guest is suspended. This operation is immediate and the guest can be restarted with the
resume (Resuming a guest) option.
Resuming a guestRestore a suspended guest withvirsh using the resume option:
virsh resume
This operation is immediate and the guest parameters are preserved for
suspend and resume operations.
Save a guestSave the current state of a guest to a file using thevirsh command:
virsh save
This stops the guest you specify and saves the data to a file, which may take some time given the amount of memory in use by your guest. You can restore the state of the guest with the
restore (Restore a guest) option. Save is similar to pause, instead of just pausing a guest the present state of the guest is saved.
Restore a guestRestore a guest previously saved with thevirsh save command(Save a guest) using virsh :
virsh restore
This restarts the saved guest, which may take some time. The guest's name and UUID are preserved but are allocated for a new id.
Shut down a guestShut down a guest using thevirsh command:
virsh shutdown
You can control the behavior of the rebooting guest by modifying the
on_shutdown parameter in the guest's configuration file file.
Rebooting a guestReboot a guest usingvirsh command:
virsh reboot
You can control the behavior of the rebooting guest by modifying the
on_reboot parameter in the guest's configuration file file.
Forcing a guest to stopForce a guest to stop with thevirsh command:
virsh destroy
This command does an immediate ungraceful shutdown and stops any guest domain sessions (which could potentially lead to file corrupted file systems still in use by the guest). You should use the
destroy option only when the guest is unresponsive. For para-virtualized guests, use the shutdown option(Shut down a guest) instead.
Getting the domain ID of a guestTo get the domain ID withvirsh :
virsh domid
Getting the domain name of a guestTo get the domain name withvirsh :
virsh domname [domain-id or domain-uuid] Getting the UUID of a guestTo get the UUID with virsh :virsh domuuid [domain-id or domain-name]
An example of
virsh domuuid output:
# virsh domuuid r5b2-mySQL01 4a4c59a7-ee3f-c781-96e4-288f2862f011 Displaying guest InformationUsingvirsh with the guest's domain ID, domain name or UUID you can display information on the specified guest:
virsh dominfo
This is an example of
virsh dominfo output:
# virsh dominfo r5b2-mySQL01 id: 13 name: r5b2-mysql01 uuid: 4a4c59a7-ee3f-c781-96e4-288f2862f011 os type: linux state: blocked cpu(s): 1 cpu time: 11.0s max memory: 512000 kb used memory: 512000 kb Displaying hypervisor informationTo display hypervisor informationvirsh :
virsh nodeinfo
An example of
virsh nodeinfo output:
CPU model x86_64 CPU (s) 8 CPU frequency 2895 Mhz CPU socket(s) 2 Core(s) per socket 2 Threads per core: 2 Numa cell(s) 1 Memory size: 1046528 kb
This displays the node information and the machines that support the virtualization process.
Displaying the guestsTo display the guest list and their current states withvirsh :
virsh list
Other options available include:
the
--inactive option which lists inactive domains (domains that have been defined but are not currently active), and
the
--all domain lists all domains, whether active or not. Your output should resemble the this example:
Id Name State ---------------------------------- 0 Domain-0 running 1 Domain202 paused 2 Domain010 inactive 3 Domain9600 crashed
The output from
virsh list is categorized as one of the six states(listed below).
Displaying virtual CPU informationTo display virtual CPU information from a guest withvirsh :
virsh vcpuinfo [domain-id, domain-name or domain-uuid]
An example of
virsh vcpuinfo output:
# virsh vcpuinfo r5b2-mySQL01 VCPU: 0 CPU: 0 State: blocked CPU time: 0.0s CPU Affinity: yy Configuring virtual CPU affinityTo configure the affinity of virtual CPUs with physical CPUs:virsh vcpupin [domain-id, domain-name or domain-uuid] [vcpu] , [cpulist]
Where
[vcpu] is the virtual VCPU number and [cpulist] lists the physical number of CPUs.
Configuring virtual CPU countTo modify a domain's number of CPUs withvirsh :
virsh setvcpus
The new
count
value cannot exceed the count above the amount specified when the guest was created.
Configuring memory allocationTo modify a guest's memory allocation withvirsh :
virsh setmem [domain-id or domain-name] [count]
You must specify the
[count]
in kilobytes. The new count value cannot exceed the amount you specified when you created the guest. Values lower than 64 MB are unlikely to work with most guest operating systems. A higher maximum memory value will not affect the an active guest unless the new value is lower which will shrink the available memory usage.
Managing virtual networksThis section covers managing virtual networks with thevirsh command. To list virtual networks:
virsh net-list
This command generates output similar to:
[root@domain ~]# virsh net-list Name State Autostart ----------------------------------------- default active yes vnet1 active yes vnet2 active yes
To view network information for a specific virtual network:
virsh net-dumpxml [vnet name]
This displays information about a specified virtual network in XML format:
# virsh net-dumpxml vnet1 <network> <name>vnet1</name> <uuid>98361b46-1581-acb7-1643-85a412626e70</uuid> <forward dev='eth0'/> <bridge name='vnet0' stp='on' forwardDelay='0' /> <ip address='192.168.100.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.100.128' end='192.168.100.254' /> </dhcp> </ip> </network>
Other
virsh commands used in managing virtual networks are:
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|