下面给你一个从原理到落地的说明,讲清楚 如何把 PXE 启动与 Debian + Cobbler 集成,适合做自动化装机环境。
PXE + Cobbler 的关系:
客户端 (PXE)
↓
DHCP (分配 IP + 指向 TFTP)
↓
TFTP (pxelinux.0 / grub)
↓
Cobbler (提供 kickstart / preseed + 镜像)
↓
HTTP/FTP/NFS (系统安装源)
Cobbler 本身不是 PXE 服务,它只是:
apt update
apt install cobbler cobbler-web tftp tftp-hpa xinetd \
dhcp-server apache2 -y
Debian 下 Cobbler 依赖
tftpd-hpa,不要用atftpd
vi /etc/cobbler/settings.yaml
关键项:
server: 192.168.1.10
next_server: 192.168.1.10
manage_dhcp: true
manage_tftpd: true
systemctl enable --now cobblerd
systemctl enable --now apache2
systemctl enable --now tftpd-hpa
cobbler check
cobbler sync
编辑:
/etc/cobbler/dhcp.template
示例:
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 192.168.1.1;
range 192.168.1.100 192.168.1.200;
filename "pxelinux.0";
next-server 192.168.1.10;
}
应用:
cobbler sync
mount -o loop debian-12-amd64-DVD-1.iso /mnt
cobbler import \
--name=debian12 \
--arch=x86_64 \
--path=/mnt
完成后:
cobbler distro list
/var/lib/cobbler/preseed/debian12.seed
示例(简化):
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/get_hostname string debian
d-i mirror/country string manual
d-i mirror/http/hostname string 192.168.1.10
d-i mirror/http/directory string /cobbler/ks_mirror/debian12
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i passwd/root-password password cobbler
d-i passwd/root-password-again password cobbler
d-i grub-installer/bootdev string /dev/sda
cobbler profile edit \
--name=debian12-x86_64 \
--kickstart=/var/lib/cobbler/preseed/debian12.seed
pxelinux.0如果是 UEFI:
cobbler profile edit --name=debian12-x86_64 \
--boot-loader=grub
Cobbler 会自动生成:
/var/lib/tftpboot/grub/grub.cfg
tftpd-hpa 是否运行cobbler sync
ls /var/www/cobbler/ks_mirror/
preseed 中明确指定:
d-i netcfg/choose_interface select eth0
PXE 负责“启动”,Cobbler 负责“管理”,Debian 用 preseed 实现全自动安装。
如果你愿意,我可以:
你现在是做 实验室 / 生产环境 / 云镜像 哪种?