我正在使用 为 Ubuntu Server 20.04 设置无人值守安装packer
。但是,尽管我autoinstall
在 中指定了boot_command
,安装程序总是要求我确认(我需要手动输入“是”-在屏幕截图中间):
这显然违背了“无人值守安装”的概念,但我无法弄清楚问题出在哪里。我在下面发布了boot_command
我正在使用的两个不同的系统,并在帖子末尾发布了我的完整配置。
两个启动命令都会生成一个有效的安装,但仍需要确认。启动命令 1:
boot_command = ["<enter><wait2><enter><wait><f6><esc><wait>", "autoinstall<wait2> ds=nocloud;", "<wait><enter>"]
启动命令2:
"boot_command": [
"<enter><wait2><enter><wait><f6><esc><wait>",
"linux /casper/vmlinuz autoinstall ds=nocloud;",
"<wait><enter>",
"initrd /casper/initrd",
"<wait><enter>",
"boot"
],
完整配置:./ubuntu2004.pkr.hcl:
source "virtualbox-iso" "autogenerated_1" {
boot_command = ["<enter><wait2><enter><wait><f6><esc><wait>", "autoinstall<wait2> ds=nocloud;", "<wait><enter>"]
boot_wait = "2s"
cd_files = ["./http/user-data", "./http/meta-data"]
cd_label = "cidata"
disk_size = 8192
guest_additions_path = "VBoxGuestAdditions_{{ .Version }}.iso"
guest_os_type = "Ubuntu_64"
headless = false
http_directory = "http"
iso_checksum = "sha256:f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98"
iso_urls = ["https://releases.ubuntu.com/focal/ubuntu-20.04.3-live-server-amd64.iso"]
shutdown_command = "echo 'ubuntu'|sudo -S shutdown -P now"
ssh_agent_auth = true
ssh_handshake_attempts = "200"
ssh_private_key_file = "/home/asdf/.ssh/virtual_id_ed25519"
ssh_username = "vagrant"
ssh_wait_timeout = "10000s"
vboxmanage = [["modifyvm", "{{ .Name }}", "--memory", "1024"], ["modifyvm", "{{ .Name }}", "--cpus", "1"]]
virtualbox_version_file = ".vbox_version"
vm_name = "packer-ubuntu-20.04-amd64"
}
build {
sources = ["source.virtualbox-iso.autogenerated_1"]
provisioner "shell" {
scripts = ["scripts/init.sh"]
}
provisioner "shell" {
scripts = ["scripts/cleanup.sh"]
}
post-processor "vagrant" {
compression_level = "8"
output = "ubuntu-20.04-test.box"
}
}
./http/用户数据:
#cloud-config
autoinstall:
version: 1
locale: en_US
keyboard:
layout: en
variant: us
network:
network:
version: 2
ethernets:
enp0s3:
dhcp4: true
storage:
layout:
name: lvm
ssh:
install-server: yes
user-data:
users:
- name: vagrant
ssh_authorized_keys:
- ssh-ed25519 REDACTED
sudo: ALL=(ALL) NOPASSWD:ALL
groups: [adm, sudo]
lock_passwd: true
shell: /bin/bash
packages:
- openssh-server
- build-essential
late-commands:
- echo 'vagrant ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/vagrant
答案1
我遇到了同样的问题,并在控制台上注意到 Packer 在安装程序准备好之前输入了“yes”(安装程序在 200 秒后暂停,但 boot_wait 设置为 180)。我增加了“boot_wait”值来纠正这个问题(见下文)。还显示了两个额外的超时设置,您可能需要(或不需要)调整它们:
boot_wait =“300秒”
ip_wait_timeout =“20米”
ssh_timeout=“30米”