Virtualbox: Mount a shared folder in Guest FreeBSD from Host Ubuntu

17,634

Solution 1

Samba

It is possible to mount either a shared FreeBSD folder or a shared Ubuntu folder with samba. Both ways work. Either case you need to configure a share folder (you mentioned you used the Ubuntu GUI to do that) and then on the other machine you need to mount the share using the correct IP and making sure that both the Guest and Host are on the same network or using port forwarding in case you had NAT configured.

Because there is too many solutions, I am not going to list them all here. Please could you provide more information regarding the network configuration of your Guest OS? What settings did you use when creating the VM? Do you use NAT, Bridge, Host-only or Internal Network? I'm going to provide you with one example which assume that your guest is able to view on the network your host (for example, you have one network card defined as host-only).

First share a network folder on Ubuntu as you did. Make sure to create a user account in Samba on the Ubuntu host or that guest access is possible (e.g. sudo smbpasswd -a <username> to give access to a user, replace by the username.

Then on FreeBSD, mount the Ubuntu share by using the correct IP address (10.0.0.2 is probably the one for your NAT "router" created by VirtualBox and therefore it probably won't work), for example either use the Ubuntu IP address on your LAN (e.g. 192.168.1.x) or the one that was defined for the host-only interface. Then your mount_smbfs command will succeed:

mount_smbfs -U <username> //<correct IP>/sharedfolder /home/user/shared

vboxsf

When vboxsf gets supported by FreeBSD (thanks Alexander for pointing that out) and if you want to use VirtualBox builtin share mechanism with vboxsf, you need to install the Guest Additions in the Guest OS (some FreeBSD in your case). Usually this is done via the VirtualBox menu under Devices, there is a shortcut to Install Guest Additions....

However, for FreeBSD you have to do it differently. They have a dedicated documentation for this:

Once the Guest Additions installed, you can use the mount command with the vboxsf filesystem. You need however to share a folder using VirtualBox share folder mechanism, see under VirtualBox's Devices menu the item Share Folders.... Note that the name you will give to the share in this menu will be the name of the "device" you give to mount.

Solution 2

As pointed out at another topic,

Shared Folders for FreeBSD guests are not supported yet [...] There is some draft code and a kernel module for it but it's not working yet.

That is as of Jun 24, 2014.

Solution 3

There is a port available on github:

https://github.com/lwhsu/freebsd-vboxfs

It is tested to work successfully on FreeBSD 11.0-RELEASE-p1.

Solution 4

As of today (2020-05), all ways to mount host folders using native vboxvfs formally work:

mount_vboxvfs -w myshare /mnt
mount -t vboxvfs myshare /mnt

The only problem here is the result is very unstable (host used was FreeBSD 12). I've tried different combinations of guest OS versions (FreeBSD 11 and 12), host I\O cache flag in controller settings, read-only mount flags etc - nothing brings stable work. Files appear\disappear, you will see all kind of glitches like e.g. folder behaves as a file etc. I've got many kernel panics in guest OS too.

So the only valid way to share folder from host OS to "FreeBSD Guest" is using NFS. This works really great, without issues so far.

Share:
17,634

Related videos on Youtube

Bernhard
Author by

Bernhard

Updated on September 18, 2022

Comments

  • Bernhard
    Bernhard over 1 year

    I have Ubuntu 12.10 as Host OS and FreeBSD 9 as Guest OS in Virtualbox 4.1.18. I have Samba installed in both Ubuntu and FreeBSD and shared a few folders from virtualbox, also ticking the automount option.

    I have also done right click and share in Ubuntu. But when I try to mount in FreeBSD using

    mount -t vboxfs sharedfolder /home/user/shared`
    

    it says sharedfolder operation not permitted. I also used

    mount_smbfs //10.0.0.2/sharedfolder /home/user/shared
    

    but I get can't get server address

    How to share folder/files between Host Ubuntu and Guest FreeBSD from virtualbox ?

    • peterph
      peterph about 11 years
      Do you have any reason for not using NFS?
    • Admin
      Admin about 11 years
      NFS ??? How to ? or is it installed by default ?
    • peterph
      peterph about 11 years
      Network File System should be installed by default and if not, you can install it as any other packages. It is the most prominent network file system for Unices.
    • user3811206
      user3811206 almost 9 years
      BTW, most likely sharedfolder: Operation not permitted means that only root can do that.
    • John Smith
      John Smith almost 9 years
      "Shared Folders for FreeBSD guests are not supported yet" - see my answer below
  • Admin
    Admin about 11 years
    I use NAT, the default network for GuestOS. I tried with mount vboxsf even with su, but no any luck. I have shared folder under virtualbox shared mechanism, settings and Shared Folders and gave name sharedfolders for the ones that I wanted to share. I also used automount option available while sharing using virtualbox.
  • Huygens
    Huygens about 11 years
    @JhilkeDai As I said, you can only used the vboxsf and Shared Folder if you have installed the Guest Additions inside the Guest OS, for which I gave you a few links. Did you install them? For Samba, try to use "Bridge" mode, share a folder on the Host (Ubuntu) and try to access it from the Guest (FreeBSD) using smbclient -L <ubuntu hostname>.
  • Admin
    Admin about 11 years
    yes, the Guest Additions were the trick in GuestOS, I never guessed it could be like that, neither I understand how it works. But it works :D
  • Huygens
    Huygens about 11 years
    Adding the Guest Additions is like adding a set of new drivers to your Guest virtual machine. For an analogy in non-virtual environment, it is like installing a Graphic card without the drivers, you do not have access to all possibilities. Once you install the drivers you can get all features because the OS is aware of them and offer to make use of them to users.
  • Abel Cheung
    Abel Cheung almost 9 years
    It is very interesting how this standard boilerplate answer which is actually completely false for virtualbox shared folder managed to become accepted answer.
  • Huygens
    Huygens almost 9 years
    @AbelCheung as you are so kind of telling me I'm wrong, please prove me so and provide an alternative answer. I'm curious to learn new stuff.
  • Huygens
    Huygens almost 9 years
    OK I've read the other answer. So vboxsf is not supported on FreeBSD. I will update my answer.
  • Abel Cheung
    Abel Cheung almost 9 years
    Sorry for being harsh, I have been bitten badly after trusting the answer and spending lots of time trying to use it until reading the other answer.
  • Mikhail T.
    Mikhail T. over 6 years
    Says "not fully working" on the GitHub. And hasn't been updated since January 11 -- the day after you posted your answer :)