[SOLVED] [P] Mount host directory inside LXC container not possible

cmonty14

Well-Known Member
Mar 4, 2014
343
5
58
Hi,

I have configured a container running OpenMediaVault. This NAS software should have access to directories /mnt/<dir> on the host.

I found this blog posting providing some information on this topic.
Basically it instructs to edit /var/lib/lxc/<container-name>/fstab and apend a line
Code:
/path/to/host/directory path/to/container/directory none bind,create=dir

I entered the container and modified /etc/fstab accordingly:
Code:
root@vm102-omv:~# cat /etc/fstab
# UNCONFIGURED FSTAB FOR BASE SYSTEM
/mnt/bilder mnt/bilder none bind,create=dir
/mnt/dokumente mnt/dokumente none bind,create=dir

But inside container I cannot read/write any file in the directories.

Another question in that context:
Where are all the files / directories that belong to a container stored?

Any advice for solving this issue is appreciated.


THX
 
Last edited:
Hi

Where are all the files / directories that belong to a container stored?

LXC Container are stored as loopback iamges, basically a big file containing the filesystem of the container. This allows for instance to move the container to a LVM transparently for instance.


For instance let us suppose I want to find where the loopback image of my CentOS container:

Code:
# list all my LXCs
pct list 
VMID       Status     Name                
[B]103[/B]        running    [B]centos6[/B]             
111        stopped    lxcdeb8

Code:
# I know my container is stored on the storage I called 'nfs-write'
pvesm list nfs-write | grep 103
nfs-write:103/vm-103-rootfs.raw                             raw 8589934592 [B]103[/B]

Concerning your mount problem, if your have ressources in your host that you want to access in your guest I would try to do some USB or PCI pass through with a kvm guest rather that using LXC.
 
The developers of LXC have implemented a solution for mounting host directories inside a container.
Therefore I don't understand why this should not be available in Proxmox VE.
 
Hi,
first at all PVE is beta and so many things are not implemented.
It is possible to use dir as rootfs.
http://forum.proxmox.com/threads/22736-directory-based-storage-in-lxc

Can you confirm that directory based storage in lxc is only available with ZFS?
I guess no, but I don't fully understand this posting.

Could you please share some more information?

BTW, where should I post feature requests for Proxmox PVE 4?
I consider this issue not as a bug but rather as a feature request.

THX
 
I have a look in the source and it is implemented only for zfs.
We will discuss if we implement this for rootfs.
what we will implement is multiple disk support.
feature request here at the forum is fine or you can make it on the devel, user list.
http://pve.proxmox.com/cgi-bin/mailman/listinfo
 
I have a look in the source and it is implemented only for zfs.
We will discuss if we implement this for rootfs.
what we will implement is multiple disk support.
feature request here at the forum is fine or you can make it on the devel, user list.
http://pve.proxmox.com/cgi-bin/mailman/listinfo

Well, I understand your response that you would take ownership of this request.
Therefore the additional request on the developers list would generate more confusion sharing this request to the developers community?
Would you agree?

And do you confirm that the workaround introduced in this posting won't work?
 
Last edited:
I guess the easiest way to support the standard LXC way is to mount the rootfs on the host into LXC's standard directory instead of changing lxc.rootfs to the image file in the PVE code.

In the mean time a dirty hack you can always use is using sshfs from guest to host, but the guest needs to have an ssh-user on the host for this.
What I miss in linux is a filedescriptor based mount. An fmount system call. You can already pass filedescriptors over sockets, so this would allow bindmounts to cross namespaces easily.
 
I guess the easiest way to support the standard LXC way is to mount the rootfs on the host into LXC's standard directory instead of changing lxc.rootfs to the image file in the PVE code.

In the mean time a dirty hack you can always use is using sshfs from guest to host, but the guest needs to have an ssh-user on the host for this.
What I miss in linux is a filedescriptor based mount. An fmount system call. You can already pass filedescriptors over sockets, so this would allow bindmounts to cross namespaces easily.

I tried to use the workaround with sshfs from guest (=container) to host.
Therefore I installed packages
sshfs and
fuse-utils
but I get this error message:
Code:
root@vm102-omv:~# modprobe fuse
libkmod: ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file '/lib/modules/3.19.8-1-pve/modules.dep.bin'

If I cannot troubleshoot this issue I cannot use this workaround.

THX
 
Looks like you tried to load the fuse module on the guest, but since it shares a kernel with the host, you have to load it on the host instead.
 
Just out of curiosity, what is your use case here, are your trying to add a usb hard disk in openmediavault ? ( since you were talking about sharing the /mnt dir from the host ..)
 
Just out of curiosity, what is your use case here, are your trying to add a usb hard disk in openmediavault ? ( since you were talking about sharing the /mnt dir from the host ..)

Please check my first (initial) posting.
 
Looks like you tried to load the fuse module on the guest, but since it shares a kernel with the host, you have to load it on the host instead.

On the host the package fuse exists:
Code:
user@pc3:~$ apt-cache policy fuse
fuse:
  Installiert:           2.9.3-15+deb8u1
  Installationskandidat: 2.9.3-15+deb8u1
  Versionstabelle:
 *** 2.9.3-15+deb8u1 0
        500 http://ftp.de.debian.org/debian/ jessie/main amd64 Packages
        500 http://security.debian.org/ jessie/updates/main amd64 Packages
        100 /var/lib/dpkg/status

But it looks like that I cannot load the module:
Code:
user@pc3:~$ lsmod | grep fuse
1 user@pc3:~$ sudo modprobe fuse
user@pc3:~$ lsmod | grep fuse
1 user@pc3:~$

What is wrong here?
Should I enter "fuse" in /etc/modules?
 
for what its worth:

so when you end up editing the config file, and then starting the ct and the config jumps back to the version of before, you know your working the wrong file.

or, for google purposes: lxc.mount.entry keeps disaperaing from config file this is all about mounting an host dir inside a proxmox lxc container. this is a working solution for 5.2-9 pve

in proxmox pve 5 you have to edit not the lxc config file (this one: /var/lib/lxc/#ofcontainer/config) but you have to edit /etc/pve/lxc/#ofcontainer.conf

just add as last line:
Code:
lxc.mount.entry = /path/of/folder/on/host path/to/mount/point/in/container none ro.bind,make=dir 0 0
in my case it was
Code:
lxc.mount.entry = /mnt/backups/dump home/omv-backup/dump none ro,bind,make=dir 0 0

while /mnt/backups/dump is my proxmox scheduled backup location
and home/omv-backup/dump points to the home dir of the omv-backup user inside the container
read only as I only suck those backups to an other machine and dont want anybody able to write to my host
make=dir as i am lazy to prepare the dir in the container, it just makes the /dump dir, obvisiously this should not exist inside the container!

cheers and have fun.

this is the summary of about 8h of what ever this was at this time of day.
mostly due to outstanding documentation of this featrure, maybe a bit of a lack of coffee too.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!