This guide will walk you through the steps on how to setup a VirtualBox shared folder inside your Ubuntu Server guest.
This guide assumes that you are using the following setup:
- Oracle VM VirtualBox version 6.0.10 with Extension Pack installed
- Microsoft Windows 7 SP1 as the host OS
- A fresh install of Ubuntu Server 18.04.2 LTS as the guest OS
You could still make this guide work with other setups (possibly with some modifications to the commands and whatnot). But if you want to do it the way I did then please feel free to use my setup above.
-
Open VirtualBox
-
Right-click your VM, then click Settings
-
Go to Shared Folders section
-
Add a new shared folder
-
On Add Share prompt, select the Folder Path in your host that you want to be accessible inside your VM. Type
shared
for the Folder Name. Make sure that Read-only and Auto-mount are unchecked and Mount point is blank. Then click OK. -
Start your VM
-
Once your VM is up and running, go to Devices -> Insert Guest Additions CD image
-
Use the following command to mount the CD
sudo mkdir /media/cdrom sudo mount -t iso9660 /dev/cdrom /media/cdrom
-
Install dependencies for VirtualBox guest additions
sudo apt-get update sudo apt-get install -y build-essential linux-headers-`uname -r`
-
Run the installation script for the guest additions. Wait until the installation completes.
sudo /media/cdrom/./VBoxLinuxAdditions.run
-
Reboot VM
sudo shutdown -r now
-
Create
shared
directory in your homemkdir ~/shared
-
Mount the shared folder from the host to your
~/shared
directorysudo mount -t vboxsf shared ~/shared
-
The host folder should now be accessible inside the VM.
cd ~/shared
This directory mount we just made is temporary and it will disappear on next reboot. To make this permanent, we'll set it so that it will mount our ~/shared
directory on system startup
-
Edit
fstab
file in/etc
directorysudo nano /etc/fstab
-
Add the following line to
fstab
(separated by tabs). Make sure to replace<username>
with your username. Save the file.shared /home/<username>/shared vboxsf defaults 0 0
-
Edit
modules
sudo nano /etc/modules
-
Add the following line to
/etc/modules
and savevboxsf
-
Reboot the VM and log-in again
sudo shutdown -r now
-
Go to your home directory and check to see if the directory is highlighted in green.
If it is then congratulations! You successfully linked the directory within your VM with your host folder.
How to point apache's web directory to our folder in the host.
- Remove apache's old
html
directory (WARNING! Backup your data if necessary)sudo rm -rf /var/www/html
- Add a symbolic link in its place
sudo ln -s ~/shared /var/www/html
Note: This setup works fine with Windows hosts. But if you are using Linux or Mac as the host then you may have to set appropriate file permissions on your host directory with chmod in order to make it work.
If you've followed the steps above and it still doesn't work, please let me know by posting a comment below. Please use the following format and be sure to be as detailed as possible so that I can have enough information to help you out.
VirtualBox version: <insert VirtualBox version here>
Host: <OS name> <version>
Guest: <OS name> <version>
Description: <detailed description of the problem>
Do note that I'm mostly a Windows user and I'm not that well versed with Linux but I will do my best to help you out.
@estorgio thank you for your article been using your help, anyway why not use the article as tree branch? so just select branch version 16.04 or 18.04, it will help a lot and also it will be good if the url for this article is clear not hash
@rsyqvthv okay i got it, for those in need for special chmod and chown,
in /etc/fstab
shared /home/<username>/shared vboxsf rw,exec,uid=<youruserid>,gid=<yourusergroupid>,dmode=755,fmode=644 0 0
example :
modul /odoo/custom/addons vboxsf rw,exec,uid=112,gid=115,dmode=755,fmode=644 0 0
dmode = directory mode
fmode = file mode
after that as usual
shutdown -r now
if you check
stat /home/<username>/shared
it will show you the right ownership with your custom user and group also this apply to the folder and also child files or foldershow to find your user id and your group id or user group id, check this: https://kb.iu.edu/d/adwf (i'm lazy to write it LoL)
Note 1:
auto-mount and make permanent doesn't work using multi folder setting, just tested and only work on Transient folder (or maybe I just don't know how to use 'mount points') anyway i just don't thick those two and multi folder sharing worked fineWrite multi line for multi Shared Folders:
i'm using multiple odoo version and it must have their own user:group (defaults, you can customized it, but better leave it as is)
so i need
user name odoo
group name odoo
or at least for best practice not root:root
Note 2:
again something is not right,
virtual box: Version 6.1.6 r137129 (Qt5.6.2)
host: windows 10
guest: ubuntu 18.04.4
if you edit Shared Folder settings while the terminal is on, for some unknown reason the saved path of Transient Folders is gone when you power down terminal (never happen on latest v5.x and v6.0 vbox).
so have to save while terminal is off and you can tick the auto mount option to use Machine Folders mode