Ubuntu 18.04/20.04 Preseed+Packer部署磁盘格式化卡滞问题求助
解决Packer部署Ubuntu 18.04/20.04时的Preseed配置问题
我之前在使用Packer配合preseed自动化部署Ubuntu服务器镜像时,也遇到过几乎一模一样的问题,咱们针对性来解决:
问题1:Ubuntu 18.04卡在"Confirm destructive action"弹窗循环选No
这个问题的核心是你缺少了确认删除磁盘所有现有分区的preseed参数。安装程序在执行自动分区前会弹出确认销毁磁盘数据的弹窗,而你的配置里没有自动确认这个操作的指令,导致默认选"No",陷入循环。
需要在boot_command中添加以下行:
" d-i partman/confirm_delete_all boolean true<wait>",
另外,建议把partman-auto/init_automatically_partition从biggest_free改为guided,更适配18.04 live-server的安装流程:
" d-i partman-auto/init_automatically_partition select guided<wait>",
问题2:Ubuntu 20.04卡在"Guided Storage Configuration"界面
Ubuntu 20.04 Server使用了全新的Subiquity安装器,不再兼容旧的debian-installer(d-*)系列参数,这是你卡住的关键原因。你需要改用Subiquity的autoinstall配置方式:
调整boot_command开头
替换原来的d-i auto-install/enable boolean true为Subiquity的自动安装启动参数:
"autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<wait>",
添加Subiquity专属的存储配置参数
在boot_command中添加存储配置的JSON(直接嵌入到preseed参数里),同时添加确认指令:
" subiquity/storage/config string {\"layout\": {\"name\": \"direct\"}, \"swap\": {\"size\": 0}}<wait>", " subiquity/storage/confirm boolean true<wait>",
另外,20.04的很多原d-i参数需要替换为Subiquity版本,比如:
- 替换
d-i debconf/priority select critical为subiquity/debconf/priority select critical - 替换
d-i passwd/root-login boolean true为subiquity/root-login boolean true - 替换
d-i passwd/root-password-crypted password !!为subiquity/root-password-crypted password !!
完整可用的Packer配置示例
适配Ubuntu 18.04的配置片段
{ "builders": [ { "type": "vsphere-iso", "vcenter_server": "{{user `vsphere_server`}}", "username": "{{user `vsphere_username`}}", "password": "{{user `vsphere_password`}}", "insecure_connection": "true", "vm_name": "T-ubuntu-1804", "datastore": "{{user `vsphere_datastore`}}", "folder": "{{user `vsphere_folder`}}", "host": "{{user `vsphere_host`}}", "convert_to_template": "true", "network": "{{user `vsphere_network`}}", "boot_order": "disk,cdrom", "guest_os_type": "ubuntu64Guest", "CPUs": 1, "RAM": 2048, "RAM_reserve_all": false, "disk_controller_type": "pvscsi", "disk_size": 80000, "disk_thin_provisioned": false, "network_card": "vmxnet3", "ssh_username": "{{user `ssh_username`}}", "ssh_password": "{{user `ssh_password`}}", "iso_paths": ["[datastore1] ISO/Linux/ubuntu-18.04.4-live-server-amd64.iso"], "boot_command": [ " d-i auto-install/enable boolean true<wait>", " d-i debconf/priority select critical<wait>", " d-i debian-installer/locale string en_US.UTF-8<wait>", " d-i localechooser/supported-locales multiselect en_US.UTF-8<wait>", " d-i console-setup/ask_detect boolean false<wait>", " d-i keyboard-configuration/xkb-keymap select GB<wait>", " d-i /choose_interface select auto<wait>", " d-i netcfg/get_hostname string unassigned-hostname<wait>", " d-i netcfg/get_domain string unassigned-domain<wait>", " d-i hw-detect/load_firmware boolean true<wait>", " d-i mirror/country string manual<wait>", " d-i mirror/http/hostname string archive.ubuntu.com<wait>", " d-i mirror/http/directory string /ubuntu<wait>", " d-i mirror/http/proxy string<wait>", " d-i passwd/root-login boolean true<wait>", " d-i passwd/root-password-crypted password !!<wait>", " d-i passwd/make-user boolean false<wait>", " d-i clock-setup/utc boolean true<wait>", " d-i time/zone string UTC<wait>", " d-i clock-setup/ntp boolean true<wait>", " d-i clock-setup/ntp-server string ntp.ubuntu.com<wait>", " d-i preseed/early_command string umount /media || true<wait>", " d-i grub-installer/only_debian boolean true<wait>", " d-i grub-installer/with_other_os boolean true<wait>", " d-i partman-efi/non_efi_system boolean true<wait>", " d-i partman-auto/disk string /dev/sda<wait>", " d-i partman-auto/init_automatically_partition select guided<wait>", " d-i partman-auto/method string regular<wait>", " d-i partman-auto/choose_recipe select atomic<wait>", " d-i partman/confirm_write_new_label boolean true<wait>", " d-i partman/choose_partition select finish<wait>", " d-i partman/confirm boolean true<wait>", " d-i partman/confirm_nooverwrite boolean true<wait>", " d-i partman/confirm_delete_all boolean true<wait>", " d-i partman-auto/confirm boolean true<wait>", " d-i base-installer/install-recommends boolean true<wait>", " d-i base-installer/kernel/image string linux-generic<wait>", " d-i debconf debconf/frontend select Noninteractive<wait>", " d-i apt-setup/restricted boolean true<wait>", " d-i apt-setup/universe boolean true<wait>", " d-i apt-setup/backports boolean true<wait>", " d-i apt-setup/use_mirror boolean false<wait>", " d-i apt-setup/services-select multiselect security, updates<wait>", " d-i apt-setup/security_host string security.ubuntu.com<wait>", " d-i apt-setup/security_path string /ubuntu<wait>", " d-i tasksel/first multiselect none<wait>", " d-i pkgsel/include string openssh-server vim git tmux build-essential open-vm-tools telnet wget curl python<wait>", " d-i pkgsel/upgrade select full-upgrade<wait>", " d-i pkgsel/update-policy select unattended-upgrades<wait>", " d-i debian-installer/splash boolean false<wait>", " d-i cdrom-detect/eject boolean true<wait>", " d-i finish-install/reboot_in_progress note<wait>", " d-i debian-installer/exit/poweroff boolean true<wait>" ] } ], "provisioners": [ { "type": "shell", "inline": ["echo 'Template build complete'"] } ] }
适配Ubuntu 20.04的配置片段
{ "builders": [ { "type": "vsphere-iso", "vcenter_server": "{{user `vsphere_server`}}", "username": "{{user `vsphere_username`}}", "password": "{{user `vsphere_password`}}", "insecure_connection": "true", "vm_name": "T-ubuntu-2004", "datastore": "{{user `vsphere_datastore`}}", "folder": "{{user `vsphere_folder`}}", "host": "{{user `vsphere_host`}}", "convert_to_template": "true", "network": "{{user `vsphere_network`}}", "boot_order": "disk,cdrom", "guest_os_type": "ubuntu64Guest", "CPUs": 1, "RAM": 2048, "RAM_reserve_all": false, "disk_controller_type": "pvscsi", "disk_size": 80000, "disk_thin_provisioned": false, "network_card": "vmxnet3", "ssh_username": "{{user `ssh_username`}}", "ssh_password": "{{user `ssh_password`}}", "iso_paths": ["[datastore1] ISO/Linux/ubuntu-20.04.6-live-server-amd64.iso"], "boot_command": [ "autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<wait>", " subiquity/debconf/priority select critical<wait>", " subiquity/locale string en_US.UTF-8<wait>", " console-setup/ask_detect boolean false<wait>", " keyboard-configuration/xkb-keymap select GB<wait>", " netcfg/get_hostname string unassigned-hostname<wait>", " netcfg/get_domain string unassigned-domain<wait>", " mirror/country string manual<wait>", " mirror/http/hostname string archive.ubuntu.com<wait>", " mirror/http/directory string /ubuntu<wait>", " mirror/http/proxy string<wait>", " subiquity/root-login boolean true<wait>", " subiquity/root-password-crypted password !!<wait>", " subiquity/make-user boolean false<wait>", " clock-setup/utc boolean true<wait>", " time/zone string UTC<wait>", " subiquity/ntp boolean true<wait>", " subiquity/ntp-server string ntp.ubuntu.com<wait>", " subiquity/early-command string umount /media || true<wait>", " subiquity/storage/config string {\"layout\": {\"name\": \"direct\"}, \"swap\": {\"size\": 0}}<wait>", " subiquity/storage/confirm boolean true<wait>", " grub-installer/only_debian boolean true<wait>", " grub-installer/with_other_os boolean true<wait>", " base-installer/install-recommends boolean true<wait>", " base-installer/kernel/image string linux-generic<wait>", " debconf debconf/frontend select Noninteractive<wait>", " apt-setup/restricted boolean true<wait>", " apt-setup/universe boolean true<wait>", " apt-setup/backports boolean true<wait>", " apt-setup/use_mirror boolean false<wait>", " apt-setup/services-select multiselect security, updates<wait>", " apt-setup/security_host string security.ubuntu.com<wait>", " apt-setup/security_path string /ubuntu<wait>", " tasksel/first multiselect none<wait>", " pkgsel/include string openssh-server vim git tmux build-essential open-vm-tools telnet wget curl python3<wait>", " pkgsel/upgrade select full-upgrade<wait>", " pkgsel/update-policy select unattended-upgrades<wait>", " subiquity/splash boolean false<wait>", " cdrom-detect/eject boolean true<wait>", " finish-install/reboot_in_progress note<wait>", " subiquity/exit/poweroff boolean true<wait>" ] } ], "provisioners": [ { "type": "shell", "inline": ["echo 'Template build complete'"] } ] }
关键遗漏的配置项总结
- Ubuntu 18.04:缺少
d-i partman/confirm_delete_all boolean true,这是自动确认销毁磁盘现有数据的核心参数;同时建议将partman-auto/init_automatically_partition改为guided更适配live-server流程。 - Ubuntu 20.04:没有适配Subiquity安装器,需要替换旧的
d-i参数为subiquity-*前缀的参数,添加autoinstall启动参数,以及用JSON格式配置存储并确认。
内容的提问来源于stack exchange,提问作者chris3389
相关产品推荐
相关产品推荐

