Can't execute scripts

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Gutchi
Posts: 34
Joined: 4. Apr 2016, 14:50

Can't execute scripts

Post by Gutchi »

Hello,

Since i have updated virtual box to 6.1.18 version i can't execute scripts and binaries from the shared folder.

For example with a test python3 script i have this

Code: Select all

/media/sf_shared./test.py 
zsh: invalid argument: ./test.py
The shebang is correct #!/usr/bin/python3 and when i try to run it from a folder inside the VM it work well. I have the same error on all the script/binaries stored on the shared folder.

Any workaround?

Thanks you
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Can't execute scripts

Post by scottgus1 »

If I understand correctly, you have a Virtualbox Shared Folder that you set up in the VM's settings. You used to be able to run scripts in that folder from the VM.

After you installed Virtualbox 6.1.18, the scripts still work well when run inside the VM, but no longer work on the host OS?

Or is it that you can copy the script to a folder inside the VM and it works, but it no longer works when run from the Virtualbox Shared Folder?

FWIW, Virtualbox Shared Folders have never officially supported running files or executables from the VSF. VSF's were designed only for manual copying of files from the VSF to the VM's disk and back. It could be that something has changed that has closed a hole your usage has been able to squeeze through. But it never was designed to allow that usage.

If you want to run reliably from a shared folder, you'd need to make a real shared folder on the host OS and share it to the VM over a Bridged or Host-Only network.

Also, from my Windows-centric eye, that period after "shared" in "/media/sf_shared./test.py" looks unusually placed. But it may be OK in Linux.
Gutchi
Posts: 34
Joined: 4. Apr 2016, 14:50

Re: Can't execute scripts

Post by Gutchi »

No exactly, I wanted to run launch scripts stored in the shared folder. Because these scripts are shared between multiple VM. Before the last VirtualBox they running well. But now i can't run these scripts from the shared folder.
They run well when i copied them in the VM filesystem. But it's not what i need. It's just a proff that the files are correct, and the error coming from the virtualbox share folder.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Can't execute scripts

Post by scottgus1 »

Gutchi wrote:I wanted to run launch scripts stored in the shared folder.
Where? On the host or inside the VMs?

I deduce that it was inside the VMs, at which this, pointed out already, applies:
scottgus1 wrote:Virtualbox Shared Folders have never officially supported running files or executables from the VSF. VSF's were designed only for manual copying of files from the VSF to the VM's disk and back. It could be that something has changed that has closed a hole your usage has been able to squeeze through. But it never was designed to allow that usage.

If you want to run reliably from a shared folder, you'd need to make a real shared folder on the host OS and share it to the VM over a Bridged or Host-Only network.
Gutchi
Posts: 34
Joined: 4. Apr 2016, 14:50

Re: Can't execute scripts

Post by Gutchi »

scottgus1 wrote:
Gutchi wrote:I wanted to run launch scripts stored in the shared folder.
Where? On the host or inside the VMs?
Yes exactly, running script stored on the share folder from inside the VM. It worked before, it should works now.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Can't execute scripts

Post by scottgus1 »

Gutchi wrote:It worked before, it should works now wasn't designed to work, though, so I have to use a different method.
FTFY :lol: Another way to access the scripts is indicated.
maharg101
Posts: 4
Joined: 28. Apr 2021, 19:26

Re: Can't execute scripts

Post by maharg101 »

I have exactly the same problem but am on Mac, and I have observed some differences depending on the guest OS.

- host Mac OSX Big Sur 11.3 on MacBook Pro (15-inch, 2018) with 32GB RAM
- VirtualBox 6.1.20 r143896 (Qt5.6.3)
- Vagrant 2.2.15 / vagrant-vbguest (0.29.0, global)

I create a synced folder in the Vagrantfile e.g.

Code: Select all

machine.vm.synced_folder "/path/to/project1/", "/opt/project1/"
In the project folder I have a bash script which is executable, and which has a shebang, and UNIX line endings, checked with `cat -vet`.

Code: Select all

#!/bin/bash
With an ubuntu 18.04 guest (hashicorp/bionic64) everything works as expected. The shell script can be executed with:

Code: Select all

/opt/project1/script.sh
With an ubuntu 21.04 guest (ubuntu/hirsute64, alvistack/ubuntu-21.04) the script cannot be executed because of a 'Bad interpreter'.

If I copy the script from /opt/project1 (the synced directory) to /home/vagrant (not a synced directory) the script executes as expected.

At this point I compared the copied script with cat -vet, md5sum, diff, etc and it is _identical_.

At this point, I re-iterate that the line endings in the the file are UNIX. Repeat UNIX. Plus the script works perfectly when copied to a non-synced folder.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Can't execute scripts

Post by scottgus1 »

That was a very good, detailed first post! Unfortunately, it's exactly the same solution for exactly the same problem. :D

Stop using a Virtualbox Shared Folder for execution of scripts, for all the reasons stated above. Use a real shared folder, shared from the host OS over a network.

