From 404454e4ed1cdb0e42af6655796891d8d841b329 Mon Sep 17 00:00:00 2001 From: CHUCK <204468377+drainch@users.noreply.github.com> Date: Wed, 23 Apr 2025 05:02:51 -0400 Subject: [PATCH] Add PXE boot configuration and scripts * **PXE boot configuration**: Add `dnsmasq.conf` to configure PXE boot, set TFTP root directory, and configure DHCP options. * **PXE bootloader configuration**: Add `pxelinux.cfg/default` to configure the PXE bootloader and set the bootloader to point to the macOS KVM kernel/initrd. * **Serve PXE boot files**: Add `serve_pxe.sh` script to serve `pxelinux.0`, `vmlinuz`, and `initrd` via TFTP using `dnsmasq`. * **Retrieve internal IP**: Add `get_internal_ip.sh` script to retrieve the internal IP address of the Codespace. * **Update boot script**: Modify `boot-macOS-headless.sh` to use the PXE boot files from the `netboot` directory and add a network boot option to the QEMU command. --- boot-macOS-headless.sh | 2 ++ netboot/dnsmasq.conf | 10 ++++++++++ netboot/get_internal_ip.sh | 5 +++++ netboot/pxelinux.cfg/default | 4 ++++ netboot/serve_pxe.sh | 24 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) mode change 100755 => 100644 boot-macOS-headless.sh create mode 100644 netboot/dnsmasq.conf create mode 100644 netboot/get_internal_ip.sh create mode 100644 netboot/pxelinux.cfg/default create mode 100644 netboot/serve_pxe.sh diff --git a/boot-macOS-headless.sh b/boot-macOS-headless.sh old mode 100755 new mode 100644 index b5ce2e8..d3d938b --- a/boot-macOS-headless.sh +++ b/boot-macOS-headless.sh @@ -67,6 +67,8 @@ args=( -device vmware-svga -display none -vnc 0.0.0.0:1,password=on -k en-us + -netdev user,id=pxenet0,tftp=netboot/tftpboot,bootfile=pxelinux.0 + -device e1000,netdev=pxenet0 ) qemu-system-x86_64 "${args[@]}" diff --git a/netboot/dnsmasq.conf b/netboot/dnsmasq.conf new file mode 100644 index 0000000..86aebff --- /dev/null +++ b/netboot/dnsmasq.conf @@ -0,0 +1,10 @@ +# Configuration for dnsmasq to support PXE boot + +# Set the TFTP root directory +enable-tftp +tftp-root=/tftpboot + +# Configure DHCP options for PXE boot +dhcp-range=192.168.1.100,192.168.1.200,12h +dhcp-boot=pxelinux.0 +pxe-service=x86PC, "Install macOS", pxelinux diff --git a/netboot/get_internal_ip.sh b/netboot/get_internal_ip.sh new file mode 100644 index 0000000..837034d --- /dev/null +++ b/netboot/get_internal_ip.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Script to retrieve the internal IP address of the Codespace + +hostname -I diff --git a/netboot/pxelinux.cfg/default b/netboot/pxelinux.cfg/default new file mode 100644 index 0000000..f28e229 --- /dev/null +++ b/netboot/pxelinux.cfg/default @@ -0,0 +1,4 @@ +DEFAULT macOS +LABEL macOS + KERNEL vmlinuz + APPEND initrd=initrd.img diff --git a/netboot/serve_pxe.sh b/netboot/serve_pxe.sh new file mode 100644 index 0000000..cb42ae6 --- /dev/null +++ b/netboot/serve_pxe.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Serve pxelinux.0, vmlinuz, and initrd via TFTP using dnsmasq + +# Ensure dnsmasq is installed +if ! command -v dnsmasq &> /dev/null +then + echo "dnsmasq could not be found, please install it." + exit +fi + +# Create tftpboot directory if it doesn't exist +TFTPBOOT_DIR="tftpboot" +if [ ! -d "$TFTPBOOT_DIR" ]; then + mkdir -p "$TFTPBOOT_DIR" +fi + +# Copy necessary files to tftpboot directory +cp pxelinux.0 "$TFTPBOOT_DIR/" +cp vmlinuz "$TFTPBOOT_DIR/" +cp initrd.img "$TFTPBOOT_DIR/" + +# Start dnsmasq to serve PXE boot files +dnsmasq --conf-file=netboot/dnsmasq.conf