Hike Nalbandyan
Hike Nalbandyan

Reputation: 1056

Sharing ubuntu 16.04 vm folder with mac os (with samba)

I followed million tutorials and guides on how to do it but no luck... Something is missing, hope you guys can help me out.

My OS: macOS Sierra
Virtualbox OS: Ubuntu 16.04
VM Network Adapter: Bridged Adapter

These are my steps:

  1. Connect to vm via ssh

  2. Install samba
    $ sudo apt install samba

  3. Create a directory to be shared
    $ sudo mkdir /media/testshare

  4. Add new share to smb.conf
    $ sudo vim /etc/samba/smb.conf

    [testshare]
    comment = My Shared Folder
    path = /media/testshare
    browseable = yes
    readonly = no
    guest ok = yes

  5. Restart samba

  6. Add a samba password
    $ sudo smbpasswd -a {username}

  7. Try to connect from mac: In Finder, Command+K to open "Connect to Server" and in Server Address: smb://192.168.0.104

I'm getting this:enter image description here

I tried smb://192.168.0.104/testshare, smb://192.168.0.104/media/testshare

I have no idea how to make it work. Help!

EDIT:

Might help, this is what I get when I run
$ sudo netstat -tulpn | egrep "samba|smbd|nmbd|winbind": enter image description here * I know that the ip is different now (192.168.0.104 => 192.168.0.109), its a new vm, don't pay attention to that.

Upvotes: 0

Views: 4049

Answers (1)

Ukr
Ukr

Reputation: 2704

Host OS: macOS El Capitan
VM (guest) OS: Ubuntu Server 16.04.5 LTS
VirtualBox v5.2.18
Both host OS and guest OS must have same user (further in the text: username).

Stage 1: Install VirtualBox Guest Additions:

1.1. Locate the VirtualBox Guest Additions,

$ cd /Applications/VirtualBox.app/Contents/MacOS/
$ cp VBoxGuestAdditions.iso ~/Downloads/

1.2. Start the VM

1.3. Click the CD icon in the bottom right task bar

1.4. Select "Choose disk image..."" and search for the VBoxGuestAdditions.iso

1.5. In the guest terminal type (you can also do this from the host terminal if you SSH into it):

$ sudo su
$ apt update
$ apt upgrade
$ apt-get install dkms build-essential linux-headers-generic gcc make
$ mount /dev/cdrom /mnt
$ cd /mnt
$ sh ./VBoxLinuxAdditions.run
$ reboot

Stage 2: Shared Folders Setup:

2.1. Create rules in VM:

  • Stop the VM
  • Go to Settings > Shared Folders
  • Click in the Add new port forwarding rule green button in the top right of the window.
  • Search and select the folder you would like to share (e.g.: /path/to/shared/host_folder)
  • Select the Auto-mount and Make Permanent options
  • Start the VM

2.2. To mount shared folder on /opt you must create shared_folder_dir subfolder and set appropriate permissions to it:

$ sudo mkdir -p /opt/shared_folder_dir
$ sudo chmod ug+w -Rv /opt/shared_folder_dir
$ sudo chown username:username -Rv /opt/shared_folder_dir

2.3. Add username to the vboxsf group:

$ sudo adduser username vboxsf
$ sudo usermod -a -G vboxsf username

2.4. Reboot VM to apply changes:

$ sudo reboot

Stage 3: Auto mounting host_folder into /opt/shared_folder_dir:

3.1. Change VM's /etc/rc.local:

$ sudo nano /etc/rc.local

and place following right above exit 0:

# 'folder_name' = given in the shared folders configuration
# 'path/to/shared/folders' = guest path to access the shared folders from
# 'id' = prints uid/gid
# sudo mount -t vboxsf -o uid={uid},gid={gid} {shared_folder_name} {path/to/shared/folder}
sleep 5
sudo mount -t vboxsf -o uid=1000,gid=1000 host_folder /opt/shared_folder_dir
exit 0
<<< EOF >>>

Note: I've added sleep 5 to execute mount operation after VirtualBox Guest Additions has started. You can check that by journalctl -b command.

3.2. Reboot VM to apply changes:

$ sudo reboot

See also

Upvotes: 3

Related Questions