Lvm – Easy way to transfer files between host and LXC container on LVM

file-transferlvmlxc

This is an easy task in the case of containers that share the same filesystem but I'm not sure what would be the proper approach for containers that use LVM disks.

I know I could use rsync or scp but I would like to know if it is possible to do this without setting up ssh/ftp/http servers. Additionally, it would be nice to be able to transfer the files without modifying container's config since it would require a container restart. It would be a good idea to avoid persistent mounted shared folders since these might bring a potential security risk (easy mount/umount option should be available).

An option that popped up in my mind would be to use a WebDAV server on the host and mount it in the container but I haven't yet analyzed it and I'm not sure about the performance penalty that it might bring. Other option that I though of is to mount the LVM partition on the host but I'm not sure whether this is safe.

Update

In my configuration I'm creating the containers using the following command:

lxc-create -t ubuntu -n "${NAME}" -B lvm --vgname lxc-vg --fssize "${SIZE}"

I'm using the default configuration except for the autostart feature which is achieved by adding the following lines to /var/lib/lxc/${NAME}/config file:

lxc.start.auto = 1
lxc.start.delay = 0

Best Answer

Revised answer: LXC containers share the same kernel as the host, so any filesystem they mount should be accessible from outside.

If you do a cat /proc/mounts on the host, can you see the container filesystems?

If you see a line like /dev/mapper/... /var/lib/lxc/o1/rootfs ext4 ... then you should be able to access /var/lib/lxc/o1/rootfs from the host, without any further commands.