Access to shared folders in Virtual Box
Command line
By default, VirtualBox shared folders are created with read/write permission for the guest. This can be done from the command line on the host with:
VBoxManage sharedfolder add "VM name" --name sharename --hostpath "C:\test"
By adding the option --readonly
we can restrict these for read-only access. Use the --transient
option if you only want the shares to appear in the present session but not persistent for following sessions. There are some limitations for shared folders (see this question for details). If prerequisites are met we may mount these shared folders manually by running the following commands in the guest:
mkdir /home/<user>/vboxshare
sudo mount -t vboxsf -o uid=1000,gid=1000 sharename /home/<user>/vboxshare
Of course, we can also use different mount options to mount as read/only or mount with read access only to root.
Auto-Mount through Virtual Box Manager
In case we enabled auto-mounting on creating a shared folder from the Virtual Box Manager those shared folders will automatically be mounted in the guest with mount point /media/sf_<name_of_folder>
. To have access to these folders users in the guest need to be a member of the group vboxsf
.
sudo usermod -aG vboxsf $USER
The guest will need to restart
to have the new group added.
Source and further reading: Virtual Box User Manual
virtualbox虚拟机NAT搭配host-only
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [10.0.2.4/24]
gateway4: 10.0.2.2
nameservers:
addresses: [223.5.5.5, 119.29.29.29]
routes:
- to: 10.0.0.0/24
via: 192.168.1.254
metric: 100
eth1:
addresses: [10.0.0.2/24]
routes:
- to: 192.168.1.0/24
via: 10.0.0.1
metric: 100