(When one posts on an existing topic one is expected to have read the topic and tried the suggested solutions.. It appears you may not have done this, otherwise you'd know that Virtualbox Shared Folders was not designed for your chosen process.)
maharg101
Posts: 4
Joined: 28. Apr 2021, 19:26

Re: Can't execute scripts

Post by maharg101 »

That was a very good, detailed first post!
Thanks @scottgus1 ! :D
Unfortunately, it's exactly the same solution for exactly the same problem. :D
I thought you might say that.
Stop using a Virtualbox Shared Folder for execution of scripts, for all the reasons stated above. Use a real shared folder, shared from the host OS over a network.
It looks like we may indeed have to. It's a great shame if that's the case. In my experience, many developers rely on the bi-directional file-syncing for efficient developer workflows between host and guest. Of course other options (docker, kvm, cloud instance, ...) are available, but VirtualBox remains a useful tool to have at our disposal, especially where a full OS instance is required. It's convenient, fast, simple to orchestrate, and reliable.

I do find it odd that VSF's were designed only for manual copying of files, and yet it has worked for all of these many years. I had a quick scan of the documentation (chapter 4; I am not permitted to post URLs on my first day on the forum) and can find no mention of this limitation in the design. Not can I find any mention of this on the forum up until now. For example, the "HOWTO: Use Shared Folders" at /viewtopic.php?f=3&t=15868 does not mention it.

I find it doubly odd that a virtual filesystem which otherwise feels POSIX-ish with execute bits and so on can influence the efficacy of the shebang. But there we are.

I do wonder if the "bug" (if I may be so bold) is within VirtualBox, or has been introduced elsewhere. As I noted in my post earlier, it still works on an Ubuntu 18.04 guest for me.
(When one posts on an existing topic one is expected to have read the topic and tried the suggested solutions.. It appears you may not have done this, otherwise you'd know that Virtualbox Shared Folders was not designed for your chosen process.)
I have used other methods such as network (nfs) sharing in the past, and they have served me well. But given that VSFs have worked so well up until now, there has been little incentive to go to such extravagant lengths. I read the topic thoroughly before responding, and added my own experiences to the discussion in the spirit of co-operation. Thus I regard your criticism as unwarranted. As you have doubtless contributed more to my prosperity via your contributions to the venerable VirtualBox, than I have to yours, I will simply wish you well, and move on.

edit: I did subsequently find a mention from your good self of this at /viewtopic.php?f=6&t=80854
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Can't execute scripts

Post by scottgus1 »

I believe that the idea that VSFs were not supposed to be used for other than manual file copying comes from forum gurus who have delved deeply into the VSF source code. I believe I first got it from Mpack, who truly knows his stuff.

The manual does say:
This is similar to how you would use network shares in Windows networks, except that shared folders do not require networking, only the Guest Additions.
However, when folks try to run a VSF like a real shared folder, they start having jam-ups eventually. Could be unexpected changes by the devs. It could be that the original idea of a VSF was to allow full shared folder experience, but that has faded for some reason or could not be fully implemented, and the manual might be too optimistic. The advice to use VSFs only for copying and use real shared folders for opening/saving/editing/database-ing pulls most folks out of the fire and gets them going again. FWIW if Virtualbox were not involved and real computers were being used, only real shared folders would be available.
maharg101 wrote:I read the topic thoroughly before responding, and added my own experiences to the discussion in the spirit of co-operation. Thus I regard your criticism as unwarranted.
Most add-on posters don't read the topic first. Regrettably your post had no indication you read the topic first, either, thus my advice. I'm glad you did read the post first, that's rare! An acknowledgement in your first post that you had read through, like a "I saw the advice above that VSF's shouldn't be used to run anything, but I have a question about..." would have shown me you were the rare forum user that does read the post first. Helping folks to improve their posts is part of running the forum.
maharg101
Posts: 4
Joined: 28. Apr 2021, 19:26

Re: Can't execute scripts

Post by maharg101 »

Fair points @scottgus1.

I note that someone has raised a ticket on this issue, and identified that the change is likely related to newer linux kernels.

See virtualbox dot org /ticket/20232 (still technically in my first day as a forum member; cannot post links)
Gutchi
Posts: 34
Joined: 4. Apr 2016, 14:50

Re: Can't execute scripts

Post by Gutchi »

I'm not alone! I have made some tests as you @scottgus1. I can't understand well, but it's looks to be a problem with Virtualbox and recent kernel > 5.4 as it explained in the ticket 20232. I haven't see it, thanks I will follow it. But it looks old.
Martin
Volunteer
Posts: 2560
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Can't execute scripts

Post by Martin »

The changelog of the just released Virtualbox 6.1.22 mentions a fix for this.
maharg101
Posts: 4
Joined: 28. Apr 2021, 19:26

Re: Can't execute scripts

Post by maharg101 »

6.1.22 allows for execution from virtual shared folders. Have confirmed on https://www.virtualbox.org/ticket/20232
Gutchi
Posts: 34
Joined: 4. Apr 2016, 14:50

Re: Can't execute scripts

Post by Gutchi »

Nice ! Thanks you
Post Reply