Initial commit

This commit is contained in:
S David 2023-09-25 16:11:22 -04:00
commit ef6836a188
8 changed files with 258 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
netboot/*.efi
netboot/*.lkrn
netboot/*.kpxe
netboot/*.pxe
netboot/images/*

25
LICENSE Normal file
View File

@ -0,0 +1,25 @@
Applies to configuration files and autoexec.ipxe script.
Copyright © 2023 Saul D. Beniquez
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

95
README.md Normal file
View File

@ -0,0 +1,95 @@
# PXE Boot Configuration Repository
This Git repository contains configuration files and scripts for setting up PXE boot using DNSMasq, Lighttpd, TFTP-HPA, and Netboot.xyz. This is meant to run on FreeBSD systems but can be adapted to work with Linux or any UNIX that can run Dnsmasq as a proxying DHCP server.
Configuration is done using FreeBSD's `rc.conf` for network booting. Please follow the instructions below to set up your PXE boot environment.
## Table of Contents
- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Repository Contents](#repository-contents)
- [Configuration](#configuration)
- [Usage](#usage)
- [License](#license)
## Introduction
PXE (Preboot eXecution Environment) booting allows you to boot and install operating systems over the network. This repository provides a streamlined configuration for setting up a server providing PXE boot service using netboot.xyz, using DNSMasq and TFTP-HPA on a FreeBSD system. Additionally, it includes configurations for the `rc.conf` file to enable network booting on FreeBSD.
To ensure compliance with GPL licenses, this repository does not include iPXE and Netboot.xyz binaries. Instead, a shell script is provided that can download these binaries for you.
## Prerequisites
Before you begin, ensure you have the following prerequisites:
- A FreeBSD system (tested on FreeBSD 13.2)
- dnsmasq and optionally tftpd-hpa
- Storage for your PXE-boot binaries
- Administrative privileges on the FreeBSD system
- Internet connectivity on the FreeBSD system
- A network segment for PXE boot clients
## Repository Contents
- **etc/dnsmaqs-dhcp.conf**: DNSMasq configuration file for DHCP and TFTP boot.
- **etc/rc.conf.local**: Example `rc.conf` file for enabling network booting on FreeBSD.
- **download-ipxe-netboot.sh**: Shell script to download iPXE and Netboot.xyz binaries.
## Prerequisites
1. Clone this Git repository to your FreeBSD system:
```shell
git clone https://github.com/yourusername/pxe-boot-config.git
```
2. Install the following packages `dnsmasq` , `tftpd-hpa`
```shell
pkg install dnsmasq tftp
# optional:
pkg install ipxe
# go to /usr/local/share/ipxe for ipxe binaries
```
3. Copy the `netboot` folder in this configuration to `/netboot` or elsewhere. If you choose elsewhere, be sure to modify the files under `etc` to have the correct referneces.
4. Deploy the following configuration files at `/usr/local/etc` or `/etc/`
- **/usr/local/etc/dnsmaqs-dhcp.conf**: Update DHCP settings and paths as needed.
- **/etc/rc.conf.local**: (FreeBSD only) Configure daemons and services required
## Usage
Follow these steps to set up PXE booting on your FreeBSD system:
1. Install dependencies and set up the configuration files as described in the [Prerequisites](#prerequisites) section.
2. Run the `download-ipxe-netboot.sh` script to download iPXE and Netboot.xyz binaries. This script will fetch the necessary binaries and place them in the appropriate directories.
```shell
./download-ipxe-netboot.sh
```
3. Start and enable the DNSMasq and TFTP services:
```shell
sudo service dnsmasq enable
sudo service dnsmasq start
# Optional: You may use the dnsmasq-provided tftp server if you cannot use tftpd-hpa. Modify dnsmasq.conf accordingly
sudo service tftpd enable
sudo service tftpd start
```
4. Ensure that your PXE boot clients are configured to boot from the network. Refer to your client's BIOS/UEFI settings for PXE boot options.
5. Boot your PXE clients and follow your chosen OS installation process.
## License
This repository is provided under the [BSD 2-Clause](LICENSE). Specifically, the downloader script, the documentation, and the `autoexec.ipxe` file.
Please note that the iPXE and Netboot.xyz binaries are subject to their respective GPL licenses.
To avoid GPL violations, the `download-ipxe-netboot.sh` script is provided to fetch these binaries directly from their official sources, or proivde your own substitutions.
Please review the licenses of iPXE and Netboot.xyz before using this repository in production environments.

44
etc/dnsmasq.conf Normal file
View File

@ -0,0 +1,44 @@
# Disable DNS Server
port=0
# Enable DHCP logging
log-dhcp
# Respond to PXE requests for the specified network;
# run as DHCP proxy
dhcp-range=192.168.1.0,proxy
# Set certain "tags" so dnsmasq can respond differently to different pxe clients
# iPXE sends a 175 option.
dhcp-match=set:ipxe-http,175,19
dhcp-match=set:ipxe-https,175,20
dhcp-match=set:ipxe-menu,175,39
# pcbios specific
dhcp-match=set:ipxe-pxe,175,33
dhcp-match=set:ipxe-bzimage,175,24
dhcp-match=set:ipxe-iscsi,175,17
# efi specific
dhcp-match=set:ipxe-efi,175,36
# combination
# set ipxe-ok tag if we have correct combination
# http && menu && iscsi ((pxe && bzimage) || efi)
tag-if=set:ipxe-bios,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-pxe,tag:ipxe-bzimage
tag-if=set:ipxe-efi,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-efi
#PC BIOS Support
pxe-service=tag:!ipxe-bios,X86PC,PXE,undionly.kpxe
#pxe-service=tag:!ipxe-bios,X86PC,PXE,ipxe.pxe
pxe-service=tag:ipxe-bios,X86PC,PXE,autoexec.ipxe
# EFI Varieties
#pxe-service=tag:!ipxe-efi,IA32_EFI,PXE,snponlyx32.efi
#pxe-service=tag:!ipxe-efi,BC_EFI,PXE,snponly.efi
pxe-service=tag:!ipxe-efi,X86-64_EFI,PXE,ipxe.efi
#enable-tftp
#tftp-no-fail
#tftp-root=/netboot
#tftp-unique-root
interface=re0

10
etc/lighttpd-pxe.conf Normal file
View File

@ -0,0 +1,10 @@
server.pid-file ="/var/run/lighttpd_pxe.pid"
server.document-root = "/netboot"
server.follow-symlink = "enable"
server.bind = "0.0.0.0"
$SERVER["socket"] == "[::]:6080" { }
server.port = 6080
dir-listing.activate = "enable"

10
etc/rc.conf.local Normal file
View File

@ -0,0 +1,10 @@
lighttpd_enable="YES"
lighttpd_instances="pxe"
lighttpd_pxe_conf="/usr/local/etc/lighttpd-pxe.conf"
# for PXE boots
dnsmasq_enable="YES"
tftpd_enable="YES"
tftpd_flags="-v -l -s -u nobody -p /netboot"

47
netboot/autoexec.ipxe Normal file
View File

@ -0,0 +1,47 @@
#!ipxe
# vim: set ft=sh :
set server_name host0
set my_http http://${server_name}:6080
set netboot_url http://boot.netboot.xyz
echo =======================================
echo ::::. Begin autoexec.ipxe script! .::::
echo =======================================
echo
sleep 1
echo Querying DHCP
:retry_dhcp
dhcp net0 || goto retry_dhcp
isset ${dns} || goto retry_dhcp
echo net0/ip: ${net0/ip}
echo dns: ${dns}
echo gateway: ${gateway}
echo
iseq ${platform} efi && goto is_efi || goto not_efi
:is_efi
echo Loading UEFI netboot.xyz
sleep 2
#|| chain --autofree ${netboot_url}
chain --autofree ${my_http}/images/netboot.xyz.efi || goto failed
:not_efi
echo Loading PCBIOS netboot.xyz
sleep 2
chain --autofree ${my_http}/images/netboot.xyz.kpxe || goto failed
:failed
echo
echo ================================
echo .:::: !! Netboot failure!! ::::.
echo ================================
echo
sleep 5
prompt Press any key to drop to iPXE shell...
shell

View File

@ -0,0 +1,20 @@
#!/bin/sh
# Copyright © 2023 Saul D. Beniquez
# License: BSD 2-Clause
downloader=fetch
if [ "$(uname -a)" -eq "Linux" ]; then
downloader=wget
fi
$downloader https://boot.ipxe.org/ipxe.pxe
$downloader https://boot.ipxe.org/ipxe.efi
$downloader https://boot.netboot.xyz/ipxe/netboot.xyz.kpxe
$downloader https://boot.netboot.xyz/ipxe/netboot.xyz.efi
mv netboot.xyz.* images/
# vim: ts=8 sts=0 noet sw=8 :