-
Server Setup
1.1. Install Required Packages
1.2. Create Folder Structure
1.3. TFTP and Proxy DHCP Configuration
1.4. HTTP Configuration
1.5. Samba Configuration
1.6. NFS Configuration -
File Preparation
2.1. Windows
2.2. Windows Additional Files
2.3. Ubuntu
2.4. Ubuntu Preseed (Optional) -
Build iPXE
3.1. Install Required Packages
3.2. Clone Repository
3.3. Modify Source Code (Optional)
3.4. Create Script
3.5. Compile Source Code
3.6. Selection Menu Creation -
Docker
4.1. Install Required Packages
4.2. Adapting to Your Environment
4.3. Using the Container
apt install -y dnsmasq nginx-light samba nfs-kernel-server
mkdir -p /tftpboot/{windows,ubuntu}
Backup the configuration file.
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.old
Overwrite the configuration file.
cat <<EOF > /etc/dnsmasq.conf
# Disable Built-in DNS Server
port=0
# Enable TFTP Server
enable-tftp
# Set TFTP Base Folder
tftp-root=/tftpboot
# Set boot file to x64 machines with UEFI firmware
pxe-service=x86-64_EFI,,ipxe.efi
# Set boot file to x64 machines with BIOS/Legacy firmware
#pxe-service=x86PC,,ipxe.pxe
# Set DHCP Range and Proxy operation mode
dhcp-range=192.168.15.0,proxy
# Enable Logging
log-dhcp
# Set log file
log-facility=/var/log/dnsmasq.log
EOF
Restart the service to apply changes.
systemctl restart dnsmasq
Overwrite the configuration file.
cat <<EOF > /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
#root /var/www/html;
root /tftpboot;
#index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
EOF
Restart the service to apply changes.
systemctl restart nginx
Backup the configuration file.
cp /etc/samba/smb.conf /etc/samba/smb.conf.old
Overwrite the configuration file.
cat <<EOF > /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
map to guest = bad user
guest account = nobody
[windows]
path = /tftpboot/windows
guest ok = yes
read only = yes
browseable = yes
EOF
Restart the service to apply changes.
systemctl restart smbd
Backup the configuration file.
cp /etc/exports /etc/exports.old
Overwrite the configuration file. Change the subnet and mask as needed
cat <<EOF >> /etc/exports
/tftpboot/ubuntu 192.168.15.0/24(ro,no_root_squash,no_subtree_check)
EOF
Export the folder
exportfs -av
Restart the service
systemctl restart nfs-kernel-server
Mount your Windows ISO
mkdir /mnt/cdrom && mount ~/path/to/iso /mnt/cdrom
Copy the content to the HTTP/SMB Folder
cp -rv /mnt/cdrom /tftpboot/windows
Unmount the ISO after copying it's contents
umount /mnt/cdrom
Download wimboot
from ipxe's repository
wget 'https://github.com/ipxe/wimboot/releases/latest/download/wimboot' -o /tftpboot/windows/wimboot
Create the winpeshl.ini
file
cat <<EOF > /tftpboot/windows/winpeshl.ini
[LaunchApp]
AppPath = .\install.bat
EOF
Create the install.bat
file, which contains a script to map our smb share and execute the installer
cat <<EOF > /tftpboot/windows/install.bat
wpeinit
net use i: \\192.168.15.200\windows
i:\setup.exe
EOF
Mount your Ubuntu ISO
mkdir /mnt/cdrom && mount ~/path/to/iso /mnt/cdrom
Copy the content to the HTTP/SMB Folder
cp -rv /mnt/cdrom/. /tftpboot/ubuntu
Unmount the ISO after copying it's contents
umount /mnt/cdrom
This file will set the Locale, Keyboard Layout to Brazilian Portuguese and System Language to English.
cat <<EOF > /tftpboot/ubuntu/preseed/ubuntu.seed
# The values can also be preseeded individually for greater flexibility.
d-i debian-installer/language string en
d-i debian-installer/locale string pt_BR.UTF-8
# Keyboard selection.
d-i keyboard-configuration/xkb-keymap select br
EOF
This repository have the same ipxe.efi compiled binary available, but feel free to build it yourself.
apt install -y git gcc make liblzma-dev
git clone https://github.com/ipxe/ipxe.git ~/ipxe
Enable NFS support, which is usually necessary when booting live USB ISOs.
sed -i 's/#undef\tDOWNLOAD_PROTO_NFS/#define\tDOWNLOAD_PROTO_NFS/' ~/ipxe/src/config/general.h
The following commands are used during ipxe troubleshooting.
Enable ping command support
sed -i 's/\/\/#define\ PING_CMD/#define\ PING_CMD/' ~/ipxe/src/config/general.h
Enable command to show ip information
sed -i 's/\/\/#define\ IPSTAT_CMD/#define\ IPSTAT_CMD/' ~/ipxe/src/config/general.h
Enable Shutdown and Reboot commands inside iPXE CLI
sed -i 's/\/\/#define\ REBOOT_CMD/#define\ REBOOT_CMD/' ~/ipxe/src/config/general.h
sed -i 's/\/\/#define\ POWEROFF/#define\ POWEROFF/' ~/ipxe/src/config/general.h
This script will request the seletion menu to all boot options.
cat <<EOF > ipxe/src/embed.ipxe
#!ipxe
isset ${next-server} || set next-server ${proxydhcp/dhcp-server}
dhcp
chain http://${next-server}/menu.ipxe || shell
EOF
In this case we'll be compiling to x64 machines with UEFI Firmware.
cd ipxe/src/ && make bin-x86_64-efi/ipxe.efi EMBED=embed.ipxe
Read the official documentation for all build targets.
When the build process finish, copy the file the TFTP server folder.
cp ~/ipxe/src/bin-x86_64-efi/ipxe.efi /tftpboot
This menu have entries for Windows, Ubuntu and Boot from Hard Disk.
cat <<EOF > /tftpboot/menu.ipxe
#!ipxe
isset ${menu-default} || set menu-default WinPE
##################################################
:start
menu Welcome to iPXE's Boot Menu
item WinPE Install Windows 10
item Ubuntu Ubuntu Live
item BootHardDisk Boot from Hard Disk
choose --default exit --timeout 15000 target && goto ${target}
##################################################
:WinPE
kernel http://${next-server}/windows/wimboot
initrd http://${next-server}/windows/winpeshl.ini
initrd http://${next-server}/windows/install.bat
initrd http://${next-server}/windows/bootmgr.efi bootmgr.efi
initrd http://${next-server}/windows/efi/boot/bootx64.efi Bootx64.efi
initrd http://${next-server}/windows/boot/bcd BCD
initrd http://${next-server}/windows/boot/boot.sdi boot.sdi
initrd http://${next-server}/windows/sources/boot.wim boot.wim
boot
:Ubuntu
kernel http://${next-server}/ubuntu/casper/vmlinuz
initrd http://${next-server}/ubuntu/casper/initrd
imgargs vmlinuz initrd=initrd root=/dev/nfs boot=casper file=preseed/ubuntu.seed keyboard-configuration/layoutcode=br netboot=nfs nfsroot=${next-server}:/tftpboot/ubuntu ip=dhcp --
boot
:BootHardDisk
exit
goto start
EOF
This repository contains a docker version of the server that can only install Windows.
apt install -y docker.io docker-compose
-
Edit ipxe.efi changing
dhcp-range=192.168.15.0,proxy
line to match your subnet address -
Edit install.bat changing
net use i: \\192.168.15.200\windows
line to match the host machine address
- Mount a single windows ISO to
files/iso
- Build and run the container in background using
docker-compose up -d
- Stop the container using
docker-compose down
- Arch Wiki dnsmasq - PXE Server
- Arch Wiki dnsmasq - Proxy DHCP
- Arch Wiki dnsmasq - TFTP
- iPXE official Build Reference
- rikka0w0's iPXE customization/build guide
- iPXE official Build Targets Reference
- robinsmidsrod's Extensive iPXE Menu Example
- Customizing WinPE
- Adding Drivers to WinPE
- iPXE Official WinPE Menu Entry Reference
- winpeshl.ini Reference
- NFS Configuration Reference
- iPXE Official Live Ubuntu Menu Entry Reference
- Docker Compose cap_add Reference
- All cap_add Options