Tuesday, January 20, 2015

How to Create Shared Folders with LXC

If you have ever used Shared Folders in either VMWare or Virtual Box,  you might have come to enjoy the ability to access files seemlessly between the Host and the Guest operating systems.

With LXC we can achieve the same thing with a few simple steps.  This method does have some shortcomings that may or not be a show stopper depending on the use case. Personally, I don't like this method but it is handy to know how to do this.

In this example I going going to show how to share a directory between a host and a guest name guest01.

First create the shared folder on the host:

$ mkdir /home/justin/Documents/guest01/

Next, edit the guest's fstab  file to include the following line:

/home/justin/Documents/guest01  /var/lib/lxc/guest01/rootfs/home/justin/Documents/ none bind 0 0  

Next, reboot your container. 

You'll find that you can now share files between your host and guest.

Why I don't like this method

There is two reasons why I do not like this method.  The first problem is that it breaks the isolation the guest and host have to some degree.   One really awesome thing about LXC and the virtualization trend in general is that added layer of security we have by layering our software stack.

The second reason why I do not like this method is that the file ownership and permissions problems that arise because of this solution.   A few other blogs and forum threads recommended using 'chmod -R 7777 ~Documents/guest01' but this is a horrible approach to managing permissions.  This completely clobbers any sane file permissions and allows any user to read and delete those files.

This approach does have it's uses in the right circumstances, like read-only access to a set of files or as a simple way of moving files but please be careful when using this tactic.

No comments: