kvm/qemu pxe boot setup on fedora.

kvm support disk less booting of operating systems over network, kvm default network can be configured to act a pxe server.

packages required to setup pxe boot, tfp is a udp based file sharing service used to push the required files for pxe boor, /var/lib/tftpboot will be directory for tftp server.
we need to copy syslinux files to this location by creating a directory called pxelinux.

As the vm boot up with option from network boot , it will be able to fetch intial files required to boot from pxelinux.0 , installation files of iso can be fetched from http , nfs , or ftp over network.

i am running http server to provide files for installation

for creating a grub menu, create a directory pxelinux.cfg with file default

cat default 
default vesamenu.c32
prompt 1
timeout 600

display boot.msg

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://192.168.122.1/centos7/
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img xdriver=vesa nomodeset
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel memtest
  append -
# sudo cp /usr/share/syslinux /var/lib/tftpboot/pxelinux/
here is the contents of /var/lib/tftpboot/pxelinux/
#
 tree  -d /var/lib/tftpboot/pxelinux/
/var/lib/tftpboot/pxelinux/
├── com32
│   └── include
│       ├── bitsize
│       ├── bitsize32
│       ├── bitsize64
│       ├── gplinclude
│       │   ├── acpi
│       │   ├── disk
│       │   ├── dmi
│       │   ├── vpd
│       │   └── zzjson
│       ├── hw
│       ├── klibc
│       │   ├── i386
│       │   └── x86_64
│       ├── linux
│       ├── netinet
│       ├── sys
│       │   ├── i386
│       │   └── x86_64
│       └── syslinux
├── diag
├── dosutil
└── pxelinux.cfg
# dnf install syslinux-tftpboot syslinux-devel syslinux-common tftpd 

After the packages are installed , enable and run tfp service.

#systemctl start tftp
#systemctl enable tftp

here is my default network xml file configured for pxe install.

# virsh net-dumpxml default 
<network>
  <name>default</name>
  <uuid>cdaebe20-c72d-4434-932e-58e00de5e837</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:d9:5b:b9'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
      <host mac='52:54:00:d8:a0:f4' name='centosext' ip='192.168.122.11'/>
      <host mac='52:54:00:2d:07:d3' name='centosext1' ip='192.168.122.22'/>
      <host mac='52:54:00:17:1a:99' name='centosext2' ip='192.168.122.33'/>
      <host mac='52:54:00:7b:f9:f3' name='centosext3' ip='192.168.122.44'/>
      <host mac='52:54:00:df:5f:2f' name='centosext4' ip='192.168.122.55'/>
      <host mac='52:54:00:d8:a0:f4' name='centosext5' ip='192.168.122.66'/>
      <host mac='52:54:00:82:18:49' name='chefnode1' ip='192.168.122.77'/>
      <host mac='52:54:00:8d:10:87' name='chefnode2' ip='192.168.122.88'/>
      <host mac='52:54:00:c6:41:eb' name='chefnode3' ip='192.168.122.99'/>
      <host mac='52:54:00:7a:73:a0' name='chefnode4' ip='192.168.122.111'/>
      <bootp file='/pxelinux/pxelinux.0' server='192.168.122.1'/>
    </dhcp>
  </ip>
</network>

Setting up a lvm partition for the new vm,

#sudo virsh vol-create-as  store pxe1 10G 
Vol pxe1 created

Lets install os from pxe, after executing the below virt-install command , connect from any vnc client on host ip address port 5900

#virt-install --name pxe1 --ram 512 --disk path=/dev/store/pxe1 --vcpus 2  --pxe --os-type linux --os-variant rhel7 --network network=default  --graphics  vnc,listen=0.0.0.0   --accelerate

Starting install...