VBoxLinuxAdditions.run never exits with 0 - bash

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$

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

A followup to Victor Roetman's method, which avoids some pathing issues:
if ! modinfo vboxsf >/dev/null 2>&1; then
echo "Cannot find vbox kernel module. Installation of guest additions unsuccessful!"
exit 1
fi

I can confirm that the problem still exists in the install.sh script for version 5.0.4 - and that Derek's workaround is still good. I've included the relevant snippets in the code sample below:
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 will never be set to 1 on line 343 because INSTALLATION_DIR is created (as a parent directory) for the INSTALLATION_MODULES_DIR on line 329.

Even with VirtualBox 5.0 guest additions, I find the return code of VBoxLinuxAdditions.run to be completely unreliable. For example, if I remove gcc from the box, and run with
REMOVE_INSTALLATION_DIR=0 ./VBoxLinuxAdditions.run
as stated in another answer, it will fail to build but still give a return code of 0.
My solution is to check if the kernel modules were built. So I run it like this:
/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

I tried Derek's solution and it did not worked. I am scripting the creation of VMs using vagrant's packer. What I did was the following:
echo "sudo /path/to/installer/VBoxLinuxAdditions.run" > /tmp/install_va.sh
/bin/bash /tmp/install_va.sh
sudo /usr/sbin/VBoxService --version
This way, the spurious error result (which in my case was making Vagrant's packer to destroy the VM) will happen in the subprocess and not catched in the current process. The last operation's result will be the result of the script. If the last check errored, something went wrong in the installation.

Related

Vagrant was unable to mount VirtualBox shared folders. ERROR: INVALID ARGUMENT

I know that other people during the years had met similar problems (like this ) however in my case the guest addition is installed (0.30.0 version) and I tried to reinstall it a lot of times.
I work on Windows10 and those are the version of VirtualBox and Virtual Machine.
Virtualbox on your host claims: 5.2.8
VBoxService inside the vm claims: 6.1.22
This is the code of the problem:
default: /vagrant => C:/Users/XXXX XXXX/Documents/src
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1000,gid=1000,_netdev vagrant /vagrant
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
I never found the error Invalid argument in similar cases so my question is if this need a particular procedure.
Thank you very much
Just had a similar problem after an update - was getting the same:
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
What I found in virtualbox startup was the message:
VirtualBox Guest Additions: Kernel headers not found for target kernel
5.4.0-81-generic. Please install them and execute
/sbin/rcvboxadd setup
Used "vagrant ssh" to access the virtualbox command line and ran:
sudo apt-get install linux-headers-$(uname -r)
After that restarted vagrant:
vagrant halt
vagrant up
Then it actually built the VirtualBox Guest Additions properly and mounted my shared folders.
Had the same exact error as you after making my second vagrant project - specifically after changing my public_network setting.
mount -t vboxsf -o uid=1000,gid=1000,_netdev vagrant /vagrant
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
At I also tried several solutions from people's answers like the one mentioned here and updated my VirtualBox.
I'm not really sure how mine works but here's what I did:
I logged into the VM (vagrant ssh) and installed the guest additions manually
cd /opt
sudo wget -c
http://download.virtualbox.org/virtualbox/6.1.26/VBoxGuestAdditions_6.1.26.iso O VBoxGuestAdditions_6.1.26.iso
And then tried:
sudo mount VBoxGuestAdditions_5.1.28.iso -o loop /mnt
sudo sh /mnt/VBoxLinuxAdditions.run
But I got an error saying something like permission denied or no directory.
So I reload vagrant (vagrant reload), but the error still occurred. However, I still continued trying something else, so I thought maybe I should install the vbguest plugin and did this:
vagrant plugin install vagrant-vbguest
That removed the error for me after reload but when I logged into vagrant again, I still can't see my shared folders so I halted my vb and run provision:
vagrant up --provision
Then I got a message which said that there was an error while executing VBoxManage so on and so forth. So I paused all running machine in my VB, closed all running VB apps in my desktop, and run the command:
vagrant destroy
After recreating vagrant vagrant up, everything miraculously worked! I can now navigate to my shared folders' directory.
I'm still in the process of learning vagrant so I can't really explain what actually happened in my machine but I hope this can somehow be of help to you or to someone who have the same issue.
Step 1: open virtual box then right click on installation machine then ->close->power off.
Step 2: then run below command
vagrant halt
vagrant up
Finally got it working the following way (this related answer was of great help along with Paul_Z's answer in this same question).
Step 1:
Make sure VirtualBox Guest Additions Software is installed.
If this solved your Issue, then great! If not, continue on to step 2.
Step 2:
Read the VirtualBox Guest Additions installation output carefully.
(If no longer possible, you can rerun the setup by using cd to go to
/opt/VBoxGuestAdditions-*your-version-number-here*/init/
and then run:
sudo ./vboxadd setup)
Step 3:
Install the needed dependencies with the distribution's package manager that the error message shows. (In my particular case, it mentioned that the system couldn't perform kernel module builds because gcc make and perl were not present in the system).
Step 4:
Rerun the VirtualBox Guest Additions setup by going to
/opt/VBoxGuestAdditions-*your-version-number-here*/init/
and then run:
sudo ./vboxadd setup
(If more dependencies are requested, go back to step 3)
Step 5: Reboot
Step 6 (Optional):
Add user to vboxsf group so that it is able to access the shared folder if needed. (As explained in this answer).
sudo usermod -G vboxsf -a your_user_name
I have the issue i Ubuntu 20.04 and simply download a more recent version of VirtualBox, then extract the GuestAditions ISO and installed it
I ran just
vagrant plugin install vagrant-vbguest
and after this the box came up.

Vagrant VBoxGuessAdditions error

I created a Vagrant box with Ubuntu + KDE. I have a problem with resolution screen in this. A perhaps way to resolve this is install new VBoxGuessAdditions.
Indeed I change boolean (from false to true) on this line on my vagrantFile :
config.vbguest.auto_update = true
With this line at 'false' value I have no problem for up my vagrant.
But when a set this config at 'true' I have this error :
Installing the Window System drivers
Installing X.Org Server 1.17 modules ...done.
Setting up the Window System to use the Guest Additions ...done.
You may need to restart the the Window System (or just restart the guest system)
to enable the Guest Additions.
Installing graphics libraries and desktop services components ...done.
An error occurred during installation of VirtualBox Guest Additions 5.0.12. Some functionality may not work as
intended.
In most cases it is OK that the "Window System drivers" installation failed.
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
stdin: is not a tty
Cleaning up downloaded VirtualBox Guest Additions ISO...
==> default: Checking for guest additions in VM...
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
C:/Users/mynickname/.vagrant.d/gems/gems/vagrant-vbguest-0.11.0/lib/vagrant-vbguest/download.rb:23:in `unlink': P
ermission denied # unlink_internal - C:/Users/mynickname/.vagrant.d/tmp/VBoxGuestAdditions_5.0.12.iso (Errno::EAC
CES)
from C:/Users/mynickname/.vagrant.d/gems/gems/vagrant-vbguest-0.11.0/lib/vagrant-vbguest/download.rb:23:i
n `cleanup'
from C:/Users/mynickname/.vagrant.d/gems/gems/vagrant-vbguest-0.11.0/lib/vagrant-vbguest/hosts/base.rb:62
:in `cleanup'
from C:/Users/mynickname/.vagrant.d/gems/gems/vagrant-vbguest-0.11.0/lib/vagrant-vbguest/installers/base.
rb:194:in `cleanup'
My environment :
OS Host : Windows 7 pro
VirtualBox : 5.0.12 r104815
Vagrant : 1.8.1
ruby : 1.9.3p545
Can anyone know what doing on this vagrant and information of VBoxGuessAdditions ?
Try Vagrant 1.7.X. I had the same issue with 1.8.X.
Cheers,

Vagrant halt is failing with _syntax error near unexpected token `||'_

Vagrant is not able to halt / reload after the initial vagrant up (ie the one where the vm is provisioned). The initial vagrant up completes correctly, however after that I am not able to do the vagrant halt or reload.
The error message that I am getting is
==> default: Attempting graceful shutdown of VM...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
shutdown -h now
Stdout from the command:
Stderr from the command:
stdin: is not a tty
bash: line 2: syntax error near unexpected token `||'
bash: line 2: `export SSH_AUTH_SOCK= || ||'
List of vagrant plugin I am using
- vagrant-proxyconf (1.5.2)
- vagrant-share (1.1.5, system)
Vagrant version is 1.8.1
Virtualbox [provider] version 4.3.34r104062
Host OS : Windows 7 Enterprise
I have tried re-installing, all the components, destroying the VMs, deleting the config files [ie ~/.VirtualBox & ~/.vagrant.d]
Please help me in resolving the issue
This is not the fix.
The error went away when I again downloaded the code base from github.

vagrant ash: sudo: not found

When starting my vagrant box with a small 15MB Busybox image, the first time I get an error during the phase
Mounting shared folders...
It seems vagrant is trying something with sudo, which isn't istalled. I get this error:
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mkdir -p /vagrant
Stdout from the command:
Stderr from the command:
ash: sudo: not found
It works so far, I can login as root with the password vagrant, but I guess this is not perfect?
This is my setup: https://github.com/rubo77/ffnord-example/blob/pyddhcpd/Vagrantfile
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
config.ssh.shell = 'ash'
(0..9).each do |i|
config.vm.define "gc-node0#{i}" do |node|
end
end
By default vagrant share/sync the directory /vagrant (guest) with the current project directory, the one containing the Vagrantfile (host), more directories can be shared using config.vm.synced_folder, I don't know if the default /vagrant can be disabled.
If you aren't using the shared directories feature then the missing sudo isn't a problem.
If your filesystem is writeable you can create the /vagrant directory once, so on next up vagrant shouldn't try to sudo mkdir again;
but assuming you're using VirtualBox (I don't know about others emulator behavior/architecture) you'll face another problem, shared directories require the kernel modules vboxsf and vboxguest (from VirtualBox Guest Additions) to be built (against the running kernel sources) and loaded (insmod), and the command mount.vboxsf to be built and installed in /sbin, plus your busybox require the option mount helpers enabled because vagrant use mount -t vboxsf and not mount.vboxsf directly, when vagrant try to mount the shared directories and those requirements aren't matched there is a long timeout before failing with error (a minute/two or more).
Notice that busybox (current stable) support sudo, is just disabled by default.
If you're building the buildroot yourself from sources I can tell that the shared feature works (I managed to get an image with busybox to work as vagrant expect), if you're using some pre-built kernel/busybox... may be a problem, you have to find matching binaries for vboxsf, vboxguest, mount.vboxsf and if the mount helpers option is disabled in your busybox you need to find a workaround (perhaps modifying vagrant to use mount.vboxsf).

Laravel Homestead: Provisioning failing on Windows 8

I'm trying to use Laravel Homestead for a Laravel 4.2.9 project. Here's what I'm running:
Windows 8.1 64-bit
VirtualBox 4.3.17
Vagrant 1.6.5
Latest Homestead version
When running the box with vagrant up for the first time or issuing the vagrant provision command, I get this:
==> default: Running provisioner: shell...
default: Running: inline script
==> default: /tmp/vagrant-shell: line 1: /home/vagrant/.ssh/$2: ambiguous redirect
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Contents of /tmp/vagrant-shell on the box:
echo "$1" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2
This seems to be affecting nginx configuration as there is no default server conf and it's not listening on port 80 as expected. Presumably the provisioning script would handle that if it was able to proceed.
What might be causing this to happen?
I had the same problem and changed file homestead.rb in "scripts" directory by adding additional quotation marks and backslash around "$2".
s.inline = "echo \"$1\" > /home/vagrant/.ssh/\"$2\" && chmod 600 /home/vagrant/.ssh/\"$2\""

Resources