0

I have an LXC container, where I setup the fstab to use a directory situated on an external usb disk. I need this because I use this container for disk intensive computations on my laptop, and I need to keep being able to work on it.

If I unmount the disk on my host system and then remount it (plug-in / plug-out), or simply the systems goes to sleep, then inside my container I am unable to access the mounted point again (io error)

I can understand it does not work out of the box, but what bother me is that I didn't find out how to remount the shared directory : I can unmount it from inside the container, but then how do I remount it. All the docs is about using lxc.mount or fstab to mount those directory which is ok if you restart the container, but I was unable to find a doc on how to mount a shared directory live on a running lxc container.

  • I would suggest sharing the parent directory of the mounted device. Eg if you would want to share /media/stuff with your container, perhaps instead share /media or cause the device to be mounted as /media/containerX/stuff and share /media/containerX. That should be enough to keep the directory /media/containerX being consistent between insertions of the device. – Cameron Kerr Jun 01 '15 at 10:21
  • Hello, your idea is good but it means giving full access to the disk to the container. – alex garel Jun 07 '15 at 12:43
  • Not if you control where the disk is mounted. – Cameron Kerr Jun 07 '15 at 18:36
  • Could you explain ? What I mean is you have to give full access to the mounted disk (and not just a directory within it). – alex garel Jun 07 '15 at 22:03
  • Ah, I see what you mean. Yes, that would be true. – Cameron Kerr Jun 08 '15 at 00:06
  • Finally I used your technique but adding a bind mount of a folder of my device within a folder mounted in the lxc machine. So I can give access only to the folder I want. – alex garel Jun 16 '15 at 10:19

1 Answers1

0

This is what I finally did :

The disk mounts in : /mnt/disk I want /mnt/disk/myfolder to be accessible in LXC container as /home/user/ext/myfolder

So I create a folder /mnt/lxc-ext/myfolder and made lxc-ext accessible to lxc via the container fstab (provided the lxc.aa_profile = lxc-container-default-with-mounting option on ubuntu):

/mnt/lxc-ext /home/user/ext none bind 0 0

So each time I plug the disk in I do a bind mount of the target folder in /mnt/disk/myfolder:

sudo mount -B /mnt/disk/myfolder /mnt/lxc-ext/myfolder

And it works like a charm, no more IO errors.