Table of Contents

VMINFO

Base VM created. Specs of this are as follows

This machine is the base os to clone to other VMs. This when running can be accessed via the console when connected to HAL. I have created 3 users. These are darren, dave, and wayne. Auth keys copied from Skype, and other sources to allow them all to connect to this machine when turned on or copied to another target. No confirguration of the clined VMs due to ssh and user configuration completed on this machine.

To clone the above. Log in to vms it will take you to the default vms user directory. the following code will need to be run uder this user keeping the paths the same.

virt-clone --original centosbase -n (Insert New Name) -f /var/lib/libvirt/vms/images/(name of image).qcow2

Connecting To the VM Through The Host

The following code has been activated on the Host. This must not be removed or stopped.

sudo systemctl enable serial-getty@ttyS0.servicesudo systemctl enable serial-getty@ttyS0.service

There are a number of ways to connect to each VM either via the use of an external program like Putty directly or via the Hosts command Line interface using virsh. In order to do this via the command line. We first need to get the name of the box we would like to connect to.

So first login as vms user and change to its home directory. Next we will run the following command to get a list of VMs avaliable.

virsh list

This will give the following output showing each VM available.

Id    Name   State
----------------------------------------------------
 7     base-v2                        paused
 8     base-v3                        running

We will then need to connect to the VM required. Note: You can only connect to VMs that are in the running state.

virsh console (Name Goes Here), eg virsh console base-v3

Quick Reference

virsh command quick reference taken from the following page. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/virtualization/chap-virtualization-managing_guests_with_virsh

The following tables provide a quick reference for all virsh command line options.

Guest management commands

CommandDescription
helpPrints basic help information.
listLists all guests.
dumpxmlOutputs the XML configuration file for the guest.
createCreates a guest from an XML configuration file and starts the new guest.
startStarts an inactive guest.
destroyForces a guest to stop.
defineOutputs an XML configuration file for a guest.
domidDisplays the guest's ID.
domuuidDisplays the guest's UUID.
dominfoDisplays guest information.
domnameDisplays the guest's name.
domstateDisplays the state of a guest.
quitQuits the interactive terminal.
rebootReboots a guest.
restoreRestores a previously saved guest stored in a file.
resumeResumes a paused guest.
saveSave the present state of a guest to a file.
shutdownGracefully shuts down a guest.
suspendPauses a guest.
undefineDeletes all files associated with a guest.
migrateMigrates a guest to another host.

The following virsh command options manage guest and hypervisor management options

CommandDescription
setmemSets the allocated memory for a guest.
setmaxmemSets maximum memory limit for the hypervisor.
setvcpusChanges number of virtual CPUs assigned to a guest. Note that this feature is unsupported in Red Hat Enterprise Linux 5.
vcpuinfoDisplays virtual CPU information about a guest.
vcpupinControls the virtual CPU affinity of a guest.
domblkstatDisplays block device statistics for a running guest.
domifstatDisplays network interface statistics for a running guest.
attach-deviceAttach a device to a guest, using a device definition in an XML file.
attach-diskAttaches a new disk device to a guest.
attach-interfaceAttaches a new network interface to a guest.
detach-deviceDetach a device from a guest, takes the same kind of XML descriptions as command attach-device.
detach-diskDetach a disk device from a guest.
detach-interfaceDetach a network interface from a guest.
domxml-from-nativeConvert from native guest configuration format to domain XML format. See the virsh man page for more details.
domxml-to-nativeConvert from domain XML format to native guest configuration format. See the virsh man page for more details.

These are miscellaneous virsh options

CommandDescription
versionDisplays the version of virsh
nodeinfoOutputs information about the hypervisor

Connecting to the hypervisorConnect to a hypervisor session with virsh:

# virsh connect ''{hostname OR URL}''

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 with virsh:

# virsh dumpxml ''{domain-id, domain-name or domain-uuid}''

This command outputs the guest's XML configuration file to standard out (stdout). You can save the data by piping the output to a file. An example of piping the output to a file called guest.xml:

# virsh dumpxml ''GuestID''> ''guest.xml''

This file guest.xml can recreate the guest . You can edit this XML configuration file to configure additional devices or to deploy additional guests. 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/libvirt/vmlinuz.2dgnU_</kernel>
         <initrd>/var/lib/libvirt/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:3[e:49:1d:11'/ e:49:1d:11'/]>
             <script path='vif-bridge'/>
         </interface>
     <graphics type='vnc' port='5900'/>
     <console tty='/dev/pts/4'/>
  </devices>
</domain>

<blockquote>

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 the dumpxml option. To create a guest with virsh from an XML file:

</blockquote>

