6.2. Creating Guests with virt-install
You can use the
virt-install command to create guest virtual machines from the command line. virt-install is used either interactively or as part of a script to automate the creation of virtual machines. Using virt-install with Kickstart files allows for unattended installation of virtual machines.
The
virt-install tool 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-install commands to complete successfully. The virt-install man page also documents each command option and important variables.
qemu-img is a related command which may be used before virt-install to configure storage options.
An important option is the
--graphics option 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-type for your operating system when running this command.
Refer to
man virt-install for more examples.
Note
When installing a Windows guest with
virt-install, the --os-type=windows option is recommended. This option prevents the CD-ROM from disconnecting when rebooting during the installation procedure. The --os-variant option 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”