The article shows how to setup Ubuntu on KVM using PXE boot
Since we`ll use DHCP server from qemu-kvm - no need to install additional one. Start with installation of tftpd-hpa and apache2:
sudo apt-get install tftpd-hpa apache2
Check that tftpd-hpa listens on UDP 69:
netstat -antpu | grep 69
The default directory for tftpd-hpa is /var/lib/tftpboot/, if you want to change this - make changes in /etc/default/tftpd-hpa, corresponding parameter is TFTP_DIRECTORY
Download Ubuntu installation iso image and mount it:
sudo mount -o loop ubuntu-16.04.5-server-amd64.iso /mnt/iso
Copy boot installation files to tftpd-hpa default directory:
cd /mnt/iso
sudo cp -fr install/netboot/* /var/lib/tftpboot/
Make "ubuntu" folder under apache default folder, which is /var/www/html:
sudo mkdir /var/www/html/ubuntu
Copy rest of installation file to /var/www/html/ubuntu:
sudo cp -fr ./* /var/www/html/ubuntu/
Add following to /var/lib/tftpboot/pxelinux.cfg/default (where 172.18.194.239 is the IP address of our PXE server):
label linux
kernel ubuntu-installer/amd64/linux
append ks=http://172.18.194.239/ubuntu/ks.cfg vga=normal initrd=ubuntu-installer/amd64/initrd.gz \
kernel ubuntu-installer/amd64/linux
append ks=http://172.18.194.239/ubuntu/ks.cfg vga=normal initrd=ubuntu-installer/amd64/initrd.gz \
ramdisk_size=16432 root=/dev/rd/0 rw --
Change KVM network config by adding following line to DHCP settings (the command is virsh net-edit <NETWORK_NAME>):
<bootp file='pxelinux.0' server='172.18.194.239'/>
After this issue commands:
virsh net-destroy <NETWORK_NAME>
virsh net-start <NETWORK_NAME>
The example of network config:
<network>
<name>default</name>
<uuid>f93b1d19-b850-474a-a736-5a3973618404</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:e3:32:60'/>
<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.0' server='172.18.194.239'/>
</dhcp>
</ip>
</network>
<name>default</name>
<uuid>f93b1d19-b850-474a-a736-5a3973618404</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:e3:32:60'/>
<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.0' server='172.18.194.239'/>
</dhcp>
</ip>
</network>
Prepare kickstart file and place it under /var/www/html/ubuntu/ks.cfg
Create new KVM guest machine using PXE boot:
Check for bootp packets using tcpdump:
tcpdump -nei ens7 \(port 67 or port 68\)