Domain Creation

A domain is really the virtual machine. Creating a new domain is just one simple command. virt-install. It takes a lot of parameters though, it is adviseable to read the virt-install manpage.

Creating

Use the following script to create your domains.

createdomain.sh

   1 #!/bin/sh
   2 NAME="stretch-template"
   3 RAM="1024"
   4 LVM_SIZE="4G"
   5 LVM_GROUP="vg2"
   6 GRAPHICS_PROTOCOL="spice" #spice, vnc
   7 OS="debian9"
   8 MEDIA="/mnt/media/debian/stretch/debian-9.1.0-amd64-netinst.iso"
   9 
  10 if [ $# -eq 0 ]
  11 then
  12         echo "${0}: domain-name"
  13 else
  14         NAME=${1}
  15 fi
  16 LVM_NAME="kvm_${NAME}_vda"
  17 
  18 if [ ! -e /dev/${LVM_GROUP}/${LVM_NAME} ]
  19 then
  20 
  21         # create lvm partition
  22         lvcreate --size ${LVM_SIZE} --name ${LVM_NAME} ${LVM_GROUP}
  23 
  24         # create the virtual machine
  25         virt-install --name ${NAME} --memory ${RAM} --disk /dev/${LVM_GROUP}/${LVM_NAME},bus=virtio,format=raw --os-variant ${OS} --network bridge=br0,model=virtio --cdrom ${MEDIA} --graphics ${GRAPHICS_PROTOCOL},listen=192.168.1.33,password=${NAME} --noautoconsole --virt-type kvm
  26 else
  27         echo "${0}: refusing to overwrite existing domain"
  28 fi

Parameters

--name

Give the domain its name. This name is used byt the virsh software as a reference to the domain.

--memory

The amount of memory for the domain. Setting a high value to make the istallation run smoother can be a good idea. It is possible to lower the memory later on.

--disk

The place where the domain has its virtual disk. Here it is an lvm volume using the raw format, but other formats can be used.

--os-variant

Determines the OS running in the domain.

--network

Configure the network interface.

--cdrom

Set the installation media.

--graphics

Configure the guest console.

--noautoconsole

Do not try to connect to the guest console, just start the domain.

--virt-type

Set the hypervisor.