【问题标题】:VBoxLinuxAdditions.run never exits with 0VBoxLinuxAdditions.run 永远不会以 0 退出
【发布时间】:2020-10-24 08:17:30
【问题描述】:

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

他们似乎正在安装,所以我不明白为什么这个脚本总是返回 1。

我正在使用带有 Debian 6 来宾操作系统的 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

我的 .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$

【问题讨论】:

  • 你的食谱在哪里?有日志输出吗?你是如何运行命令的?
  • 我会马上更新。
  • 那么我不确定 Chef 可以如何帮助您。如果脚本退出非零,那可能是一个错误。您可以告诉 Chef 脚本“允许”返回 1。
  • 谁对我的问题投了反对票,请告诉我它有什么问题,以便我至少可以改进我的问题。谢谢。

标签: bash debian chef-infra virtualbox


【解决方案1】:

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

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

./VBoxLinuxAdditions.run --target foo --noexec

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

test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1

(无论 $INSTALLATION_DIR 是否存在,REMOVE_INSTALLATION_DIR 都不会设置为 1)。

文件末尾的错误是这样的:

test -n "$REMOVE_INSTALLATION_DIR" &&
    echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"

由于 $REMOVE_INSTALLATION_DIR 永远不会被设置,test -n 返回 1(失败),而不是像作者应该的那样在安装脚本的末尾提供退出 0,它从末尾脱落并给出最后一个退出代码到外壳。

成功的解决方法:

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

【讨论】:

  • 你,我的朋友,既是绅士又是学者。
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

    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,因为在第 329 行为INSTALLATION_MODULES_DIR 创建了INSTALLATION_DIR(作为父目录)。

    【讨论】:

      【解决方案4】:

      即使添加了 VirtualBox 5.0 来宾,我发现 VBoxLinuxAdditions.run 的返回码完全不可靠。例如,如果我从框中删除 gcc,然后运行

      REMOVE_INSTALLATION_DIR=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
      

      【讨论】:

        【解决方案5】:

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

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

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

        【讨论】:

          猜你喜欢
          • 2018-06-09
          • 1970-01-01
          • 2019-09-23
          • 2014-08-04
          • 2012-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-03-26
          相关资源
          最近更新 更多