[lxc-users] Establish a bind mount to a running container

Stéphane Graber stgraber at ubuntu.com
Fri Oct 7 09:45:46 UTC 2016


On Fri, Oct 07, 2016 at 07:03:21AM +0000, Jäkel, Guido wrote:
> Dear experts,
> 
> I wonder if it's possible to establish a bind mount filesystem resource from the LXC host to an already running container in an manual way, but analogous as it is done at startup time. 
> 
> I already figured out that the releasing an existing link is no thing; just umount it from inside the container. But is there a way to establish one while shifting the destination of a bind mount into the right namespace?
> 
> I ask about, because in a couple of days I have to change a (NFS) filesystem source (because of an hardware migration) that is common to a large number of running containers but not frequently used and I want to avoid to restart all the containers with it services.
> 
> thank you for advice
> 
> Guido

It's very difficult due to a number of restrictions in place in the kernel.

The only way of doing this that I'm aware of is what we do in LXD. We
create a path on the host before the container starts, put that on a
rshared mountpoint, then bind-mount that directory into the container
under some arbitrary path.

Then when you want to inject a new mount in the container, you can mount
it in a sub-directory of that path you create on the host, which will
then have the container inherit the mount entry thanks to the host
mountpoint being rshared and the container's mountpoint being rslave.

Once the mountpoint shows up in the container, you can then move it to
whatever path you actually want it on.



LXD abstracts this rather nicely as you can do:

    lxc config device add <NAME> home disk source=/home path=/mnt/home

Which will do all the magic mount manipulations for you, resulting in
/mnt/home in the container being a bind-mount of /home on the host.

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20161007/e53304a4/attachment.sig>


More information about the lxc-users mailing list