Ubuntu VirtualBox的Packer创建无法关闭

时间:2015-08-05 07:30:34

标签: ubuntu virtualbox packer

我正在尝试使用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 

1 个答案:

答案 0 :(得分:1)

事实证明,在shutdown_command中有non-breaking space而不是常规空白。对于OSX,可以disable non-breaking spaces,对于Sublime Text,可以有Unicode highlighter