Creating virtual machines using the Virtual Machine Manager
The following methods are available with virt-manager for Guest OS installation:
- Local installation media (ISO Image or CD-ROM)
- Network installation (HTTP, FTP, or NFS)
- Network boot (PXE)
- Importing existing disk images
In this section, we will create new virtual machines running different operating systems, each using one of the aforementioned installation methods, so that by the end of this chapter you will be familiar with all the available methods for creating virtual machines and will thoroughly understand the Create a new virtual machine wizard.
We will create the following Guest OS:
- Windows 7
- CentOS 6
To create the VM using a graphical interface, start the Virtual Machine Manager by executing the virt-manager
command or open it from the Applications | System Tools menu.
Creating a new virtual machine wizard
From Virtual Machine Manager, click on the Create a new virtual machine button on the toolbar or select File | New Virtual Machine to open the wizard, which allows creating new virtual machines from virt-manager.
The wizard breaks down the virtual machine creation process into five steps:
- Choosing the installation method.
- Configuring the installation media.
- Memory and CPU configuration.
- Virtual machine storage configuration.
- Naming the guest OS and networking configuration.
Let's create a virtual machine and install the CentOS 6.5 operating system using the Local Install media (ISO Image or CD-ROM) method.
This installation method requires the operating system installation media to be inserted into the system's CD-ROM tray, available in ISO form locally, or available over the network. The ideal location to keep the ISO file is /var/lib/libvirt/images
, which acts as the default storage pool for virt-manager with all the SELinux and other permissions set properly. If the ISO file is stored somewhere else on the system, ensure that virt-manager can access it before you continue.
- Once you have ensured that virt-manager has access to the installation media, the wizard will ask you to choose how you would like to install the operating system. Select Local install media (ISO Image or CDROM) and click on the Forward button:
- Clicking on the Forward button will take you to Step 2 where you have to specify the ISO image location. If you are using a physical DVD or CD, select that:
virt-manager automatically detects the operating system based on the install media. It uses the OS information database provided by
libosinfo
. At the time of writing, thelibosinfo
database contains information on nearly 302 operating systems, including Windows, Linux, Unix, and all of the most important Linux distributions. You can extract the operating system list from thelibosinfo
database by running thesinfo-query os
command.Tip
It's important to select the correct operating system name because the emulated hardware selection for the virtual machine is closely mapped to the operating system type set. For example, by default for windows OS, the virtual disk format is selected as IDE whereas for Linux operating system it's the
virtio
disk. - On the next screen, specify the memory and CPU that you want allocate for the virtual machine:
- The wizard shows the maximum amount of CPUs and memory you can allocate. Configure these settings and click Forward to configure storage for the virtual machine:
- Make sure you assign sufficient space for your virtual machine. By default, it creates a virtual disk at the
/var/lib/libvirt/qemu
location, which is the default pool. If there are any other custom storage pools defined on the system, select Managed or other existing storage and either directly enter the path of the disk or click on the Browse button, which will open the Locate or create storage volume dialog box where you can select an existing volume or create a new one from the defined storage pool, if any available. You will learn about storage pools and how to create them in the next chapter.Note
There is also a radio button, Allocate entire disk now, to choose a disk allocation method; deselecting this button will result in a thin-provisioned disk and selecting it will result in a thick-provisioned disk (also called a pre-allocated disk).
- The next and final step is naming the guest and networking configuration. The default machine name is based on the selected OS (for example,
centos6.5
for a CentOS 6.5 VM). You can change it to whatever name you want to give but note that only underscores (_
), periods (.
), and hyphens (-
) are supported:Expanding Advanced options will bring up the virtual network configuration setting. By default, KVM provides NAT-like bridged networking. The virtual machines connected to this NAT do not appear on the network as their own devices, but will have network access through the host operating system settings. If you're planning to run server software or a webserver on your virtual machine and want it accessible from other devices on the network, you'll have to use other virtual networking configurations such as Linux bridge or macvtap.
Set a fixed MAC Address allows you to define a custom MAC address for your virtual machine. The default MAC address range used by libvirt is
52:54:00
. - If you prefer to further configure the virtual machine's hardware first, check the Customize configuration before install box first before clicking Finish. Doing so will open another wizard that will allow you to add, remove, and configure the virtual machine's hardware settings.
- If everything goes well, a virtual console for the newly created VM appears. The new domain name appears in the domain list in the Virtual Machine Manager window. The installation starts with the boot: prompt just as an installation would start on native hardware:
- The last step in the installation wizard is clicking the Reboot button to reboot the system and complete the installation. After the VM reboots you will see the operating system login screen.
The Network installation (HTTP, FTP, or NFS) method
This method involves the use of a mirrored Red Hat Enterprise Linux, CentOS, or Fedora installation tree to install a guest. Virtual Machine creation and supported guest operating system installation using this method also involves five steps, starting with the installation method section and moving on to naming the guest and networking configuration.
The steps are the same as the ISO installation procedure except for step 2 (configuring the installation media). Instead of an ISO image, here we need to pass the URL of the RHEL/CentOS installation tree:
Optionally, you can also use Kickstart URL to point to your kickstart file for unattended guest installation, and Kernel options to pass a custom kernel boot parameter if required.
Network Boot (PXE)
This method uses a Preboot eXecution Environment (PXE) server to install the guest virtual machine. PXE Guest installation requires a PXE server running on the same subnet where you wish to create the virtual machine and the host system must have network connectivity to the PXE server.
The default NATed network created by virt-manager is not compatible with PXE installation, because a virtual machine connected to the NAT does not appear on the network as its own device, and therefore the PXE server can't see it and can't send the required data to perform the installation. To use PXE Guest OS installation, you need either a software network bridge or a macvtap-based network on the host system. Here, for example, we will use a macvtap-based network and initiate the installation.
- Select PXE as the installation method in the Create a New Virtual Machine wizard and follow the rest of the steps to configure the ISO installation procedure except for step 5 where the network is configured:
- In Advanced options use Host device eth0:macvtap from the drop-down list and set Source mode to Bridge. Set a custom MAC address if you need to and click on the Finish button to begin the installation.
Importing an existing disk image
As the name suggests, this allows you to import a pre-installed and configured disk image instead of doing a manual installation. The disk image must contain a bootable operating system. This is commonly used for distributing pre-built appliance images and also for moving a virtual machine from one host to another in offline mode.
Importing a disk is much faster than other options for preparing a virtual machine. Many Linux distros are available as pre-configured bootable disk images.
Note
You can download a pre-configured disk Fedora 22 image here: https://getfedora.org/en/cloud/download/.
- Launch the Create a New Virtual Machine wizard from the virt-manager GUI and select Import existing disk image as the OS installation method.
- Provide the existing image path. Make sure it's stored in one of the defined storage pools or a place that is accessible by virt-manager. Click on the Forward button and follow the remaining steps, which are the same as the ISO installation procedure (except for the step that requires a virtual machine to be ready):