Autostart and shared folder access

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
Keating
Posts: 5
Joined: 5. May 2021, 09:30

Autostart and shared folder access

Post by Keating »

Hello,

I have a working Guest OS (Ubantu 20.04) running on an up-to-date Host MacOS Catalina (10.15.7) with up-to-date VirtualBox (6.1.22). I have the Guest working as expected, and have configured an external hard disk as a Shared Folder. This all works as expected when run manually.

However, I'm now wanting to auto-start the VM at boot. I found out how to do this, and the Guest OS does indeed boot when the Host does. However, the shared folder is mounted with permissions that prevent reading in the Guest OS. This is true even if I shut down and manually restart the Guest OS.

However, if I disable auto-start and reboot the Host OS, when I manually start the Guest OS, then everything works fine - the Shared folder can be read from the Guest OS.

When there is a problem, the Guest OS reports I do not have permission to access the mounted Shared Folder.

Output of ls -la in Guest OS when readable:

Code: Select all

drwxrwx--- 1 root vboxsf 578 Oct 14 2019 sf_Shared
Output of ls -la in Guest OS when not readable:

Code: Select all

drwxrwx--- 1 root vboxsf 578 Oct 14 2019 sf_Shared
When it isn't readable, this is what the Guest OS reports:

Code: Select all

# pwd
/media/sf_Shared
# ls -la
ls: cannot open directory '.': Operation not permitted
This parameter alone seems to be the problem:

Code: Select all

VBoxManage modifyvm <vmname> --autostart-enabled on
With it enabled, after the Host OS is rebooted, the Guest OS started at boot cannot access the Shared Folder. This is true even after manually restarting the Guest OS.
With it disabled, after the Host OS is rebooted, the Guest OS (started manually) can access the Shared Folder.

I also tried setting a long start delay so I could log into my Host OS before the Guest OS started up. While I'm able to do this, the permissions on the Shared Folder still prevent it from being accessed from the Guest OS.

Has anyone else experienced this problem and know a workaround?

Kind regards to any solutions.
Keating
Posts: 5
Joined: 5. May 2021, 09:30

Re: Autostart and shared folder access

Post by Keating »

After playing around a bit more, it no longer seems to matter whether I have autostart-enabled or not. The shared folder is no longer accessible at all from within the Guest OS - always reports no permissions. Guest additions definitely installed, and the Guest OS user is added to /etc/groups:

Code: Select all

vboxsf:x:998:plex
If I manually remove and re-add the Shared Folder, I can see the folder disappear and reappear in the /media directory. It is has permissions root:vboxsf, but always reports I don't have permissions to view it, even if I run as root in the Guest OS.

Attached a log from the failure.
Attachments
Plex-2021-05-05-22-32-39.log.zip
(31.87 KiB) Downloaded 8 times
granada29
Volunteer
Posts: 687
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostart and shared folder access

Post by granada29 »

hmmm -I just tried this on Big Sur 11.3.1 with VirtualBox 6.1.22 and a Debian bullseye (fully up to date including guest additions for VirtualBox 6.1.22) guest. It all seems to work as expected. I was able to create, edit and a save a file to the shared directory on the guest.

I mounted the shared folder manually with no additional options:

Code: Select all

root@debianvb:/sbin# mount -t vboxsf common /mnt
root@debianvb:/sbin# cd /mnt
root@debianvb:/mnt# ls -l
total 94764
drwxr-xr-x 1 root root       64 Jan 20  2010  Backups
drwxrwxrwx 1 root root      192 Nov  2  2017  bignum
-rwxr-xr-x 1 root root 14918144 Jun 11  2012  CheckPointVPN.msi
-rw-r--r-- 1 root root 16687104 May  8  2014  CheckPointVPNW8.msi
On comparing my session log to yours, I do note that you have

Code: Select all

00:00:01.186493 Shared Clipboard: Not available, rc=VERR_NOT_SUPPORTED
whereas in my log I see:

Code: Select all

00:00:01.716494 Shared Clipboard: Service loaded
00:00:01.716548 Shared Clipboard: Mode: Bidirectional
00:00:01.716622 Shared Clipboard: Service running in normal mode
It may be a red herring, but maybe you could try getting the clipboard operational and see if that helps
Keating
Posts: 5
Joined: 5. May 2021, 09:30

Re: Autostart and shared folder access

Post by Keating »

That sort of worked - I didn't need that to be enabled so left it default off. It seems to have put it back in the state I reported at the start. As long as I don't auto-start the VM at boot of the Host OS, I can access the Shared Folder from the Guest. Still have the same problem if the Guest auto starts.
granada29
Volunteer
Posts: 687
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostart and shared folder access

Post by granada29 »

Thanks for reporting back. It seems odd to me that the clipboard is required for shared folders to properly set the permissions. This might be worth a bug report.

I think the start at boot issue may be a timing problem. You probably need to wait until the volume containg the shared folder has been mounted by the OS before starting the VM. How to do this will depend on the mechanism that you're using to start the VM, but if there is a shell script involved you can probably add code to wait until the folder is available.
Keating
Posts: 5
Joined: 5. May 2021, 09:30

Re: Autostart and shared folder access

Post by Keating »

I found this configuration option to enable on the Host:

Code: Select all

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true
This does seem to force the Host to mount the external drives without logging in - at least I can check by ssh-ing into the Host after a fresh boot of the Host. However, it didn't seem to make any difference. It still was the case that with --autostart-enabled on set, it cannot access the Shared Folder at boot. Interestingly, it also didn't work when I started the VM manually via ssh in headless mode after a fresh boot. I'll continue to experiment with various start up scripts, rather than relying on the built in options of VirtualBox, but I'm at a loss to understand what's going on here.
granada29
Volunteer
Posts: 687
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostart and shared folder access

Post by granada29 »

Possibly your VM is starting before the disk automounter runs. Try adding a delay of say 30 secs before your script starts the VM. I know thats a long time, but it should give an indication of what might be going on. A more sophisticated script (e.g. monitoring for presence of the shared folder) could be done later.
Keating
Posts: 5
Joined: 5. May 2021, 09:30

Re: Autostart and shared folder access

Post by Keating »

After a lot of messing around, I haven't been able to get shared folders to work reliably at all. It would work okay only if the VM I wanted to access was manually started and no other VM had started before it.

What I've done instead is use

Code: Select all

autofs
in Ubuntu to mount a network drive, shared from the Host. This seems to work fine, and the order of boots no longer matters, and I can start the Guest OS when the Host OS boots and do not need to log into the Host first.

So, I've achieved what I wanted, but I couldn't do it through shared folders.
Post Reply