Nutanix环境下使用Packer自动化创建Debian 11模板的预配置(preseed)技术咨询
我目前正在尝试通过Packer在Nutanix环境中自动化创建Debian 11模板,现在需要一些关于预配置(preseed)/自动化Debian安装的建议。
背景与已完成的工作
首先,我参考了Debian的官方文档后,决定使用preseed.cfg文件来实现自动化安装。我从Debian提供的示例preseed.cfg开始,根据自己的需求做了修改,最后用debconf-set-selections -c preseed.cfg命令验证了语法,结果一切正常。
预配置文件的使用方式选择
我了解到使用preseed.cfg有三种不同的方式:
- 通过initrd:对我来说难度较高,没找到简单的教程/文档
- 通过网络:因为防火墙限制,目前不是可行选项
- 通过文件:看起来是目前最简单、最合适的选项
遇到的问题
当Packer启动VM创建时,会把Debian ISO加载为第一光驱,空虚拟磁盘作为第二存储。我让Packer把我的preseed.cfg脚本加载为光驱,从hypervisor角度看,这是挂载在第三位置的第二光驱。但问题是,VM从第一位置的ISO启动后,并没有自动挂载包含preseed.cfg的第二光驱,除非我进入Debian控制台手动挂载,否则无法访问这个文件。
尝试的方法与疑问
我在论坛上看到一种方法:把preseed.cfg上传到原始debian.iso的文件夹中,修改/isolinux/txt.cfg文件如下,然后用OSCDIMG重新生成ISO:
label install menu label ^Install kernel /install.amd/vmlinuz append vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed/preseed.cfg --- quiet
我想问问大家,这种做法是否合理?有没有什么我没考虑到的点,或者更简单的实现方法?
后续尝试与编辑内容
EDIT:(原未标注日期)
我尝试了initrd方法,现在只剩一个问题:必须手动选择“Automated Install”,有没有办法取消这个手动操作?
EDIT2:2023年01月02日
我又试了两种方法:
- 在
isolinux/txt.cfg里的append行加上auto=true priority=critical,变成:
append auto=true priority=critical vga=788 initrd=/install.amd/initrd.gz preseed/file=/cdrom/preseed.cfg --- quiet
结果还是停在启动菜单(不过如果我手动选择自动化安装,预配置文件能正常工作,说明preseed.cfg本身没问题)
2. 测试修改isolinux.cfg为prompt 1 timeout 1,结果直接跳转到手动选择语言的步骤...
EDIT3:2023年01月03日
下面是我使用的preseed.cfg配置:
# SETUP AUTO MODE d-i auto-install/enable boolean true d-i debconf/priority select critical # LANGUAGE & KEYMAP d-i debian-installer/locale string fr_FR d-i keyboard-configuration/xkb-keymap select fr(latin9) # NETWORK d-i netcfg/choose_interface select auto d-i netcfg/get_hostname string template-debian-11-x64 d-i netcfg/get_domain string my_domain.net d-i netcfg/hostname string template-debian-11-x64 # MIRRORS d-i mirror/http/hostname string http://deb.debian.org/debian/ d-i mirror/http/hostname string http://security.debian.org/debian-security # ACCOUNTS d-i passwd/root-password password mypassword! d-i passwd/root-password-again password mypassword! d-i passwd/user-fullname string user d-i passwd/username string user d-i passwd/user-password password mypassword! d-i passwd/user-password-again password mypassword! d-i passwd/user-uid string 1010 d-i passwd/user-default-groups string si audio cdrom video # LVM PART d-i partman-auto/disk string /dev/sda d-i partman-auto/method string lvm d-i partman-auto-lvm/guided_size string 95% d-i partman-lvm/device_remove_lvm boolean true d-i partman-md/device_remove_md boolean true d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm_nooverwrite boolean true d-i partman-auto/choose_recipe select multi 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 #APT d-i apt-setup/cdrom/set-first boolean false tasksel tasksel/first multiselect standard, ssh-server # GRUB d-i grub-installer/bootdev string /dev/sda d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true #FINAL d-i finish-install/reboot_in_progress note
非常感谢大家的帮助!
Gael
备注:内容来源于stack exchange,提问作者motorbass

