How to mount an nfs share inside an lxc container

Mattias Hedman

Well-Known Member
Jan 19, 2019
120
10
58
54
I have googeled and tried more than one solution but none seems to work.
I have edited apparmour, added mp0 to the lxc config, fiddling with other things inside lxc 100.cfg.
None seems to do what I want. Can it be that hard to mount an nfs inside an lxc container?

Got a container running Centos7.
 
I have googeled and tried more than one solution but none seems to work.
I have edited apparmour, added mp0 to the lxc config, fiddling with other things inside lxc 100.cfg.
None seems to do what I want. Can it be that hard to mount an nfs inside an lxc container?

Got a container running Centos7.
Came across your question. I have Jellyfin in a lxc container on Ubuntu, so not strictly Proxmox, but I don't see why it wouldn't work. My Video files are on a separate drive and I just need Jellyfin to read and play them. The following command line on the host Ubuntu 20.04 allows that:

lxc config device add MrJelly shared_dir disk path=/home/ubuntu/Videos source="/media/gort/black_drive_2/Videos/DVDs"

MrJelly: Is the name of the container for jellyfin

shared_dir: Any made up device name to implement the share

path=/home/ubuntu/Videos: Is a the reference directory for Jellyfin to find videos within the container (default user name being "ubuntu")

source="/media/gort/black_drive_2/Videos/DVDs": The location of the host video files

Works something like a symlink. Not sure if you can change the permissions on the host directory it would allow write access, as I haven't tried it, but it works fine readonly. You can create more than one link. Just change the shared_dir device name parameter and the path=/home/ubuntu/Videos to something different.

Good luck with your project, hope the above helps you out.
 
Last edited:
Using privileges LXCs using SMB/NFS shares is easy. You just need to enable the "allow CIFS/NFS" feature using the GUI for the LXC.
The problem are unprivileged LXCs where this feature is forbidden. But the bind-mount workaround oguz mentioned is still working.
 
Hi Everyone.

I'm trying to also give access to an NFS share inside the LXC.
I followed oguz recommendation and created the NFS mount on host then use the following command to add it to the LXC:

pct set 205 -mp0 /mnt/bindmounts/shared,mp=/shared

But this caused Snapshot feature to be disabled "The current guest configuration does not support taking new snapshots".

I tried adding It with the backup=0 flag:

pct set 205 -mp0 /mnt/bindmounts/shared,mp=/shared,backup=0

But still no luck. I really wanted to use the Snapshot in this LXC. Any workaround for this?

Thanks.

Proxmox: 7.1-7
 
Thank you for your suggestion.

If I use the LXC NFS direct mount method, Snapshots will work as intended?
 

Absolutely agree. Resharing in case the original goes away.


#TL;DR​

How do you mount NFS shares inside an LXC container?

  1. Create a privileged LXC container, using any guest distribution of your choosing
  2. Once created, modify the config file (/etc/pve/lxc/<id>.conf on Proxmox) and add features: mount=nfs
  3. Restart the container
  4. Mount your data (e.g. mount -t nfs 192.168.1.1:/data /mnt/data)
 

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!