The KVM (Kernel-based virtual Machine) virtualization technology has several options regarding the configuration and management of the virtual machines. In order to create a new virtual machine, we can use the VMM (Virtual Machine Manager), which is a tool with a great GUI, and very similar to the rest of the virtualization technologies tools (such as VMWare workstation, or VirtualBox, etc), but it is also possibleto create a new virtual machine without this GUI, through command-line.
In the case we use the GUI tool, the configuration is very similar to the rest of the applications, what has to be indicated are the disks, memory, network, etc, etc. Another trait, is that an existing virtual machine can be modified. Nevertheless, the alternative of the command line, could be useful in order to deploy new virtual machines faster.
This command-line based installation, is going to be accomplished through the virt-install tool, and we can check the manual page (man virt-install) to know more about this tool and its parameters.
In this case, the example is about the creation of a new virtual machine from scratch (a new Arch Linux OS), installing it by its .iso image.
One of the steps on the creation of the new virtual machine, is the installation, which will display a new screen for the new virtual machine, and this requires a program called virt-viewer , so we first need to install this before performing the installation:
sudo apt-get install virt-viewer
After installing this tool, we can continue with the installation, indicating the main parameters of the virtual machine. According to the man page we an indicate some of the following parameters, such as the name of the new virtual machine, the amount of RAM memory, the path of the virtual disk file (and its type, keeping in mind the types of file system supported by KVM), the network configuration (if we are going to use networking functions on this machine), and the CDROM (if any). other parameters can also be indicated for having a more detailed configuration, such as the boot order (–boot), the CPU architecture, or configurations, the screen, etc. It is noticed that the virt-install tool has a lot of possible allowed configurations.
In this case I will create this new virtual machine from the ISO image that I’ve downloaded, and I’ll proceed with the installation, so the command I ran was:
virt-install --name arch-vm --ram 64 --disk path=/home/rmariano/vm-disks/arch.vmdk,size=1 --network bridge=virbr0 --vnc --os-variant generic26 --cdrom software/archlinux-2011.08.19-core-x86_64.iso --boot hd,cdrom --cpu host
Where –name arch-vm means that the new name is called ‘arch-vm’, –ram 64 is the amount of assigned memory (64Mb). The following path, –disk path=/home/rmariano/vm-disks/arch.vmdk,size=1 indicates to create a new virtual disk typed on vmdk format (the format of vm-ware is supported by KVM), and with 1Gb of disk space. Then the networking configuration is indicated by –network bridge=virbr0 which means to use the bridge called ‘virbr0’ for this configuration (using a bridge requires root privileges, so this command must be executed with ‘sudo’ prefix due to this parameter), and there are also other possible options, like network=default (there has to be a default network configuration for the virtualization). The –vnc indicates the graphics, and then -os-variant generic26 means that the OS is a Linux with kernel 2.6.
After that, one of the most important parts is the CDROM parameter, in –cdrom software/archlinux-2011.08.19-core-x86_64.iso which links the CDROM to this ISO file, and mounts this way the image for the installation of the OS (the idea is that the machine will boot, then it will read the cdrom and the installation should start). However for this purpose, we need to ensure the boot order, and this is indicated in –boot hd,cdrom which means to boot first from the hard disk (the first time will be empty so it will continue with the cdrom), and then the CDROM. The last parameter, indicates the type of CPU used for the VM. In this case ‘host’ means to use the host CPU (the one of the hypervisor), and this is a great advantage in terms of performance (the instruction set will be more accurate), but it also makes this less multi platform (the CPU of the hypervisor may be different from one implementation to another, and this has to be considered if we want to migrate the virtual machine in the future – the migration of virtual machines is another interesting topic-).
Once this command was executed without issues, the virtual machine should be displayed:
Regardless the installation or configuration method, the virtual machine is created in the same way, and as it was mentioned in the first post about KVM the configuration about the virtual machine is stored in a .xml configuration file, which can be simple checked by using the ‘edit’ tool of virsh using the name of the virtual machine, in this case:
virsh edit arch-vm
Will show some of the main parameters, like for example the configurations:
Here we can see, the name of the virtual machine, the number of CPUs,etc. the rest of the configurations (disk, etc.) are also in this file, located by default in /etc/libvirt/qemu/arch-vm.xml , and a change on this file, will modify the virtual machine.
All in all, this is another option for the creation of new virtual machines, that shows how open is this technology is in terms of functionality, configurations, and management.