Is there a way to mount a directory residing on my VB guest (linux) on my host (linux)? I know I can do it the other way around with the shared folders feature on Virtualbox, but is there a way to do it this way?

I'd really like to actually mount the directory. Not use samba, or something similar to that.


The short answer is that you can't.

When you mount a directory from the host inside the guest, here's what happens. VirtualBox comes with a filesystem driver for the guest OS that stores files by going through a special VM interface rather than directly accessing a storage device. The VirtualBox process on the host interprets the requests that come through the interface by making garden-variety user-level filesystem accesses.

Now consider the symmetric situation. You want to access files on the guest. Ok, then VirtualBox should come with a driver for the guest that handles filesystem queries coming through a VM interface. There would have to be a kernel component (because a VM interface looks like hardware to the guest OS) and optionally a user-land component to actually access the files (not necessarily, this is similar to an server NFS which can be done in the kernel or in userland (an NFS server's front end goes through the network, so that bit is doable in userland)). Then, on the host side, you would need a filesystem driver that communicates through the VM interface. Filesystems are normally handled by the kernel, but they can be mediated to a user process (that's what FUSE does). So a special-purpose filesystem would be possible, but more involved than in the symmetric case. There's also a lot less demand for it. As far as I know, there's no such special-purpose filesystem for any of the major VM implementations.

I'm afraid you'll have to use a networked filesystem such as NFS, Samba or SSHFS.

  • Thanks. It's not really worth my time to go into it that much further at this point. I was just hoping for a quick and dirty method, even if it was a loopback mount or some other nonsense.
    – Falmarri
    May 25 '11 at 23:31

Gilles correctly points out the theoretical problems with doing this and notes that there are no current implementations.

The exception would be if you used fixed sizes storage devices AND you are ok with mounting the whole drive while the virtual machine is turned off. In that case this bash script will allow you to mount the VDI disk image file as a drive. You will find lots of information the topic of mounting VDI disk images.

  • That assumes only one concurrent access at a time, right? I mean, I can't mount it, then run the VM. I know there are crazy things I can do, like mount the disk image and possibly use a unionfs. But again, not worth it. The whole point I was going for was to avoid installing KDevelop on my virtual machine =P
    – Falmarri
    May 27 '11 at 21:04
  • Get over it already, if that's the motivation I promise it isn't worth it, just install the software you need in the VM, and if you need to share files setup proper file sharing using either host folder sharing or a network based file system. Seriously :)
    – Caleb
    May 27 '11 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.