vagrant ash: sudo: not found - vagrant

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).

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.

Issues mounting a shared folder in virtualbox

I'm trying to create a shared folder between MacOS (Host) and Debian (Guest) in virtualbox. I've completed the steps of installing guest additions, creating a shared folder called "share" and a folder in debian called "sf", but when I try to run
sudo mount -t vboxsf share ~/sf
I get the error
mount: realpath /Users/USERNAME/sf: No such file or directory
I'm under the impression the second path is meant to be the directory in Debian. This also happens when I remove the ~/.
Looks like you are trying to run this command from your OSX shell. Is that possibly the case?
If yes, switch to your shell on the Debian guest. Also make sure the directory ~/sf actually does exist before you run the mount command.
Hope this helps.

Vagrantfile ordering provisioner issue

I have the following vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = 4
#storage
end
config.vm.provision "shell",
path: "vagrant_files/setup_script.sh"
config.vm.provision :reload
config.vm.provision "shell",
path: "vagrant_files/setup_script_2.sh"
config.vm.provision :reload
config.vm.provision "shell",
path: "vagrant_files/setup_script_3.sh"
config.vm.synced_folder ".", "/vagrant"
end
In my setup setup_script I have vagrant install Virtual Box Guest Additions which is a requirement to get the synced folder feature to work for vagrant.
Unfortunately, even if I put the line to sync the folders at the very end of the Vagrantfile, it still attempts to do that task first resulting in an error:
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
mount: unknown filesystem type 'vboxsf'
I understand I need to first install the Virtual Box Guest Additions. Anyone else run into this issue? how did you all solve this problem?
This is an interesting issue. I spun up a CentOS 7 VM with the same base box like so...
vagrant init centos/7
vagrant up
...and the Guest Additions installation failed. Here's the relevant output from Vagrant...
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.10 - guest version is
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
./install.sh: line 345: bzip2: command not found
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
./install.sh: line 358: bzip2: command not found
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
So this base box does not have the bzip2 package installed and that causes the failure. Out of curiosity I created a new Ubuntu VM from the ubuntu/trusty64 base box and Guest Additions installed without any problem. As you might guess, the bzip2 package was already installed in Ubuntu.
I would classify this as an issue with the base box itself. The CentOS project should be baking bzip2 into all of their Vagrant base boxes that are used with VirtualBox.
Of course, this doesn't help you right now, but fortunately you have many more options for CentOS base boxes and I would expect that most of them are not affected by this issue.
To fix my issue, I just loaded the Centos box.
Then I proceeded to install Virtual Box Guest Additions
Then I proceeded to repackage the box
That solved my issue.
I used luvejo tip on https://github.com/mitchellh/vagrant/issues/6769 and it worked for me as well:
You can also install the vagrant-vbguest plugin so it adds the
VirtualBox Guest Additions for you.
vagrant plugin install vagrant-vbguest
vagrant destroy && vagrant up
And that works for me.

vagrant - constantly syncing folder setup

I am trying build a centos7 vm at my windows10 using virtualbox. I am using cento/7 box.
it by default using rsync for syncing folder and I don't really like it as I would have to open an extra cmd just to run vagrant rsync-auto for constant syncing.
I tried to use nfs but not successful.
Here is my vagrantfile.
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.synced_folder ".", "/home/vagrant/sync", type: "nfs"
end
and when I tried to run it. It gave me this.
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` home_vagrant_sync /home/vagrant/sync
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` home_vagrant_sync /home/vagrant/sync
The error output from the last command was:
mount: unknown filesystem type 'vboxsf'
I noticed that changes made by host will be synced to guest but not the other way round. I want to make the folder like a shared folder both guest and host can apply changes to it. Any best approaches to do it?
Thanks.
The reply you got is telling you to install Virtual Box guest additions. This is a separate installation action you have to perform on top of installing Virtual Box. Did you install Virtual Box Guest Additions?

Mounting a symlinked folder in vagrant & virtualbox

Okay, so here is my problem:
I use vagrant with VirtualBox. The host is Windows 8.1, the guest is Ubuntu (64bit). I am trying to use a symlinked windows folder created by
mklink /j somefolder someotherfolder
as synced folder in Vagrant. In my Vagrantfile I have
# disable the default synced folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# sync my desired folder
config.vm.synced_folder "./somefolder", "/vagrant"
Unfortunately this does not work, but gives the following error:
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3`
vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
Before you ask: Guest additions are installed, and mounting regular folders works flawlessly.
Is there a way to use symlinked directories as synced folders in vagrant with vbox?
Thanks for your help!
I was having a similar issue. I couldn't get Symlinks working with vagrant but a Hardlink Clone did. I was trying to have my Dev folder in sync with Google Drive but did not want to relocate the folder.
My Solution: Hardlink Clone
Download and install Linkshell for windows (and the listed prerequisite package) [ direct Link to actual file I downloaded | direct link to prerequisite package I downloaded ] Direct link good for Windows XP64,
Windows Vista64,
Windows Server ,
2003/2008/20012 64bit,
Windows 7/8/10 64bit
Right click on source folder (in my case the one I copied to Google drive) and select pick link source
In location where you want your "symlink", right click and select Drop as -> Hardlink Clone
Thats what it took for me to get it working with vagrant. I originally tried as symbolic link without success.
Cut the folder to where you need it from the VM, after that create the junction (or symlink) at the original location.

Resources