Home > Virtualization > Accessing host filesystem from VirtualBox guest

Accessing host filesystem from VirtualBox guest

I came into this world
A screaming infant
(Iced Earth – Life and death)

VirtualBox is a greate piece of software for desktop and workstation virtualization. I use it for both testing and production environments – if it is applicable in the latter.

One good idea for VirtualBox is if you are web/app developer for Linux and you want to keep Windows as your primary OS. One can install Linux distribution of choice in VirtualBox VM and reap both benefits of Windows as primary os (gaaameeees) and Linux as a server platform.

So why am I blogging about something that seems to work? Devil is in the details… “it seems to work” is crucial.

There are 3 ways AFAIK of sharing files between Win host and Linux guest:

  • keep files in guest (Linux) and share with host through Samba
  • keep files on host (Win) and use VirtualBox Shared Folders
  • keep files on host (Win) and mount CIFS from within guest

For someone like me, an experienced Linux sysadmin, first step is the easiest. But it has it’s drawbacks too. For example – I don’t wanna keep files in VM, in case of corruption of VM, reinstallation, or whatever. I want them on native Windows disk. So first option is clearly out.

Shared Folders are really great idea. You set folder in settings of a VM, start it up, install VirtualBox Guest Additions (which bring mount.vboxsf binary and vboxsf kernel module), mount it in guest and voila! But there’s a catch – performance. Shared Folders are really really slow… which in turn kills the idea of programming and testing code without loosing hair because of the slowness.

Analyzing the performance, it’s obvious that kernel spends really large amount of time in IO mode – so vboxsf emulation is behaving something like ZFSonLinux or FUSE… And we don’t like that, do we 😦

It seems that only viable solution is sharing folder though Windows, and mounting it via CIFS….

I did some tests, to show the performance difference. There are three directories I do my tests on:

  • /var/www/repo            ( vboxsf )
  • /var/www/repo2          ( local disk )
  • /var/www/repo3          ( windows export )

I’m doing 2 tests – find and du -sh on a 500MB svn working copy. Also I drop all caches before every test. Here are the results of vboxsf mounted test:

# time find /var/www/repo
real 2m8.864s
user 0m0.200s
sys 0m14.638s

# time du -sh /var/www/repo
592M    /var/www/repo
real 0m24.951s
user 0m0.340s
sys 0m4.859s

Next, the folder mounted via CIFS (windows share/export):

# time find /var/www/repo3
real    0m23.844s
user    0m0.280s
sys     0m1.590s

# time du -sh /var/www/repo3
653M    /var/www/repo3
real    0m3.903s
user    0m0.060s
sys     0m0.330s

Notice the difference in size, not to mention the 10 fold increase in speed… And finaly as a reference, tests of files stored localy on ext3 partition in guest:

# time find /var/www/repo3
real	0m29.775s
user	0m0.180s
sys	0m2.500s

# time du -sh /var/www/repo2
719M	/var/www/repo2
real	0m15.032s
user	0m0.530s
sys	0m0.640s

Notice once more increase in size. Clearly, CIFS mounted Windows exports win… Only drawback – you cannot do symlinks on them.

Advertisements
  1. Mark
    October 28, 2013 at 10:12 pm

    You also can’t do symlinks in a shared folder.

    • October 28, 2013 at 11:06 pm

      Indeed, but you can simulate symlinks by doing mount -t bind (for directories at least) 😉

    • February 7, 2014 at 1:50 pm

      not true. you need a recent virtualbox and the secret configuration command (and then reboot the host os)

      • February 7, 2014 at 2:00 pm

        Can you point us to a documentation link proving you’re right?

  2. Adam
    November 26, 2013 at 10:05 pm

    I have extreme slowness with the vboxfs so this is great. But, is there a tutorial on how to set this up?

  3. November 26, 2013 at 10:26 pm

    There isn’t one but I promise to write one in a matter of days if you’re interested?

  4. November 26, 2013 at 10:33 pm

    Yeah but this is for Linux guest on Linux host. I was thinking that you need one for Linux guest on Windows host 🙂

    • Adam
      November 26, 2013 at 10:35 pm

      You are correct. I need linux guest to windows host. Hmmm.. You can delete that comment so it doesn’t confuse people if you like. 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: