Set up a debian pxe server with grub - cesetxeberria/pxeserver GitHub Wiki

Download debian netinst iso, burn it to a cd or a usb and install. Just the minimal install will suffice.

As root user install dnsmasq grub-pc and grub-efi-amd64-signed.

apt-get install dnsmasq grub-pc grub-efi-amd64-signed

Create a new folder for the tftp-root and grub.

mkdir -p /home/tftp/grub

Copy needed files. We use 'grub-mkimage' command to create custom grub images with some data from the server. This is mandatory because we are using a dhcp proxy server and grub doesn't get all the necessary info.

grub-mknetdir --net-directory=/home/tftp --subdir=/grub
grub-mkimage -d /usr/lib/grub/i386-pc/ -O i386-pc-pxe -o /home/tftp/grub/booti386.0 -p '(tftp,192.168.1.54)/grub' pxe tftp
grub-mkimage -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi -o /home/tftp/grub/bootx64.efi -p '(tftp,192.168.1.54)/grub' efinet tftp

192.168.1.54 is just an example, must be replaced with your own ip address.

Create a simple "Hello world" file for the menu.

nano /home/tftp/grub/grub.cfg

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set timeout=5

menuentry "Hello" {
   echo "Hello world"
}

Create new file /etc/dnsmasq.d/custom

nano /etc/dnsmasq.d/custom

interface=eth0
bind-dynamic
dhcp-range=192.168.1.54,proxy
enable-tftp
tftp-root=/home/tftp
pxe-service=x86PC, "grub bios", grub/booti386.0
pxe-service=x86-64_efi, "grub efi", grub/bootx64.efi

'eht0' in the first line and '192.168.1.54' in the third one are just examples. Must be filled with your own interface name and network address. You can get your interface name with

ip -o link | grep "state UP" | awk '{print substr($2, 1, length($2)-1)}'

And your network address with

ip route show | grep src | awk '{print substr($1, 1, length($1)-3)}'

Restart dnsmasq

systemctl restart dnsmasq

Now you can try to pxe boot your client. You shoud see this screen