温馨提示×

如何自定义Ubuntu Cobbler的安装界面

小樊
33
2025-12-21 04:45:54
栏目: 智能运维

Ubuntu 环境下自定义 Cobbler 安装界面

一 核心思路

  • 定制 PXE 菜单与引导界面:修改 /etc/cobbler/pxe/pxelinux.cfg/default/var/lib/cobbler/loaders/ 下的引导文件(如 pxelinux.0、menu.c32),即可改变 PXE 启动菜单的样式、标题与默认项。
  • 定制安装过程界面:为 Ubuntu 使用 preseed(debian-installer 自动应答) 文件,通过 kickstart 的 preseed 指令或 Cobbler 的 –autoinstall 关联到对应的 profile/system,从而控制语言、键盘、分区、用户、软件源与安装后脚本等界面与行为。

二 准备与目录结构

  • 安装与基础配置:在 Ubuntu 上安装 cobbler cobbler-web dhcp3-server tftpd-hpa xinetd,启动 cobblerd、httpd、tftp,执行 cobbler check 并按提示修正(如设置 server/next_server、启用 TFTP、加载 boot-loaders)。
  • 关键目录与模板:
    • 引导与菜单:/var/lib/cobbler/loaders//etc/cobbler/pxe/pxelinux.cfg/default
    • Kickstart/Preseed:/var/lib/cobbler/kickstarts/
    • 镜像与仓库:/var/www/cobbler/ks_mirror//var/www/cobbler/repo_mirror
    • 配置模板:/etc/cobbler/settings/etc/cobbler/dhcp.template
  • 导入镜像与生成 distro/profile(示例):
    • 挂载 ISO 后导入:cobbler import --path=/mnt/ubuntu-22.04 --name=ubuntu-22.04
    • 查看与关联:cobbler distro listcobbler profile list;将自定义 preseed/ks 关联到相应 profile

三 自定义 PXE 启动菜单界面

  • 准备引导文件:确保 /var/lib/cobbler/loaders/ 包含 pxelinux.0、menu.c32 等(可通过安装 syslinux 并拷贝,或运行 cobbler get-loaders 获取)。
  • 编辑 PXE 菜单(示例):
    • 文件路径:/etc/cobbler/pxe/pxelinux.cfg/default
    • 示例内容(可自定义 MENU TITLE、颜色、默认项与超时):
      DEFAULT menu.c32
      PROMPT 0
      TIMEOUT 200
      MENU TITLE Cobbler Ubuntu PXE Menu
      LABEL local
        MENU LABEL Boot from local disk
        LOCALBOOT 0
      
      LABEL install-ubuntu-22.04
        MENU LABEL Install Ubuntu 22.04 (Auto)
        KERNEL ubuntu-22.04-x86_64/vmlinuz
        APPEND initrd=ubuntu-22.04-x86_64/initrd.gz ksdevice=bootif lang=en_US url=http://$next_server/cblr/svc/op/ks/system/$name autoinstall
      
    • 说明:
      • 使用 menu.c32 可显示彩色菜单;通过 TIMEOUTDEFAULT 控制等待与默认选择。
      • $next_server$name 等为 Cobbler 内置变量;ksdevice=bootif 便于按引导网卡安装。
  • 使配置生效:cobbler sync(每次修改 PXE/模板后需同步到 TFTP/HTTP)。

四 自定义 Ubuntu 安装界面与流程

  • 准备 preseed 文件(示例要点,保存为 /var/lib/cobbler/kickstarts/ubuntu-22.04.seed):
    d-i debian-installer/locale string en_US.UTF-8
    d-i keyboard-configuration/xkb-keymap select us
    d-i netcfg/choose_interface select auto
    d-i netcfg/get_hostname string ubuntu-host
    d-i netcfg/get_domain string localdomain
    d-i mirror/country string manual
    d-i mirror/http/hostname string $http_server
    d-i mirror/http/directory string /cobbler/ks_mirror/ubuntu-22.04/
    d-i mirror/http/proxy string
    
    d-i partman-auto/method string regular
    d-i partman-auto/choose_recipe select atomic
    d-i partman-partitioning/confirm_write_new_label boolean true
    d-i partman/choose_partition select finish
    d-i partman/confirm boolean true
    d-i partman/confirm_nooverwrite boolean true
    
    d-i passwd/user-fullname string Ubuntu User
    d-i passwd/username string ubuntu
    d-i passwd/user-password-crypted password $1$salt$hashedpassword   # 用 openssl passwd -1 生成
    d-i passwd/root-login boolean false
    d-i user-setup/allow-password-weak boolean true
    d-i user-setup/encrypt-home boolean false
    
    d-i pkgsel/include string openssh-server vim
    d-i pkgsel/upgrade select none
    d-i pkgsel/language-packs multiselect
    
    d-i clock-setup/utc boolean true
    d-i time/zone string Asia/Shanghai
    d-i clock-setup/ntp boolean true
    
    d-i preseed/late_command string \
      in-target sh -c 'echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/ubuntu && chmod 440 /etc/sudoers.d/ubuntu'
    
    d-i finish-install/reboot_in_progress note
    
  • 将 preseed 关联到 profile(两种方式,二选一或并用):
    • 方式 A(推荐,通过 kickstart 的 preseed 指令):
      cobbler profile edit \
        --name=ubuntu-22.04-x86_64 \
        --kickstart=/var/lib/cobbler/kickstarts/ubuntu-22.04.seed \
        --autoinstall=/var/lib/cobbler/kickstarts/ubuntu-22.04.seed
      
    • 方式 B(直接新建一个使用 preseed 的 profile):
      cobbler profile add \
        --name=ubuntu-22.04-auto \
        --distro=ubuntu-22.04-x86_64 \
        --kickstart=/var/lib/cobbler/kickstarts/ubuntu-22.04.seed \
        --autoinstall=/var/lib/cobbler/kickstarts/ubuntu-22.04.seed
      
  • 同步并测试:cobbler sync,从 PXE 选择对应菜单项启动安装。

五 验证与排错

  • 基础健康检查:cobbler check;确保 /etc/cobbler/settingsserver/next_server 正确、TFTP 已启用、引导文件就位。
  • 查看服务与日志:systemctl status cobblerd httpd tftpd-hpa;日志位于 /var/log/cobbler/(如 cobbler.log、install.log),便于定位菜单或 preseed 阶段的问题。
  • 变更生效:每次修改 PXE 菜单/模板/ks/preseed 后执行 cobbler sync,必要时重启相关服务。

0