Thu, April 5, 2018 ยท 2 min read

kvm/qemu pxe boot setup on fedora.

pxe http server

kvm/qemu pxe boot setup on fedora.

KVM supports diskless booting of operating systems over a network, kvm default network can be configured to act as a pxe server.

Packages required to set up pxe boot: tftp is a UDP based file sharing service used to push the required files for pxe boot. /var/lib/tftpboot will be a directory for tftp server. We need to copy syslinux files to this location by creating a directory called pxelinux.

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

I am running http server to provide files for installation.

pxe http server

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/
dnf install syslinux-tftpboot syslinux-devel syslinux-common tftpd

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

systemctl start tftp
systemctl enable tftp

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'/>
      <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

Install OS from pxe:

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

pxe boot menu

pxe installation