gpt4 book ai didi

ubuntu - Ubuntu VirtualBox 的 Packer 创建无法关闭

转载 作者:行者123 更新时间:2023-12-04 19:17:41 25 4
gpt4 key购买 nike

我正在尝试创建一个 Ubuntu VirtualBox使用 Packer .

VirtualBox 创建良好,但 Packer 无法将其关闭并提示

==> virtualbox: Gracefully halting virtual machine...
virtualbox: bash:  sudo: command not found
==> virtualbox: Timeout while waiting for machine to shut down.

如果我在出现上述消息时手动登录正在构建的 VirtualBox,我可以使用 sudoshutdown没有问题。

重现问题的最小 Packer 配置是
{
"variables": {
"ssh_name": "ubuntu",
"ssh_pass": "ubuntu",
"host_name": "tahr"
},
"builders": [{
"name": "virtualbox",
"type": "virtualbox-iso",
"guest_os_type": "Ubuntu_64",
"vboxmanage": [
["modifyvm","{{.Name}}","--vram","32"]
],
"disk_size": 10000,
"iso_url": "http://releases.ubuntu.com/trusty/ubuntu-14.04.3-server-amd64.iso",
"iso_checksum": "0501c446929f713eb162ae2088d8dc8b6426224a",
"iso_checksum_type": "sha1",
"http_directory": "virtualbox",
"http_port_min": "9001",
"http_port_max": "9001",
"ssh_username": "{{user `ssh_name`}}",
"ssh_password": "{{user `ssh_pass`}}",
"ssh_pty" : "true",
"ssh_wait_timeout": "15m",
"shutdown_command": "echo {{user `ssh_pass`}} | sudo -S shutdown -P now",
"boot_command": [
"<esc><esc><enter><wait>",
"/install/vmlinuz noapic ",
"preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
"hostname={{user `host_name`}} ",
"fb=false debconf/frontend=noninteractive ",
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
"keyboard-configuration/variant=USA console-setup/ask_detect=false ",
"initrd=/install/initrd.gz -- <enter>"
]
}]
}

virtualbox/preseed.cfg包含
d-i debian-installer/language string en
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/preferred-locale string en_US.UTF-8
d-i localechooser/supported-locales en_US.UTF-8
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layout select USA
d-i keyboard-configuration/variant select USA
d-i keyboard-configuration/modelcode string pc105
d-i netcfg/get_hostname string this-host
d-i netcfg/get_domain string this-host
d-i time/zone string UTC
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i debconf debconf/frontend select Noninteractive
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect standard, ubuntu-server
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
d-i mirror/http/proxy string
d-i passwd/user-fullname string ubuntu
d-i passwd/username string ubuntu
d-i passwd/user-password password ubuntu
d-i passwd/user-password-again password ubuntu
d-i user-setup/encrypt-home boolean false
d-i user-setup/allow-password-weak boolean true
d-i pkgsel/install-language-support boolean false
d-i pkgsel/include string build-essential ssh
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select safe-upgrade
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note

为了清楚起见,故意最小化了上述 Packer 设置。最终目标是让 Packer 设置也为生产创建 AWS 实例(实际上工作正常)。

如果我更换
"shutdown_command": "echo {{user `ssh_pass`}} | sudo -S shutdown -P now"


"shutdown_command": "env"

然后我得到输出
virtualbox: XDG_SESSION_ID=1
virtualbox: TERM=xterm
virtualbox: SHELL=/bin/bash
virtualbox: SSH_CLIENT=10.0.2.2 63390 22
virtualbox: SSH_TTY=/dev/pts/0
virtualbox: USER=ubuntu
virtualbox: SSH_AUTH_SOCK=/tmp/ssh-xO4Ad2K13w/agent.825
virtualbox: MAIL=/var/mail/ubuntu
virtualbox: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
virtualbox: PWD=/home/ubuntu
virtualbox: LANG=en_US.UTF-8
virtualbox: SHLVL=1
virtualbox: HOME=/home/ubuntu
virtualbox: LOGNAME=ubuntu
virtualbox: SSH_CONNECTION=10.0.2.2 63390 10.0.2.15 22
virtualbox: XDG_RUNTIME_DIR=/run/user/1000
virtualbox: _=/usr/bin/env

最佳答案

原来有non-breaking space而不是 shutdown_command 中的常规空白。对于 OSX,可以 disable non-breaking spaces ,对于 Sublime Text,有一个 Unicode highlighter .

关于ubuntu - Ubuntu VirtualBox 的 Packer 创建无法关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31826070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com