Allow standard user access to virtual machines in VirtualBox

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
xox101
Level 3
Level 3
Posts: 114
Joined: Sat Jan 29, 2011 7:34 pm

Allow standard user access to virtual machines in VirtualBox

Post by xox101 »

Code: Select all

jerry@jerry-ThinkPad-X250:~$ inxi -Fxxxrz
System:
  Kernel: 5.4.0-96-generic x86_64 bits: 64 compiler: gcc v: 9.3.0 
  Desktop: Cinnamon 5.2.7 wm: muffin 5.2.0 dm: LightDM 1.30.0 
  Distro: Linux Mint 20.3 Una base: Ubuntu 20.04 focal 
Machine:
  Type: Laptop System: LENOVO product: 20CLS0PY00 v: ThinkPad X250 
  serial: <filter> Chassis: type: 10 serial: <filter> 
  Mobo: LENOVO model: 20CLS0PY00 serial: <filter> UEFI: LENOVO 
  v: N10ET61W (1.40 ) date: 03/17/2020 
Battery:
  ID-1: BAT0 charge: 16.8 Wh condition: 17.5/24.0 Wh (73%) volts: 12.3/11.4 
  model: LGC 45N1113 type: Li-ion serial: <filter> status: Unknown 
  ID-2: BAT1 charge: 16.9 Wh condition: 19.0/23.5 Wh (81%) volts: 12.1/11.4 
  model: LGC 45N1127 type: Li-ion serial: <filter> status: Discharging 
CPU:
  Topology: Dual Core model: Intel Core i7-5600U bits: 64 type: MT MCP 
  arch: Broadwell rev: 4 L2 cache: 4096 KiB 
  flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx 
  bogomips: 20751 
  Speed: 798 MHz min/max: 500/3200 MHz Core speeds (MHz): 1: 801 2: 798 
  3: 798 4: 799 
Graphics:
  Device-1: Intel HD Graphics 5500 vendor: Lenovo driver: i915 v: kernel 
  bus ID: 00:02.0 chip ID: 8086:1616 
  Display: x11 server: X.Org 1.20.13 driver: modesetting 
  unloaded: fbdev,vesa resolution: 1920x1080~60Hz 
  OpenGL: renderer: Mesa Intel HD Graphics 5500 (BDW GT2) v: 4.6 Mesa 21.0.3 
  direct render: Yes 
Audio:
  Device-1: Intel Broadwell-U Audio vendor: Lenovo driver: snd_hda_intel 
  v: kernel bus ID: 00:03.0 chip ID: 8086:160c 
  Device-2: Intel Wildcat Point-LP High Definition Audio vendor: Lenovo 
  driver: snd_hda_intel v: kernel bus ID: 00:1b.0 chip ID: 8086:9ca0 
  Sound Server: ALSA v: k5.4.0-96-generic 
Network:
  Device-1: Intel Ethernet I218-LM vendor: Lenovo driver: e1000e v: 3.2.6-k 
  port: 3080 bus ID: 00:19.0 chip ID: 8086:15a2 
  IF: enp0s25 state: down mac: <filter> 
  Device-2: Intel Wireless 7265 driver: iwlwifi v: kernel port: efa0 
  bus ID: 03:00.0 chip ID: 8086:095b 
  IF: wlp3s0 state: up mac: <filter> 
Drives:
  Local Storage: total: 223.57 GiB used: 118.86 GiB (53.2%) 
  ID-1: /dev/sda vendor: Crucial model: CT240BX500SSD1 size: 223.57 GiB 
  speed: 6.0 Gb/s serial: <filter> rev: R013 scheme: MBR 
Partition:
  ID-1: / size: 218.57 GiB used: 118.86 GiB (54.4%) fs: ext4 dev: /dev/sda5 
Sensors:
  System Temperatures: cpu: 37.0 C mobo: 0.0 C 
  Fan Speeds (RPM): cpu: 2500 
Repos:
  No active apt repos in: /etc/apt/sources.list 
  Active apt repos in: /etc/apt/sources.list.d/additional-repositories.list 
  1: deb [arch=amd64] https://repo.vivaldi.com/archive/deb/ stable main
  No active apt repos in: /etc/apt/sources.list.d/balena-etcher.list 
  Active apt repos in: /etc/apt/sources.list.d/google-chrome.list 
  1: deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
  Active apt repos in: /etc/apt/sources.list.d/micahflee-ppa-focal.list 
  1: deb http://ppa.launchpad.net/micahflee/ppa/ubuntu focal main
  Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list 
  1: deb http://packages.linuxmint.com una main upstream import backport #id:linuxmint_main
  2: deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
  3: deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
  4: deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
  5: deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
  6: deb http://archive.canonical.com/ubuntu/ focal partner
