Install KVM guest using command line

The gui virt-manager is nice to have and helps us manage/create KVM guests easily, but today I ran into a situation where X and VNC was not installed on the host and I was not allowed to install them. As a result, had to resort to command line tools to do the task. This tutorial/howto documents all the required knowledge to install , clone, edit KVM machines using the command line.

The required tools

We shall need the virt-install command line tool so if that is not available go ahead and as root or with sudo install it.,

[Error: Macro 'code' error: argument of type 'NoneType' is not iterable]

virt-install has a lot of options and you can have a look with virt-install -h

Install A Basic KVM Guest Using

[Error: Macro 'code' error: argument of type 'NoneType' is not iterable]

The above command will create a VM and starts the installation process. The problem is that you will still need a GUI such as virt-manager to be able to continue the installation. What we need to do is to use a kickstart file to do an unattended installation.

Installing the KVM Guest using Kickstart.

First we need to create a kickstart. The simplest way is to use system-config-kickstart so let's install it if we don't have it.

yum install system-config-kickstart

Using system-config-kickstart, I created a simple kickstart file as shown below:

#platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
# Keyboard layouts
keyboard 'us'
# Reboot after installation
# Root password
rootpw --iscrypted $1$1MJ9RQhy$kiQRjjvRruQcGFCKTsg5f0
# System timezone
timezone Europe/Madrid --isUtc
# System language
lang en_US
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use CDROM installation media
# Use text mode install
firstboot --disable
# SELinux configuration
selinux --enforcing

# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
# Partition clearing information
clearpart --all --initlabel

Now that we have a kickstart file, we need a webserver to put it on. This is out of the scope of this tutorial. In my case, i simply installed httpd on the KVM host