这篇文章上次修改于 282 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

74060631_p0.jpg
这里接着上一篇的说,会用到之前的 Dnsmasq 和 Lighttpd 服务。

iPXE 是 PXE 的一个开源 Bootloader,于 2010 年作为 gPXE 的分支创建,可在X86 AMD64 ARM 等架构下运行,不挑网卡,兼容 UEFI,广泛的协议支持。

What does the "i" in "iPXE" stand for?

It doesn't.

from Frequently asked questions

编译 iPXE

官方的预编译版本没有提供 HTTPS 支持,需要自行编译。
如果不需要添加功能,直接下载使用官方提供的预编译版本
注意 BIOS/UEFI 有些功能不能相互兼容,编译会报错,如启用 IMAGE_EFI 再去编译 BIOS 固件便会报错。

下载源码

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

修改配置文件

vim src/config/general.h

定位到第57行,将#undef改为#define

#define DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */

编译 undionly.kpxe,用于BIOS方式启动

cd src
make bin/undionly.kpxe

编译 ipxe.efi,用于UEFI方式启动

make bin-x86_64-efi/ipxe.efi

Choosing what to build

完成后将 undionly.kpxeipxe.efi 复制到路由器的 TFTP 文件夹

启动后如图

配置 Dnsmasq

 vim /etc/dnsmasq.conf

注释到 PXELINUX 代码,添加如下内容

# Tag dhcp request from iPXE
dhcp-match=set:ipxe,175

# inspect the vendor class string and tag BIOS client
dhcp-vendorclass=BIOS,PXEClient:Arch:00000

enable-tftp
tftp-root=/mnt/sda1/pxe/

# BIOS iPXE
dhcp-boot=tag:!ipxe,tag:BIOS,ipxe/undionly.kpxe

# UEFI iPXE
dhcp-boot=tag:!ipxe,tag:!BIOS,ipxe/ipxe.efi

# iPXE BOOT MENU
dhcp-boot=tag:ipxe,ipxe/config/boot.ipxe

启动菜单

cd /mnt/sda1/pxe/ipxe
mkdir config && cd config
vim boot.ipxe

Hello World

#!ipxe

:start
menu PXE Boot Options
# 菜单的title
item --key s shell (S)iPXE shell
item --key r reboot    (R)reboot
# 菜单显示的条目

choose --default shell --timeout 5000 option && goto ${option}
# 启动菜单 5000ms 后自动选择 shell 条目

:shell 
shell

:reboot
reboot
# 每个条目对应的功能

一个简单配置文件结构,提供 iPXE Shell 和重启功能

Hello World

Debian NetBoot

item --key d debian_netboot    (D)debian buster netboot


:debian_netboot
echo Booting Debian 10 64-bit netboot
set url https://mirrors.aliyun.com/debian/dists/buster/main/installer-amd64/current/images/netboot/debian-installer/amd64/
kernel ${url}linux initrd=initrd.gz
initrd ${url}initrd.gz
boot || goto start
# 如果启动失败自动返回 MENU

同 PXELINUX 的方法直接使用 Mirror 的 HTTPS 源,实现NetBoot。

chain

item --key a alpine_ipxe (A)Alpine iPXE Netboot
item --key e archLinux_uefi (E)ArchLinux UEFI Netboot
item --key n netboot_xyz (N)boot.netboot.xyz


:alpine_ipxe
echo Booting Alpine iPXE netboot
chain boot_alpine.ipxe
# chain https://boot.alpinelinux.org/boot.ipxe

:archLinux_uefi
echo Booting ArchLinux iPXE netboot
chain ../tools/archlinux.efi

:netboot_xyz
echo Booting boot.bootnet.xyz script
chain --autofree https://boot.netboot.xyz

chain 命令可以下载并启动执行文件。

Download and boot an executable image

MEMDISK

item --key m maxdos (M)MAXDOS
item --key m winpe_32 (3)Windows PE legacy version


:winpe_32
set boot-url http://${net0/gateway}
# 获取网关(路由器)地址,方便通过 HTTP 下载镜像
initrd ${boot-url}/iso/winpe.iso
chain ${boot-url}/iso/memdisk iso raw

:maxdos
iseq ${builtin/platform} pcbios || goto start
set boot-url http://${net0/gateway}
initrd ${boot-url}/iso/MAXDOS.IMG
chain ${boot-url}/iso/memdisk

可以直接引导 ISO 镜像,只支持 legacy(BIOS) 模式启动。

memdisk 文件可以在 SYSLINUX 中取得。

Booting Memtest

Windows PE

item --key w boot_wepe (W)Windows PE 


:boot_winpe
iseq ${builtin/platform} efi || goto start
# 非 UEFI 模式自动返回 MENU
set boot-url http://${net0/gateway}
kernel ${boot-url}/iso/wimboot
initrd ${boot-url}/iso/BOOTPE/bootmgr.efi             bootmgr.efi
initrd ${boot-url}/iso/BOOTPE/boot/boot.sdi                boot.sdi
initrd ${boot-url}/iso/BOOTPE/sources/boot.wim            boot.wim
boot

通过 wimboot 启动 Windows PE 镜像,文件下载点这里

这里使用的无垠 PE 制作的 Win8PE64网络版.iso ,将其解压到 HTTP 服务目录下的 iso/BOOTPE 里。

由于无垠 PE 修改了 BCD 文件,无法在 BIOS 模式下用 wimboot 启动,BIOS 启动部分建议使用 MEMDISK。

Network-booting Windows PE

之后的计划

  • Linux NFS/HTTP LiveCD
  • Windows iSCSI 无盘启动
  • Linux 和 Windows 自动部署

边学边记,希望不咕...🤣

参考和链接

iPXE - open source boot firmware

ipxe-scripts

netboot.xyz

一步步搭建PXE网络装机

Introducing netboot.xyz Docker Network Boot Server Image (PXE)

[VLOG | 全网首发菲佣级PXE打造无盘系统ESXI配合群晖ISCSI安装教程-古老的黑科技

iPXE - open source boot firmware