Issue
I am trying to automate the installation of Virtualbox guest additions using Chef, however I am running into an issue where VBoxLinuxAdditions.run never exists with exit code 0. I always get exit code 1, even without any errors being reported in scripts printout.
It seems that they are getting installed, so I do not understand why this script always returns 1.
I am working on a Windows 8.1 host, Virtualbox 4.3.12 with Debian 6 guest os.
I am trying to accomplish this by running the following recipe using 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 file:
---
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"
}
}
Below is the output I receive:
================================================================================
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$
Solution
I am running 4.3.16 on Linux, and ran into the same problem. My installation is also embedded in an automated process.
You can unpack the archive to inspect the files with
./VBoxLinuxAdditions.run --target foo --noexec
The offending and useless piece of code that is causing the problem is in the install.sh starts here:
test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
(REMOVE_INSTALLATION_DIR never gets set to 1 despite whether or not $INSTALLATION_DIR exists).
The bug, at the end of the file, is this:
test -n "$REMOVE_INSTALLATION_DIR" &&
echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
Since $REMOVE_INSTALLATION_DIR never gets set, test -n returns 1 (fail), and instead of providing an exit 0 at the end of the install script like the author should have, it falls off the end and gives that last exit code to the shell.
Successful workaround:
# REMOVE_INSTALLATION_DIR=0 ./VBoxLinuxAdditions.run
# echo $?
0
Answered By - Derek Douville Answer Checked By - Mary Flores (WPSolving Volunteer)