How to create Virtualbox shared folder between Windows host and Ubuntu18.04 guest machine

14,090

After a whole day of trying different solutions I finally found the missing ingredient. But I'm gonna repeat my topic content partially and put here step by step instruction for someone struggling with this task like me.

We suppose that we already have the Ubuntu 18.04 VM installed and the linux user "myusername" with sudo permissions on this machine.

So, to share folder D:\test (just as an example) on Windows host machine to Ubuntu 18.04 Virtualbox's guest machine (it's content should be available in /home/myusername/test directory) we make these steps:

1) Start Ubuntu VM from VirtualBox interface

2) Open "Shared Folder Settings" in the "devices" submenu of the started Ubuntu VM window's upper menu and set the shared folder name as "test" and the path as "/home/myusername/test" and fill the checkbox "Make Permanent"

3) Install virtualbox-guest-dkms and virtualbox-guest-utils packages to Ubuntu VM with the package manager.

sudo apt-get update
sudo apt-get install virtualbox-guest-dkms
sudo apt-get install virtualbox-guest-utils

4) Create a directory /home/myusername/test on your Ubuntu VM

mkdir /home/myusername/test

5) Restart Ubuntu VM

reboot

6) After rebooting mount shared folder in Ubuntu VM with command

mount -t vboxsf test /home/myusername/test

7) Check files in your /home/myusername/test directory, they should be the same files which are located in your Windows D:\test folder

ls /home/myusername/test

8) Additionally you can make this shared folder auto mounted after rebooting, to do so you need add the next line to your ubuntu user's /home/myusername/.profile file:

echo "sudo mount -t vboxsf test /home/myusername/test" >> /home/myusername/.profile

and give your user permission to mount without entering password with opening "sudo visudo" command (which is used to change the /etc/sudoers file) and add the next line:

myusername ALL = (ALL) NOPASSWD: /bin/mount

That's it, after these steps I've managed to share files from Windows host to Ubuntu guest machine. I'd like to mention that the shared directory itself and all files inside it belong to root but has 777 rights so there is no problem using them as any user can do whatever he wants with them.

Share:
14,090

Related videos on Youtube

AndreyKo
Author by

AndreyKo

Updated on May 21, 2022

Comments

  • AndreyKo
    AndreyKo almost 2 years

    I've read docs and all questions about sharing folder from host machine to Virtualbox's guest machine and still can't get it working. In my case the host is Windows machine and guest is Ubuntu18.04 server machine.

    What is advised and what I've already tried:

    1) In the VM's menu I found 'devices' submenu and clicked 'Insert Guest Additions CD image' option after which the CD icon in the status bar was lit and shows that the CD is inserted and the path to iso is C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso (I checked that file really exists there).

    2) In the same 'devices' VM's settings submenu I opened 'Shared Folder Settings' and added shared folder with name 'test' and path 'D:\test' which leads to the folder on my D: disk which contains test files.

    3) I reboot my Ubuntu VM and look into /media directory expecting to find /media/cdrom directory or something like this with file VBoxLinuxAdditions.run in it, which should be run according to docs. But /media directory is empty so I have nothing to do with it. I looked for this file into other directories but had no success.

    After that I tried to install Virtualbox-guest-additions from repository as was advised on ubuntu forum:

    sudo apt-get update
    sudo apt-get install virtualbox-guest-dkms
    

    And checked that the package was installed with command:

    lsmod | grep -io vboxguest
    

    But when I rebooted and tried to mount the shared folder with:

    mkdir -p /home/myusername/test
    sudo mount -t vboxsf test /home/myusername/test
    

    I've got error:

    mount: /home/myusername/test: wrong fs type, bad option, bad superblock on /home/myusername/test, missing codepage or helper program or other error.
    

    I see there is no /sbin/mount.vboxsf link present, I'm not sure if this is a problem, also I tried add my user to 'vboxsf' group with:

    sudo usermod -a -G vboxsf myusername
    

    but the group was not created too.

    What am I missing, what is the way to make it work?

  • Mukesh
    Mukesh about 5 years
    Hi @AndreyKo after 3 days of struggle your answer helped me to auto mount the Windows folder on Ubuntu18.04 using VirtualBox 6.0.6
  • AndreyKo
    AndreyKo about 5 years
    Great! That's why I left it here.
  • Pete Dermott
    Pete Dermott almost 5 years
    Brilliant! This helped me massively. One other thing to note is that you need to create the /home/myusername/test directory in your VM before trying to do this.
  • AndreyKo
    AndreyKo almost 5 years
    Thanks, Pete! You are absolutely right, I've forgotten to mention this, I'll add this to my answer.
  • Mukesh
    Mukesh almost 4 years
    @AndreyKo Your answer helped me in the past. This time I tried these steps on a VM with Ubuntu20.4 but I am facing some issues with permissions. If you can help me with magento.stackexchange.com/questions/318849/…
  • hamidi
    hamidi about 3 years
    Thanks. Everything is ok, but the owner changed after mount. Since root has done the mount, owner of /home/myusername/test changes to root. How can I change it to uid 1000?
  • hamidi
    hamidi about 3 years
    Files permissions are the same as the host, but owner differs. Owner of the files in guest are root and owner of the files in host are the default user.
  • Konrad Weber
    Konrad Weber about 3 years
    Thanks, I had in addition trouble with the installation of the Guest Additions. This link helped a lot osboxes.org/guide