Info:
  Processes: 280 Uptime: 20h 31m Memory: 7.65 GiB used: 1.50 GiB (19.7%) 
  Init: systemd v: 245 runlevel: 5 Compilers: gcc: 9.3.0 alt: 9 Shell: bash 
  v: 5.0.17 running in: gnome-terminal inxi: 3.0.38 
As per title. I am trying to set up VirtualBox Version 6.1.32 so a standard user can use a Win 7 VM but no matter what I do the VM is not available to the standard user. The user is able to bring up VirtualBox but either no VM shows as available or if I do get a VM to show it won't run despite Win 7 showing and running for the admin account. I have added the user to the vboxusers group as per VBox install page.

https://www.virtualbox.org/manual/ch02. ... -vboxusers

I have also followed this link to setup up the VMs directory within admin Home as a shared directory.

https://askubuntu.com/questions/313089/ ... other-user

Using the info in that link I have managed to make the Win 7 VM show up in VBox in the standard user account but there is something badly wrong with the permissions I assume. No matter how I set the permissions according to that link the VM is either inaccessible to the admin user or to the standard user and is never accessible to both.

Changing the standard user to admin (which I really don't want to do) has no effect either.

Done lots of searching but all I get are reams of pages explaining how to setup shared folders in VBox between guest and host and nothing pertinent to my search. Of course I could be putting in the wrong search terms.

Help would be appreciated.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
AndyMH
Level 21
Level 21
Posts: 13749
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Allow standard user access to virtual machines in VirtualBox

Post by AndyMH »

As per title. I am trying to set up VirtualBox Version 6.1.32 so a standard user can use a Win 7 VM
This should happen 'out of the box' - how did you install VB and what did you do to install win?
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
xox101
Level 3
Level 3
Posts: 114
Joined: Sat Jan 29, 2011 7:34 pm

Re: Allow standard user access to virtual machines in VirtualBox

Post by xox101 »

AndyMH wrote: Wed Jan 26, 2022 7:43 pm
As per title. I am trying to set up VirtualBox Version 6.1.32 so a standard user can use a Win 7 VM
This should happen 'out of the box' - how did you install VB and what did you do to install win?
Downloaded latest version of VB, installed using Deb file and then installed Extension Pack. Imported Win7.ova and Win10.ova into VirtualBox then installed Guest Additions. Same as I have done countless times before with multiple installs and multiple operating systems.

This has come about as I tried to get Win7 to work in VB in a friends machine for her daughter to use in a standard user account. Same problem as I detailed in my original post so to rule out her Dell being the cause I tried on my Thinkpad. Exactly the same result.

I have never had any need to use VB in a standard account or indeed in any account other than my own admin account so never encountered this problem before.

I think next step is uninstall VB, delete the VM directory and install VB from Software Manager to rule out any differences between version in repos and latest from VB website.

Also looking at Gnome Boxes as an alternative as this should be simple to setup in my opinion.

Edit: Uninstalled VB, deleted VM directory, deleted user "test", rebooted, installed VB from Software Manager, imported Win7.ova, recreated user "test" and added user to vboxusers group. No difference. Changed user "test" to admin. No change.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Allow standard user access to virtual machines in VirtualBox

Post by smurphos »

Look at the permissions for the files related to your virtual machines. It appears to be that Virtualbox defaults to making them rw for the creating user only. E.g - no surprise here that only user steve will be able to launch this VM, as no-one else has read or write permission.

Code: Select all

steve@steve-Inspiron-5580:/mnt/virtualbox_images/Mint/Mint Current MultiDE$ ls -la
total 16779448
drwxrwxr-x 4 steve steve        4096 Jan 25 10:49  .
drwx------ 6 steve steve        4096 Dec 22 19:06  ..
drwx------ 2 steve steve        4096 Jan 27 08:30  Logs
-rw------- 1 steve steve        6113 Jan 25 10:49 'Mint Current MultiDE.vbox'
-rw------- 1 steve steve        6113 Jan 25 09:52 'Mint Current MultiDE.vbox-prev'
-rw------- 1 steve steve 17181966336 Jan 27 08:50 'Mint Current MultiDE.vdi'
drwx------ 2 steve steve        4096 Jan 24 09:29  Snapshots
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Allow standard user access to virtual machines in VirtualBox

Post by smurphos »

Just as an experiment I tried setting all the permission for this VM's files/folders to rw across the board. The secondary user on this machine could then access the machine. The problem was that once she shut down the VM, her user had taken ownership of the of the *.vbox file (and it has reset itself to rw for her only) and the most recent vbox log was under her ownership and rw only. Result - I'm locked out of that VM until I sort the permissions and ownership out.

Take-home - you can't share VM's between users without constantly pigging around with permissions or ownership, and VM's for a secondary user account should to be set up / imported or whatever from within that secondary user account.

If a VM really does need be shared or initially set up by another user then an sudo enabled user needs to sudo chown -R <nextuser>:<nextuser> /path/to/VM to fix ownership each time a different user has last used the VM.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
xox101
Level 3
Level 3
Posts: 114
Joined: Sat Jan 29, 2011 7:34 pm

Re: Allow standard user access to virtual machines in VirtualBox

Post by xox101 »

smurphos wrote: Thu Jan 27, 2022 5:26 am Just as an experiment I tried setting all the permission for this VM's files/folders to rw across the board. The secondary user on this machine could then access the machine. The problem was that once she shut down the VM, her user had taken ownership of the of the *.vbox file (and it has reset itself to rw for her only) and the most recent vbox log was under her ownership and rw only. Result - I'm locked out of that VM until I sort the permissions and ownership out.

Take-home - you can't share VM's between users without constantly pigging around with permissions or ownership, and VM's for a secondary user account should to be set up / imported or whatever from within that secondary user account.

If a VM really does need be shared or initially set up by another user then an sudo enabled user needs to sudo chown -R <nextuser>:<nextuser> /path/to/VM to fix ownership each time a different user has last used the VM.
Yes, that does seem to be what is happening. I have tried VMWare as well and it seems to be the same while Gnome Boxes does not seem to have an option to export or indeed import an already setup VM.

Going to have to bite the bullet and use valuable disk space by creating a VM directory for user "test" and importing a VM into it then setting the path in VB. Hopefully that will work.

Thanks for checking it for me, I was beginning to think I had missed something very obvious!
User avatar
AndyMH
Level 21
Level 21
Posts: 13749
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Allow standard user access to virtual machines in VirtualBox

Post by AndyMH »

xox101 wrote: Thu Jan 27, 2022 9:31 am Going to have to bite the bullet and use valuable disk space by creating a VM directory for user "test" and importing a VM into it then setting the path in VB. Hopefully that will work.
I have a launcher on the desktop to start my win7 VM (there is an option in VB, 'add launcher to desktop), that executes:

Code: Select all

/usr/lib/virtualbox/VirtualBoxVM --comment "Win71" --startvm "{93f137eb-9bdf-46ad-a866-c07ba5d7a946}"
Why not create a simple script that does (user would need to be a member of sudo group):

Code: Select all

sudo chown -R $USER:$USER /path/to/VM
/usr/lib/virtualbox/VirtualBoxVM --comment "Win71" --startvm "{93f137eb-9bdf-46ad-a866-c07ba5d7a946}"
and create a launcher for it.

or better

Code: Select all

pkexec chown -R $USER:$USER /path/to/VM
/usr/lib/virtualbox/VirtualBoxVM --comment "Win71" --startvm "{93f137eb-9bdf-46ad-a866-c07ba5d7a946}"
and if you don't want to enter a password every time, create a polkit for chown.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
xox101
Level 3
Level 3
Posts: 114
Joined: Sat Jan 29, 2011 7:34 pm

Re: Allow standard user access to virtual machines in VirtualBox

Post by xox101 »

I had planned to add a shortcut, this was something I did around 10 years ago on a friends Vista machine which she was using for her own business and also as a general PC. I was forever removing crap from it until I installed VB, imported a XP VM and got her a second monitor with the XP VM set to always open on the left monitor and Vista on the right. Took a snapshot after initial install, named the VM shortcut Playbox and problem was solved. She was convinced she had two physical computers. lol Kinda why I love VB.

But herein lies the problem. Friends daughter and also friends daughters friends! Do not want to give her sudo privileges, if I do then I will be there fixing it forever more.

So I am going to try two separate VM directories. If I shrink my Win7 VM then it may work. And it may turn out to be a lot more reliable than changing the permissions. Thanks for the suggestions, I will come back to them if the separate directories thing doesn't work.
User avatar
AndyMH
Level 21
Level 21
Posts: 13749
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Allow standard user access to virtual machines in VirtualBox

Post by AndyMH »

xox101 wrote: Thu Jan 27, 2022 12:34 pm But herein lies the problem. Friends daughter and also friends daughters friends! Do not want to give her sudo privileges, if I do then I will be there fixing it forever more.
Agreed, but expect their linux knowledge to be close to zero. Not sure sudo would work which is why I suggested pkexec. Instead of creating a polkit for chown, a polkit for your script might work and would be more restrictive. Saves a few GB - my win7 VM is 46GB.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Locked

Return to “Virtual Machines”