# virsh create configuration_file.xml


</file>

Editing a guest's configuration fileInstead of using the dumpxml option, guests can be edited either while they run or while they are offline. The virsh edit command provides this functionality. For example, to edit the guest named //baseos-v3//:

<code># virsh edit baseos-v3

This opens a text editor. The default text editor is the $EDITOR shell parameter (set to vi by default).Suspending a guestSuspend a guest with virsh:

# virsh suspend {domain-id, domain-name or domain-uuid}

When a guest 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 option.Resuming a guestRestore a suspended guest with virsh using the resume option:

# virsh resume {domain-id, domain-name or domain-uuid}

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 the virsh command:

# virsh save {domain-name, domain-id or domain-uuid} filename


</file>

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. 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 the virsh save command using virsh:

<code># virsh restore filename


</file>

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 the virsh command:

<code># virsh shutdown {domain-id, domain-name or domain-uuid}

You can control the behavior of the rebooting guest by modifying the on_shutdown parameter in the guest's configuration file.Rebooting a guestReboot a guest using virsh command:

#virsh reboot {domain-id, domain-name or domain-uuid}

You can control the behavior of the rebooting guest by modifying the on_reboot element in the guest's configuration file.Forcing a guest to stopForce a guest to stop with the virsh command:

# virsh destroy {domain-id, domain-name or domain-uuid}

This command does an immediate ungraceful shutdown and stops the specified guest. Using virsh destroy can corrupt guest file systems . 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 of a guest:

# virsh domid {domain-name or domain-uuid}

Getting the domain name of a guestTo get the domain name of a guest:

# virsh domname {domain-id or domain-uuid}

Getting the UUID of a guestTo get the Universally Unique Identifier (UUID) for a guest:

# virsh domuuid {domain-id or domain-name}'

An example of virsh domuuid output:

# virsh domuuid r5b2-mySQL01 4a4c59a7-ee3f-c781-96e4-288f2862f011

Displaying guest Information Using virsh with the guest's domain ID, domain name or UUID you can display information on the specified guest:

# virsh dominfo {domain-id, domain-name or domain-uuid}

This is an example of virsh dominfo output:} Displaying host informationTo display information about the host:

# virsh nodeinfo

An example of virsh nodeinfo output:} This displays the node information and the machines that support the virtualization process.Displaying the guestsTo display the guest list and their current states with virsh:

# virsh list

Other options available include:the –inactive option to list inactive guests (that is, guests that have been defined but are not currently active), andthe –all option lists all guests. For example:

# virsh list --all
 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). * The running state refers to guests which are currently active on a CPU.

Displaying virtual CPU informationTo display virtual CPU information from a guest with virsh:

# 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

<blockquote>

Configuring virtual CPU affinityTo configure the affinity of virtual CPUs with physical CPUs:

</blockquote>

# virsh vcpupin domain-id vcpu cpulist

The domain-id parameter is the guest's ID number or name.The vcpu parameter denotes the number of virtualized CPUs allocated to the guest.The vcpu parameter must be provided.The cpulist parameter is a list of physical CPU identifier numbers separated by commas. The cpulist parameter determines which physical CPUs the VCPUs can run on.Configuring virtual CPU countTo modify the number of CPUs assigned to a guest with virsh:

# virsh setvcpus {domain-name, domain-id or domain-uuid} count

The new count value cannot exceed the count above the amount specified when the guest was created.Important

This feature is unsupported and known not to work in Red Hat Enterprise Linux 5.Configuring memory allocationTo modify a guest's memory allocation with virsh :

# 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 does not affect an active guests. If the new value is lower the available memory will shrink and the guest may crash.Displaying guest block device informationUse virsh domblkstat to display block device statistics for a running guest.

# virsh domblkstat GuestName block-device

Displaying guest network device informationUse virsh domifstat to display network interface statistics for a running guest.

# virsh domifstat GuestName interface-device

Migrating guests with virshA guest can be migrated to another host with virsh. Migrate domain to another host. Add –live for live migration. The migrate command accepts parameters in the following format:

# virsh migrate --live GuestName DestinationURL

The –live parameter is optional. Add the –live parameter for live migrations.The GuestName parameter represents the name of the guest which you want to migrate.The DestinationURL parameter is the URL or hostname of the destination system. The destination system requires: * the same version of Red Hat Enterprise Linux,

Once the command is entered you will be prompted for the root password of the destination system.Managing virtual networksThis section covers managing virtual networks with the virsh command. To list virtual networks:

# virsh net-list

This command generates output similar to:{{{ # 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 NetworkName'''

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: * virsh net-autostart network-name — Autostart a network specified as network-name.