VBoxLinuxAdditions.run永远不会退出0

apa*_*ick 1 bash debian virtualbox chef-infra

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

它们似乎已经安装,所以我不明白为什么这个脚本总是返回1.

我正在使用Debian 6 guest OS的Windows 8.1主机Virtualbox 4.3.12.

我试图通过使用厨房运行以下配方来实现这一目标:

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
Run Code Online (Sandbox Code Playgroud)

我的.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"
    }
  }
Run Code Online (Sandbox Code Playgroud)

以下是我收到的输出:

       ================================================================================
       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$
Run Code Online (Sandbox Code Playgroud)

小智 7

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

您可以解压缩存档以检查文件

./VBoxLinuxAdditions.run --target foo --noexec
Run Code Online (Sandbox Code Playgroud)

导致问题的有问题和无用的代码片段在install.sh中从这里开始:

test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
Run Code Online (Sandbox Code Playgroud)

(尽管$ INSTALLATION_DIR是否存在,REMOVE_INSTALLATION_DIR永远不会设置为1).

该文件末尾的错误是:

test -n "$REMOVE_INSTALLATION_DIR" &&
    echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
Run Code Online (Sandbox Code Playgroud)

因为$ REMOVE_INSTALLATION_DIR永远不会被设置,所以test -n返回1(失败),而不是像安装脚本那样在安装脚本的末尾提供退出0,它会从最后退出并将最后一个退出代码提供给shell .

成功的解决方法:

# REMOVE_INSTALLATION_DIR=0 ./VBoxLinuxAdditions.run
# echo $?
0
Run Code Online (Sandbox Code Playgroud)