Cobbler如何管理Debian镜像
小樊
45
2025-12-18 02:08:09
Cobbler管理Debian镜像的完整流程
一 环境准备与基础配置
- 安装必要组件(Debian/Ubuntu 系):apt-get install cobbler cobbler-web tftpd-hpa xinetd,启动服务后执行 cobbler check 进行自检。若提示缺少网络引导文件,运行 cobbler get-loaders 下载;若提示未安装 debmirror,安装它以支持 Debian 仓库镜像管理。配置 /etc/cobbler/settings:将 server 与 next_server 设为 Cobbler 服务器地址,按需开启 manage_dhcp / manage_dns;DHCP 模板 /etc/cobbler/dhcp.template 中设置子网、地址池、网关、DNS 与 next-server;TFTP 由 xinetd 托管,确保 /var/lib/tftpboot 可达;完成后执行 cobbler sync 使配置生效。
二 导入Debian安装镜像
- 挂载官方 Debian ISO(DVD1)并导入:mount -o loop /path/to/debian-12.iso /mnt;cobbler import --name debian12.11 --path /mnt。导入后会自动创建 Distro 与 Profile,可直接用于 PXE 引导与安装。注意:DVD 中的 installer initrd 并非为 PXE 网络安装准备,后续需替换为 netboot 引导文件。
三 配置PXE网络引导
- 下载 netboot initrd.gz(以 amd64 为例):wget -O /root/debian12.11-netboot.gz https://mirrors.ustc.edu.cn/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz;将官方 DVD 中的 installer initrd 与 netboot initrd 拼接,生成新的 PXE 用 initrd:cat /var/www/cobbler/distro_mirror/debian12.11/install.amd/initrd.gz /root/debian12.11-netboot.gz > /var/www/cobbler/pub/debian12.11-netboot.gz;在 Cobbler 中更新 Distro 使用该 initrd:cobbler distro edit --name debian12.11-x86_64 --initrd “/var/www/cobbler/pub/debian12.11-netboot.gz”;最后执行 cobbler sync 使 PXE 配置生效。
四 自动化安装与镜像源配置
- 准备 Preseed(Seed) 文件(示例路径:/var/lib/cobbler/templates/bookworm-workaround.seed),关键项包括:语言与键盘(如 en_US、us)、root 密码(明文或哈希)、网络自动获取(netcfg/choose_interface=auto)、安装器镜像源(mirror/http/hostname 与 directory 指向国内镜像,如 mirrors.tuna.tsinghua.edu.cn/debian)、APT 源(security、updates、bookworm main 等)、时区(Asia/Shanghai)、分区(示例为 LVM atomic)、GRUB 安装、软件包选择(如 standard、ssh-server)与安装后命令(如允许 root 登录)。将 Seed 绑定到 Profile:cobbler profile edit --name debian12.11-x86_64 --autoinstall ‘bookworm-workaround.seed’;每次修改后执行 cobbler sync。客户端设置为 PXE 启动即可无人值守安装。
五 常用管理与维护命令
- 镜像与配置:cobbler distro list / cobbler profile list;cobbler distro edit/remove;cobbler profile edit --name --autoinstall ;cobbler system add --name --profile --mac --ip --gateway --hostname ;cobbler system edit --name --netboot-enabled true;变更后 cobbler sync。仓库镜像(可选):安装 debmirror 并配置 /etc/debmirror.conf(如注释 @dists/@arches 以适配所需发行版与架构),用于管理 Debian 软件仓库镜像,便于内网离线安装与更新。