Bash VBoxLinuxAdditions.run永远不会与0一起退出

Bash VBoxLinuxAdditions.run永远不会与0一起退出,bash,debian,chef-infra,virtualbox,Bash,Debian,Chef Infra,Virtualbox,我正在尝试使用Chef自动安装Virtualbox来宾添加,但是我遇到了一个问题,即VBoxLinuxAdditions.run不存在,退出代码为0。我总是得到退出代码1,即使脚本打印输出中没有报告任何错误 看起来它们正在被安装,所以我不明白为什么这个脚本总是返回1 我正在使用Windows 8.1主机Virtualbox 4.3.12和Debian 6来宾操作系统 我试图通过使用kitchen运行以下食谱来实现这一点: include_recipe "apt" %W[make gcc xse

我正在尝试使用Chef自动安装Virtualbox来宾添加,但是我遇到了一个问题,即VBoxLinuxAdditions.run不存在,退出代码为0。我总是得到退出代码1,即使脚本打印输出中没有报告任何错误

看起来它们正在被安装,所以我不明白为什么这个脚本总是返回1

我正在使用Windows 8.1主机Virtualbox 4.3.12和Debian 6来宾操作系统

我试图通过使用kitchen运行以下食谱来实现这一点:

include_recipe "apt"

%W[make gcc xserver-xorg xserver-xorg-core linux-headers-#{node['kernel']['release']} dkms].each do |p|
  package p do
    action :install
  end
end

# get additions iso file
remote_file "#{Chef::Config[:file_cache_path]}/vboxAdditions.iso" do
  source "http://download.virtualbox.org/virtualbox/#{node['virtualbox']['version']}/VBoxGuestAdditions_#{node['virtualbox']['version']}.iso"
end

# create the mount point
directory "/mnt/vboxAdditions" do
  owner "root"
  group "root"
  mode "0755"
  action :create
end

# mount the iso
mount "/mnt/vboxAdditions" do
  action :mount
  device "#{Chef::Config[:file_cache_path]}/vboxAdditions.iso"
fstype "iso9660"
  options "loop"
end

# run the installer script
execute "install vbox guest additions" do
  command "sh /mnt/vboxAdditions/VBoxLinuxAdditions.run"
end
My.kitchen.yml文件:

---
driver_plugin: vagrant

platforms:
- name: debian-6
  driver_config:
    box: opscode-debian-6.0.7
    box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_debian-6.0.7_chef-11.2.0.box
    require_chef_omnibus: 11.4.0

suites:

- name: guest_additions
  run_list: ["recipe[virtualbox::guest_additions]"]
  attributes: {
    "virtualbox": {
      "version": "4.3.12"
    }
  }
以下是我收到的输出:

       ================================================================================
       Error executing action `run` on resource 'execute[install vbox guest additions]'
       ================================================================================


       Mixlib::ShellOut::ShellCommandFailed
       ------------------------------------
       Expected process to exit with [0], but received '1'
       ---- Begin output of sh /mnt/vboxAdditions/VBoxLinuxAdditions.run ----
       STDOUT: Verifying archive integrity... All good.
       Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
       STDERR: VirtualBox Guest Additions installer
       Removing installed version 4.2.6 of VirtualBox Guest Additions...
       Copying additional installer modules ...
       add_symlink: link file /usr/lib/VBoxGuestAdditions already exists
       Installing additional modules ...
       Removing existing VirtualBox DKMS kernel modules ...done.
       Removing existing VirtualBox non-DKMS kernel modules ...done.
       Building the VirtualBox Guest Additions kernel modules ...done.
       Doing non-kernel setup of the Guest Additions ...done.
       Starting the VirtualBox Guest Additions ...done.
       Installing the Window System drivers
       Installing X.Org Server 1.7 modules ...done.
       Setting up the Window System to use the Guest Additions ...done.
       You may need to restart the hal service and the Window System (or just restart
       the guest system) to enable the Guest Additions.

       Installing graphics libraries and desktop services components ...done.
       ---- End output of sh /mnt/vboxAdditions/VBoxLinuxAdditions.run ----
       Ran sh /mnt/vboxAdditions/VBoxLinuxAdditions.run returned 1


       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cookbooks/virtualbox/recipes/guest_additions.rb

        70:   execute "install vbox guest additions" do
        71:     command "sh /mnt/vboxAdditions/VBoxLinuxAdditions.run"
        72:   end
        73:



       Compiled Resource:
       ------------------
       # Declared in /tmp/kitchen/cookbooks/virtualbox/recipes/guest_additions.rb:70:in `from_file'

       execute("install vbox guest additions") do
         action "run"
         retries 0
         retry_delay 2
         command "sh /mnt/vboxAdditions/VBoxLinuxAdditions.run"
         backup 5
         returns 0
         cookbook_name :virtualbox
         recipe_name "guest_additions"
       end



       [2014-08-21T19:34:55+00:00] INFO: Running queued delayed notifications before re-raising exception
       [2014-08-21T19:34:55+00:00] ERROR: Running exception handlers
       [2014-08-21T19:34:55+00:00] ERROR: Exception handlers complete
       Chef Client failed. 14 resources updated
       [2014-08-21T19:34:55+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2014-08-21T19:34:55+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[install vbox guest additions] (virtualbox::guest_additions line 70) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
       ---- Begin output of sh /mnt/vboxAdditions/VBoxLinuxAdditions.run ----
       STDOUT: Verifying archive integrity... All good.
       Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
       STDERR: VirtualBox Guest Additions installer
       Removing installed version 4.2.6 of VirtualBox Guest Additions...
       Copying additional installer modules ...
       add_symlink: link file /usr/lib/VBoxGuestAdditions already exists
       Installing additional modules ...
       Removing existing VirtualBox DKMS kernel modules ...done.
       Removing existing VirtualBox non-DKMS kernel modules ...done.
       Building the VirtualBox Guest Additions kernel modules ...done.
       Doing non-kernel setup of the Guest Additions ...done.
       Starting the VirtualBox Guest Additions ...done.
       Installing the Window System drivers
       Installing X.Org Server 1.7 modules ...done.
       Setting up the Window System to use the Guest Additions ...done.
       You may need to restart the hal service and the Window System (or just restart
       the guest system) to enable the Guest Additions.

       Installing graphics libraries and desktop services components ...done.
       ---- End output of sh /mnt/vboxAdditions/VBoxLinuxAdditions.run ----
       Ran sh /mnt/vboxAdditions/VBoxLinuxAdditions.run returned 1
>>>>>> Converge failed on instance <guest-additions-debian-6>.
>>>>>> Please see .kitchen/logs/guest-additions-debian-6.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: SSH exited (1) for command: [sudo -E chef-solo --config /tmp/kitchen/solo.rb --json-attributes /tmp/kitchen/dna.json  --log_level info]
>>>>>> ----------------------
bash.exe"-3.1$

我在Linux上运行4.3.16,遇到了同样的问题。我的安装也嵌入到一个自动化的过程中

您可以解压归档文件以使用

./VBoxLinuxAdditions.run --target foo --noexec
导致问题的令人不快且无用的代码在install.sh中,从这里开始:

test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
无论$INSTALLATION\u DIR是否存在,REMOVE\u INSTALLATION\u DIR永远不会设置为1

文件末尾的错误是:

test -n "$REMOVE_INSTALLATION_DIR" &&
    echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
由于$REMOVE\u INSTALLATION\u DIR从未被设置,test-n返回1 fail,并不像作者应该的那样在安装脚本的末尾提供一个退出0,而是从结尾处脱落,并将最后一个退出代码提供给shell

成功的解决方法:

# REMOVE_INSTALLATION_DIR=0 ./VBoxLinuxAdditions.run
# echo $?
0

我在Linux上运行4.3.16,遇到了同样的问题。我的安装也嵌入到一个自动化的过程中

您可以解压归档文件以使用

./VBoxLinuxAdditions.run --target foo --noexec
导致问题的令人不快且无用的代码在install.sh中,从这里开始:

test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
无论$INSTALLATION\u DIR是否存在,REMOVE\u INSTALLATION\u DIR永远不会设置为1

文件末尾的错误是:

test -n "$REMOVE_INSTALLATION_DIR" &&
    echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
由于$REMOVE\u INSTALLATION\u DIR从未被设置,test-n返回1 fail,并不像作者应该的那样在安装脚本的末尾提供一个退出0,而是从结尾处脱落,并将最后一个退出代码提供给shell

成功的解决方法:

# REMOVE_INSTALLATION_DIR=0 ./VBoxLinuxAdditions.run
# echo $?
0

我可以确认5.0.4版的install.sh脚本中仍然存在问题,并且Derek的解决方法仍然很好。我在下面的代码示例中包含了相关的代码片段:

27  PACKAGE="VBoxGuestAdditions"
...
32  INSTALLATION_VER="5.0.4"
33  INSTALLATION_REV="102546"
...
38  INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
...
324 INSTALLATION_MODULES_DIR="$INSTALLATION_DIR/installer/"
...
329 mkdir -p -m 755 "$INSTALLATION_MODULES_DIR"
...
343 test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
344 mkdir -p -m 755 "$INSTALLATION_DIR"
...
531 test -n "$REMOVE_INSTALLATION_DIR" &&
532   echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG/FILES"

REMOVE_INSTALLATION_DIR在第343行永远不会设置为1,因为INSTALLATION_DIR在第329行被创建为INSTALLATION_MODULES_DIR的父目录。

我可以确认5.0.4版的install.sh脚本中仍然存在问题,并且Derek的解决方法仍然有效。我在下面的代码示例中包含了相关的代码片段:

27  PACKAGE="VBoxGuestAdditions"
...
32  INSTALLATION_VER="5.0.4"
33  INSTALLATION_REV="102546"
...
38  INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
...
324 INSTALLATION_MODULES_DIR="$INSTALLATION_DIR/installer/"
...
329 mkdir -p -m 755 "$INSTALLATION_MODULES_DIR"
...
343 test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
344 mkdir -p -m 755 "$INSTALLATION_DIR"
...
531 test -n "$REMOVE_INSTALLATION_DIR" &&
532   echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG/FILES"

REMOVE_INSTALLATION_DIR在第343行永远不会设置为1,因为INSTALLATION_DIR在第329行被创建为INSTALLATION_MODULES_DIR的父目录。

即使使用VirtualBox 5.0 guest additions,我发现VBoxLinuxAdditions.run的返回代码也完全不可靠。例如,如果我从框中删除gcc,并使用

删除安装目录=0./VBoxLinuxAdditions.run 正如在另一个答案中所述,它将无法构建,但仍然会给出0的返回码

我的解决方案是检查是否构建了内核模块。所以我是这样运行的:

/location/of/VBoxLinuxAdditions.run || true

if ! test -f /lib/modules/$(uname -r)/extra/vboxsf.ko
then
  echo "installation of guest additions unsuccessful"
  exit 1
fi

即使使用VirtualBox 5.0 guest additions,我发现VBoxLinuxAdditions.run的返回代码也完全不可靠。例如,如果我从框中删除gcc,并使用

删除安装目录=0./VBoxLinuxAdditions.run 正如在另一个答案中所述,它将无法构建,但仍然会给出0的返回码

我的解决方案是检查是否构建了内核模块。所以我是这样运行的:

/location/of/VBoxLinuxAdditions.run || true

if ! test -f /lib/modules/$(uname -r)/extra/vboxsf.ko
then
  echo "installation of guest additions unsuccessful"
  exit 1
fi

我尝试了德里克的解决方案,但没有成功。我正在使用vagrant的packer编写创建虚拟机的脚本。我所做的是:

echo "sudo /path/to/installer/VBoxLinuxAdditions.run" > /tmp/install_va.sh
/bin/bash /tmp/install_va.sh
sudo /usr/sbin/VBoxService --version

这样,在我的例子中,使Vagrant的打包程序破坏VM的虚假错误结果将发生在子进程中,而不会在当前进程中捕获。最后一个操作的结果将是脚本的结果。如果上次检查出错,说明安装中出现了问题。

我尝试了Derek的解决方案,但没有成功。我正在使用vagrant的packer编写创建虚拟机的脚本。我所做的是:

echo "sudo /path/to/installer/VBoxLinuxAdditions.run" > /tmp/install_va.sh
/bin/bash /tmp/install_va.sh
sudo /usr/sbin/VBoxService --version

这样,在我的例子中,使Vagrant的打包程序破坏VM的虚假错误结果将发生在子进程中,而不会在当前进程中捕获。最后一个操作的结果将是脚本的结果。如果上次检查出错,则说明安装中出现了问题。

是Victor Roetman方法的后续,该方法避免了一些路径问题:

if ! modinfo vboxsf >/dev/null 2>&1; then
  echo "Cannot find vbox kernel module. Installation of guest additions unsuccessful!"
  exit 1
fi

维克多·罗特曼方法的后续,该方法避免了一些路径问题:

if ! modinfo vboxsf >/dev/null 2>&1; then
  echo "Cannot find vbox kernel module. Installation of guest additions unsuccessful!"
  exit 1
fi

你的食谱在哪里?有日志输出吗?您是如何运行该命令的?另请参见:我将立即更新此命令。我不确定Chef届时将如何帮助您。如果脚本退出非零,则可能是错误。您可以告诉Chef允许脚本返回1。Whoie
如果投票否决了我的问题,请告诉我问题出在哪里,这样我至少可以改进我的问题。谢谢。你的食谱在哪里?有日志输出吗?您是如何运行该命令的?另请参见:我将立即更新此命令。我不确定Chef届时将如何帮助您。如果脚本退出非零,则可能是错误。你可以告诉Chef脚本可以返回1。无论谁否决了我的问题,请告诉我有什么问题,这样我至少可以改进我的问题。谢谢。你,我的朋友,是绅士和学者。你,我的朋友,是绅士和学者。