Skip to content

Instantly share code, notes, and snippets.

@jo-makar
Last active May 28, 2024 17:42
Show Gist options
  • Save jo-makar/6332a89d2fd034a39aa5b3e619950888 to your computer and use it in GitHub Desktop.
Save jo-makar/6332a89d2fd034a39aa5b3e619950888 to your computer and use it in GitHub Desktop.
Setup a PXE boot server

Setup a PXE boot server

Using dnsmasq (on Debian)

apt-get install dnsmasq pxelinux syslinux-common syslinux-efi

mkdir /srv/tftpboot

ln -s /usr/lib/PXELINUX/pxelinux.0 /srv/tftpboot/
ln -s /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /srv/tftpboot/

for f in ldlinux.c32 libutil.c32 menu.c32; do
    ln -s /usr/lib/syslinux/modules/bios/$f /srv/tftpboot/
done

mkdir /srv/tftpboot/pxelinux.cfg

/etc/dnsmasq.d/pxeboot

Remember to replace the specified subnet in the dhcp-range line

# Disable the dns function
port=0

# Log extra info on dhcp transactions
log-dhcp

# Handle pxe boot requests (as a dhcp proxy) for the specified subnet
dhcp-range=10.0.0.0,proxy

dhcp-boot=pxelinux.0
pxe-service=x86PC,"pxelinux",pxelinux

enable-tftp
tftp-root=/srv/tftproot

Unfortunately efi pxe boot does not work with dnsmasq's dhcp proxy mode (nor does ISC dhcpd support a proxy mode). So currently efi pxe boot would require a dedicated network without a dhcp server and dnsmasq in non-proxy mode. If this gets fixed in a future version of dnsmasq, replace the preceding dhcp-boot, pxe-service lines with the following:

dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:efi-x86_64,option:client-arch,9
dhcp-boot=tag:bios,pxelinux.0
dhcp-boot=tag:efi-x86_64,syslinux.efi
pxe-service=x86PC,"pxelinux",pxelinux
pxe-service=X86-64_EFI,"syslinux.efi",syslinux.efi

/srv/tftpboot/pxelinux.cfg/default

ui menu.c32
timeout 50

Can set a default label (defined in the next sections) with default

Ref: https://wiki.syslinux.org/wiki/index.php?title=Config

Memtest86+

mkdir /srv/tftpboot/memtest
cd /srv/tftpboot/memtest
curl -O http://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz
gunzip memtest86+-5.01.bin.gz

/srv/tftpboot/pxelinux.cfg/default entry

label memtest
    menu label memtest86+
    linux memtest/memtest86+-5.01.bin

CentOS 7

mkdir /srv/tftpboot/centos7
cd /srv/tftpboot/centos7
mount -o loop CentOS-7-x86_64-Minimal-1810.iso /mnt/loop
cp /mnt/loop/images/pxeboot/{initrd.gz,vmlinuz} .
umount /mnt/loop

/srv/tftpboot/pxelinux.cfg/default entry

Remember to replace the ip in the inst.repo and inst.vncconnect options

label centos7
    menu label centos 7 vnc
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img inst.repo=http://10.0.0.115 inst.vnc inst.vncconnect=10.0.0.115:5500

label centos7-console
    menu label centos 7 vnc (console=ttyS0)
    kernel centos7/vmlinuz
    append initrd=centos7/initrd.img console=ttyS0,115200 inst.repo=http://10.0.0.115 inst.vnc inst.vncconnect=10.0.0.115:5500

Host the iso contents as specified by inst.repo (or set to a public mirror, eg http://mirror.centos.org/centos/7/os/x86_64/)

mount -o loop CentOS-7-x86_64-Minimal-1810.iso /mnt/loop
cd /mnt/loop && python3 -m http.server 80
# When done of course: umount /mnt/loop

The vnc connect mode options are described at: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-vnc-installations-anaconda-modes

Alternatively can use kickstarter to automate the installation

Debian 10

mkdir /srv/tftpboot/debian10
cd /srv/tftpboot/debian10
curl -O http://ftp.debian.org/debian/dists/buster/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xvf netboot.tar.gz ./debian-installer
mv debian-installer debian10

curl -O https://www.debian.org/releases/stable/example-preseed.txt
mv example-preseed.txt preseed.cfg.orig
cp preseed.cfg.orig preseed.cfg
# Modify preseed.cfg as needed, the network console settings in particular are useful

/srv/tftpboot/pxelinux.cfg/default entry

Remember to replace the ip in the preseed/url and md5 in the preseed/url/checksum options

label debian10
  menu label debian 10 automated
  kernel debian10/amd64/linux
  append initrd=debian10/amd64/initrd.gz auto=true priority=critical interface=auto netcfg/link_wait_timeout=10 netcfg/dhcp_timeout=30 preseed/url=tftp://10.0.0.115/debian10/preseed.cfg preseed/url/checksum=93e9ffdc388a07dec05c684dbf074fe3

The installation paramters are described in the preseed.cfg.orig file and at http://hands.com/d-i/. Note that the network console supports (continuing) the installation over ssh.

Clonezilla

mkdir /srv/tftpboot/clonezilla
cd /srv/tftpboot/clonezilla
mount -o loop clonezilla-live-2.6.1-25-amd64.iso /mnt/loop
cp /mnt/loop/images/{initrd.img,filesystem.squashfs,vmlinuz} .
umount /mnt/loop

/srv/tftpboot/pxelinux.cfg/default entry

Remember to replace the ip in the fetch option

label clonezilla
  menu label clonezilla
  kernel clonezilla/vmlinuz
  append initrd=clonezilla/initrd.img boot=live username=user union=overlay config components quiet noswap edd=on nomodeset nodmraid locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch=no net.ifnames=0 nosplash noprompt fetch=tftp://10.0.0.115/clonezilla/filesystem.squashfs

Ref: https://clonezilla.org/livepxe.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment