Giter Site home page Giter Site logo

pxe-server's Introduction

Table of Contents

  1. 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

  2. File Preparation
    2.1. Windows
    2.2. Windows Additional Files
    2.3. Ubuntu
    2.4. Ubuntu Preseed (Optional)

  3. 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

  4. Docker
    4.1. Install Required Packages
    4.2. Adapting to Your Environment
    4.3. Using the Container

  5. References

Server Setup

Install Required Packages

apt install -y dnsmasq nginx-light samba nfs-kernel-server

Create Folder Structure

mkdir -p /tftpboot/{windows,ubuntu}

TFTP and Proxy DHCP Configuration

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

HTTP Configuration

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

Samba Configuration

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

NFS Configuration

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

File Preparation

Windows

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

Windows Additional Files

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

Ubuntu

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

Ubuntu Preseed (Optional)

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

Build iPXE

This repository have the same ipxe.efi compiled binary available, but feel free to build it yourself.

Install Required Packages

apt install -y git gcc make liblzma-dev

Clone Repository

git clone https://github.com/ipxe/ipxe.git ~/ipxe

Modify Source Code (Optional)

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

Create Script

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

Compile Source Code

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

Selection Menu Creation

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

Docker

This repository contains a docker version of the server that can only install Windows.

Install Required Packages

apt install -y docker.io docker-compose

Adapting to Your Environment

  • 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

Using the Container

  • 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

References

pxe-server's People

Contributors

brunowollinger avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.