Show Table of Contents
6.2. Creating Guests with virt-install
You can use the
virt-installcommand to create guest virtual machines from the command line.
virt-installis used either interactively or as part of a script to automate the creation of virtual machines. Using
virt-installwith Kickstart files allows for unattended installation of virtual machines.
virt-installtool provides a number of options that can be passed on the command line. To see a complete list of options run the following command:
# virt-install --help
Note that you need root privileges in order for
virt-installcommands to complete successfully. The
virt-installman page also documents each command option and important variables.
qemu-imgis a related command which may be used before
virt-installto configure storage options.
An important option is the
--graphicsoption which allows graphical installation of a virtual machine.
Example 6.1. Using virt-install to install a Red Hat Enterprise Linux 5 guest virtual machine
This example creates a Red Hat Enterprise Linux 5 guest:
virt-install \ --name=guest1-rhel5-64 \ --file=/var/lib/libvirt/images/guest1-rhel5-64.dsk \ --file-size=8 \ --nonsparse --graphics spice \ --vcpus=2 --ram=2048 \ --location=http://example1.com/installation_tree/RHEL5.6-Server-x86_64/os \ --network bridge=br0 \ --os-type=linux \ --os-variant=rhel5.4
Ensure that you select the correct
os-typefor your operating system when running this command.
man virt-installfor more examples.
When installing a Windows guest with
--os-type=windowsoption is recommended. This option prevents the CD-ROM from disconnecting when rebooting during the installation procedure. The
--os-variantoption further optimizes the configuration for a specific guest operating system.
After the installation completes, you can connect to the guest operating system. For more information, see Section 6.5, “Connecting to Virtual Machines”