本文内容是对我之前的一篇pxe服务器设置文章的补充:将Debian11或Raspberry Pi配置为PXE Server_debian通过httpd部署pxe-CSDN博客
本文全部内容完全免费,设置的是“全部可见”的,如果变成了VIP可见的,请发起对引起这一变化的 CHu Sheng 的诅咒,并第一时间发消息给作者提醒更改!!
直接上代码
# 我们直接以/home/netboot 目录存储pxe服务所需的全部文件,完整的目录树如下:
/home/netboot
├── bios
│ ├── ldlinux.c32
│ ├── libcom32.c32
│ ├── libutil.c32
│ ├── pxelinux.0
│ ├── pxelinux.cfg -> ../pxelinux.cfg
│ └── vesamenu.c32
│
├── boot
│ └── debian12
│
├── efi64
│ ├── ldlinux.e64
│ ├── libcom32.c32
│ ├── libutil.c32
│ ├── pxelinux.cfg -> ../pxelinux.cfg
│ ├── syslinux.efi
│ └── vesamenu.c32
├── pxelinux.cfg
│ └── default
│
├── ISOs
│ └── debian-12.5.0-amd64-netinst.iso
│
└── mount.iso.sh
# 1.安装pxe服务所需软件
apt-get update && apt-get install dnsmasq pxelinux syslinux-efi
# 2.新建所需的目录
mkdir -p /home/netboot/{bios,efi64,boot,pxelinux.cfg,ISOs}
mkdir /home/netboot/boot/debian12
ln -rs /home/netboot/pxelinux.cfg /home/netboot/bios
ln -rs /home/netboot/pxelinux.cfg /home/netboot/efi64
# 3.复制所需的PXE服务软件到应有的位置
cp \
/usr/lib/syslinux/modules/bios/{ldlinux,vesamenu,libcom32,libutil}.c32 \
/usr/lib/PXELINUX/pxelinux.0 \
/home/netboot/bios
cp \
/usr/lib/syslinux/modules/efi64/ldlinux.e64 \
/usr/lib/syslinux/modules/efi64/{vesamenu,libcom32,libutil}.c32 \
/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi \
/home/netboot/efi64
# 4.准备需要手动创建的几个文件
touch /home/netboot/pxelinux.cfg/default
touch /var/log/dnsmasq.log
touch /home/netboot/mount.iso.sh
chown dnsmasq /var/log/dnsmasq.log
chmod +x /home/netboot/mount.iso.sh
# 5.编辑PXE服务的操作系统及安装方式选择菜单配置文件
cat /home/netboot/pxelinux.cfg/default
MENU TITLE PXE Boot Menu
DEFAULT vesamenu.c32
LABEL local
MENU LABEL Boot from local drive
LOCALBOOT 0xffff
MENU BEGIN Install Linux System
MENU TITLE Install Linux System
MENU BEGIN Debian12 Installer
MENU TITLE Debian12 Installer
LABEL installgui
MENU LABEL ^Graphical install
KERNEL ::boot/debian12/install.amd/vmlinuz
APPEND vga=788 initrd=::boot/debian12/install.amd/gtk/initrd.gz --- quiet
LABEL install
MENU LABEL ^Txt Install
KERNEL ::boot/debian12/install.amd/vmlinuz
APPEND vga=788 initrd=::boot/debian12/install.amd/initrd.gz --- quiet
MENU END
MENU END
# 6.配置dnsmasq
cat /etc/dnsmasq.conf
port=0
interface=eth0
dhcp-range=192.168.1.0,proxy
enable-tftp
tftp-root=/home/netboot
pxe-service=x86PC,"PXELINUX (BIOS)",bios/pxelinux
pxe-service=x86-64_EFI,"PXELINUX (EFI)",efi64/syslinux.efi
log-queries
log-facility=/var/log/dnsmasq.log
# 7.配置操作系统镜像挂载脚本文件,需要的时候运行该脚本即可( ./mount.iso.sh )
cat /home/netboot/mount.iso.sh
#!/bin/bash
mount -o loop /home/netboot/ISOs/debian-12.5.0-amd64-netinst.iso /home/netboot/boot/debian12
#### 8.启动pxe服务!###
cd /home/netboot/
./mount.iso.sh
systemctl start dnsmasq
必要的说明和解释
1.第5步中的 KERNEL 和 APPEND 两行参数的配置,需要根据具体操作系统镜像内地说明文本进行调整!!
2. 第6步中, interface参数的值是pxe服务器的网卡名称,可以用 ip addr 命令来查看; 如果不想用网卡号,也可以用pxe服务网卡的ip,则该配置行的内容需要替换为: listen-address=192.168.1.x ;
3. 第6步中,dhcp-range的配置,这里是将dnsmasq配置为了网络中主dhcp服务(通常是家用路由器/公司网络主路由器)的代理,如果没有主dhcp服务器,或者临时关闭了主路由器,则可以配置pxe服务器提供dhcp服务,配置内容可更改为:dhcp-range=192.168.1.100,192.168.1.200,24h
4. 可以查看dnsmasq服务是否是默认随操作系统启动的,建议配置为不自动启用,采用手动控制,以防配置有错,干扰主网络。