Title: Manage Virtual Machines
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Virtual Media

In the process of creating virtual machines, the first step is the management of virtual media.  This would include cd-rom or dvd images as well as virtual hard drives.

To create an image of a cd-rom or dvd, simply copy the iso file to /var/lib/libvirt/images.  This is the default location for media images.

Although many formats are supported, the two most popular formats for virtual hard drives are raw and qcow2.  The main advantage with raw is performance.  The qcow2 format is useful when sparse files are needed, since the image file on the host will start small and grow as needed up to the maximum size.

This command will create a raw image which is 8 GB in size.

dd if=/dev/zero of=/var/lib/libvirt/images/server1-vda.img bs=1M count=8192

This command will create a qcow2 image which is 20 GB in size.

qemu-img create -f qcow2 -o preallocation=metadata server1-vdb.qcow2 20G

This command will convert another disk image format to raw.

qemu-img convert server2.vmdk -O server2.img

Notice that the newly created hard drives have not yet been formatted and do not have any partitions. A converted image will have the same partitions and filesystems which were on the original image.

Virtual Machines

Virtual machines can be managed from the command line using the virsh command.  The first command lists the running domains (guests) on a host, and the second lists all domains.

virsh list
virsh list --all

To boot a domain, run the start command with the domain's name.  Optionally add the --console option to see the boot process.  Use the ctrl-] key combination to exit the console mode.

virsh start server1
virsh start server1 --console

The domain can be paused and resumed.

virsh suspend server1
virsh resume server1

The domain can also be shutdown gracefully, rebooted, forced to power off, or forced to reset.

converted image will have the same partitions and filesystems which were on the original image.

Virtual Machines

Virtual machines can be managed from the command line using the virsh command.  The first command lists the running domains (guests) on a host, and the second lists all domains.

virsh list
virsh list --all

To boot a domain, run the start command with the domain's name.  Optionally add the --console option to see the boot process.  Use the ctrl-] key combination to exit the console mode.

virsh start server1
virsh start server1 --console

The domain can be paused and resumed.

virsh suspend server1
virsh resume server1

The domain can also be shutdown gracefully, rebooted, forced to power off, or forced to reset.

virsh shutdown server1
virsh reboot server1
virsh destroy server1
virsh reset server1

A final operation is to delete a domain.  If needed, use the destroy command first to power off the server, then delete it.  Optionally delete the hard drive images for the domain from /var/lib/libvirt/images.

virsh destroy server1
virsh undefine server1

There are many more options for virsh, such as managing network and storage settings.  Run the help command to see more information.

virsh help | more