Create KVM image and auto-install Debian

Prerequisites

#!/bin/bash

_host=test01
_domain=server.lan

_mac0=00:16:3e:ff:ff:ff

##################################################

_vg=vg01
_disk="/dev/${_vg}/guest_${_host}"

# create disk (logical volume)
if [ ! -f "$_disk" ] ; then
  sudo lvcreate --size 50G --name guest_${_host} ${_vg}
fi

# create image and install
sudo virt-install \
  --name=$_host \
  --ram=4096 \
  --vcpus=4 \
  --os-type=linux  \
  --os-variant=debianwheezy \
  --cpu host \
  --graphics none \
  --network bridge=br1,model=virtio,mac=$_mac0 \
  --location=http://d-i.server.lan:8080/debian/packages/dists/jessie/main/installer-amd64/ \
  --disk path=${_disk},cache=none,bus=virtio,format=raw \
  --hvm  \
  --virt-type kvm \
  --connect qemu:///system \
  --extra-args="console=ttyS0,115200 \
    auto=true \
    interface=eth0 \
    hostname=$_host \
    domain=$_domain \
    netcfg/get_ipaddress=$(dig +short $_host.$_domain) \
    netcfg/get_netmask=255.255.255.0 \
    netcfg/get_gateway=$(dig +short $_host.$_domain | cut -d"." -f1-3).1 \
    netcfg/get_nameservers=$(dig $(dig $_domain ns +short) +short) \
    netcfg/disable_dhcp=true \
    url=http://d-i.server.lan:8080/preseed/preseed.cfg"