Cobbler v3.3.7 配置 Ubuntu 24.04 无人值守安装,我踩过的那些坑(附完整脚本)

张开发
2026/5/29 23:22:49 15 分钟阅读
Cobbler v3.3.7 配置 Ubuntu 24.04 无人值守安装,我踩过的那些坑(附完整脚本)
Cobbler v3.3.7 配置 Ubuntu 24.04 无人值守安装我踩过的那些坑附完整脚本当我在生产环境中首次尝试用Cobbler v3.3.7部署Ubuntu 24.04时原本以为两小时能搞定的任务最终花了整整两天。这篇文章记录了我遇到的所有坑以及如何填平它们的过程。如果你正在寻找一份经过实战检验的配置指南特别是那些官方文档没提到的细节问题这里就是你要的答案。1. 环境准备阶段的隐藏陷阱很多人会直接跳过这个部分但恰恰是基础配置中的小细节会导致后续连环故障。我的Cobbler服务器运行在CentOS Stream 9上这个组合本身就有几个需要注意的兼容性问题。首先千万不要直接使用yum install cobbler安装的版本。官方仓库的3.3.7版本缺少对Ubuntu 24.04的必要支持文件。我推荐用以下方式获取完整包wget https://cobbler.github.io/rpm/cobbler-3.3.7-1.el9.noarch.rpm rpm -ivh cobbler-3.3.7-1.el9.noarch.rpm --nodeps安装后立即检查/var/lib/cobbler/distro_signatures.json文件这是第一个大坑。原始文件里根本没有Noble NumbatUbuntu 24.04代号的签名定义。我后来发现即使运行cobbler signature update也无法自动添加新版本支持。提示修改distro_signatures.json前一定要备份错误的JSON格式会导致整个Cobbler服务崩溃。2. 签名文件的手工补全艺术Ubuntu 24.04的签名定义需要手工添加到JSON文件中。经过多次尝试我总结出最稳定的配置方案noble: { signatures: [dists,.disk], version_file: Release|info, version_file_regex: Suite: noble|Ubuntu 24.04, kernel_arch: linux-headers-(.*)\\.deb, supported_arches: [i386,amd64], supported_repo_breeds: [apt], kernel_file: (linux|vmlinuz(.*)), initrd_file: initrd($|.gz$|.lz$), isolinux_ok: false, default_autoinstall: , kernel_options: autoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile, template_files: }关键点在于kernel_options的配置这与Ubuntu 22.04有显著不同。如果沿用旧参数会导致安装程序无法获取autoinstall配置。3. cloud-init配置的版本适配难题Ubuntu 24.04的cloud-init配置语法发生了重大变化。直接使用22.04的模板会导致安装卡在分区阶段。经过反复测试这是最终可用的cloud-init_user-data模板#cloud-config autoinstall: version: 1 refresh-installer: update: yes apt: disable_components: [] geoip: true preserve_sources_list: false primary: - arches: [amd64] uri: http://$http_server/cblr/links/$distro identity: hostname: $hostname password: $default_password_crypted realname: Ubuntu User username: ubuntu kernel: package: linux-generic locale: en_US.UTF-8 network: version: 2 ethernets: eth0: dhcp4: true ssh: allow-pw: true authorized-keys: [] install-server: true storage: config: - type: disk id: disk-sda match: size: largest ptable: gpt wipe: superblock - type: partition id: partition-0 device: disk-sda size: 1G flag: boot - type: partition id: partition-1 device: disk-sda size: -1 user-data: disable_root: false特别注意storage部分的配置变化24.04不再支持旧的layout: lvm简写方式必须明确指定分区方案。4. PXE引导参数的致命细节这是最折磨我的部分。Ubuntu 24.04的安装内核参数必须包含特定指令才能正确触发无人值守安装cobbler profile edit --name Ubuntu24-casper-x86_64 \ --kernel-optionsautoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile常见的几个错误配置表现缺少autoinstall参数安装程序会进入交互界面dsnocloud-net格式错误无法加载cloud-init配置URL路径错误表现为安装卡在Loading autoinstall data阶段我编写了一个自动修复脚本会在每次cobbler sync后检查PXE配置#!/bin/bash # /var/lib/cobbler/triggers/sync/post/fix_ubuntu24_pxe.sh for profile in $(cobbler profile list); do distro$(cobbler profile report --name $profile | awk /^Distribution/ {print $3}) version$(cobbler distro report --name $distro | awk /OS Version/ {print $4}) if [[ $version noble ]]; then sed -i /^menu default/d /var/lib/tftpboot/pxelinux.cfg/default sed -i s|append initrd.*|append initrd/images/Ubuntu24/initrd.gz autoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile|g /var/lib/tftpboot/pxelinux.cfg/default fi done5. 离线安装的特别处理如果需要在无外网环境部署必须修改apt配置并预下载依赖包。这是我的解决方案首先在profile配置中添加离线标记cobbler profile edit --name Ubuntu24-casper-x86_64 --koptsautoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile net.ifnames0 biosdevname0然后修改autoinstall模板的apt部分apt: disable_components: [] geoip: false preserve_sources_list: true primary: - arches: [amd64] uri: http://$http_server/cblr/repo_mirror/Ubuntu24创建本地镜像仓库mkdir -p /var/www/cobbler/repo_mirror/Ubuntu24 debootstrap --archamd64 noble /var/www/cobbler/repo_mirror/Ubuntu24 http://archive.ubuntu.com/ubuntu6. 实战检验过的完整脚本以下是我最终使用的全自动配置脚本包含所有关键步骤和错误处理#!/bin/bash # cobbler_ubuntu24_autoinstall.sh COBBLER_IP192.168.1.100 # 修改为你的Cobbler服务器IP ISO_PATH/iso/ubuntu-24.04-live-server-amd64.iso # 1. 准备Cobbler环境 yum install -y debootstrap pykickstart # 2. 添加Ubuntu 24.04签名 cat EOF /var/lib/cobbler/distro_signatures.json noble: { signatures: [dists,.disk], version_file: Release|info, version_file_regex: Suite: noble|Ubuntu 24.04, kernel_arch: linux-headers-(.*)\\.deb, supported_arches: [i386,amd64], supported_repo_breeds: [apt], kernel_file: (linux|vmlinuz(.*)), initrd_file: initrd($|.gz$|.lz$), isolinux_ok: false, default_autoinstall: , kernel_options: autoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile, template_files: } EOF # 3. 挂载ISO并导入 mkdir -p /mnt/ubuntu24 mount -o loop $ISO_PATH /mnt/ubuntu24 cobbler import --nameUbuntu24 --path/mnt/ubuntu24 --archx86_64 # 4. 配置profile cobbler profile edit --nameUbuntu24-x86_64 \ --autoinstall/var/lib/cobbler/templates/cloud-init_user-data \ --kernel-optionsautoinstall dsnocloud-net;shttp://$COBBLER_IP/cblr/svc/op/autoinstall/profile/\$profile # 5. 创建修复触发器 cat EOF /var/lib/cobbler/triggers/sync/post/fix_ubuntu24_pxe.sh #!/bin/bash for p in $(cobbler profile list); do distro$(cobbler profile report --name $p | awk /^Distribution/ {print $3}) version$(cobbler distro report --name $distro | awk /OS Version/ {print $4}) [[ $version noble ]] || continue sed -i s|append initrd.*|append initrd/images/$distro/initrd.gz autoinstall dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile|g /var/lib/tftpboot/pxelinux.cfg/default done EOF chmod x /var/lib/cobbler/triggers/sync/post/fix_ubuntu24_pxe.sh # 6. 重启服务 systemctl restart cobblerd httpd cobbler sync7. 排错技巧与日志分析当安装失败时按这个顺序检查PXE阶段问题检查/var/log/httpd/error_log和/var/lib/tftpboot/pxelinux.cfg/default文件内容内核加载问题在客户端按Shift键进入GRUB菜单编辑启动参数添加consolettyS0,115200n8获取串口输出autoinstall失败在客户端启动时添加dsnocloud-net;shttp://$server/cblr/svc/op/autoinstall/profile/$profile debug参数cloud-init问题安装完成后检查/var/log/cloud-init-output.log和/var/log/cloud-init.log最常见的三个错误及解决方案No such file or directory when loading initrd原因distro的initrd路径配置错误修复cobbler distro edit --nameUbuntu24-x86_64 --initrd/images/Ubuntu24/initrd.gzAutoinstall configuration not found原因URL路径拼写错误或web服务无权限修复检查/etc/cobbler/settings中的autoinstall_templates_dir权限Failed to load autoinstall config原因cloud-init模板语法错误修复使用yamllint检查模板文件特别注意缩进和冒号后的空格

更多文章