我正在尝试使用Chef自动安装Virtualbox guest添加项,但是我遇到了一个问题,其中VBoxLinuxAdditions.run从不存在,退出代码为0.我总是得到退出代码1,即使脚本中没有报告任何错误打印输出。
它们似乎已经安装,所以我不明白为什么这个脚本总是返回1。
我正在使用Debian 6 guest OS的Windows 8.1主机Virtualbox 4.3.12。
我试图通过使用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
我的.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$
答案 0 :(得分:7)
我在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
答案 1 :(得分:1)
我可以确认问题仍然存在于版本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,因为在第329行INSTALLATION_DIR
创建了INSTALLATION_MODULES_DIR
(作为父目录)。
答案 2 :(得分:1)
维克多·罗特曼(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 :(得分:0)
即使添加了VirtualBox 5.0 guest虚拟机,我发现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
答案 4 :(得分:0)
我尝试了Derek的解决方案,但没有成功。我正在编写使用流浪汉的打包程序创建VM的脚本。我所做的是:
echo "sudo /path/to/installer/VBoxLinuxAdditions.run" > /tmp/install_va.sh
/bin/bash /tmp/install_va.sh
sudo /usr/sbin/VBoxService --version
这样,虚假错误结果(在我的情况下是使Vagrant的打包程序破坏VM)将在子进程中发生,而不会在当前进程中捕获。最后一个操作的结果将是脚本的结果。如果最后一次检查错误,则说明安装中出现了问题。