[SOLVED] Can I bind-mount a directory into a running lxc?

n0x0n

Member
Jan 20, 2022
32
2
13
Hi, well, the title says it all: Can I bind-mount a directory into a running lxc?
 
Hi,
I would've guessed the behavior would be the same as for volume mount points, but in fact, mounting into a running container is not yet handled for bind and device mounts. So thanks for the report :)! I sent a patch that should make it work in a future version.
 
Hi Fiona, that's great, thank you very much.
Would you like me to test that patch (currently running 7.2-7)?
Would it be sufficient to patch /usr/share/perl5/PVE/LXC/Config.pm, or would I need to do something else?
 
Sure, more testing never hurts! Patching the file is enough if you use pct, changes are picked up immediately then. To have the API daemons reload the module, use systemctl reload-or-restart pveproxy.service pvedaemon.service. If you want to go back to the packaged version, you can use apt install --reinstall pve-container.
 
Applied patch and tested.

Testcase 1: Mounting a host directory into running LXC using pct set 100 -mp0 /mnt,mp=/media/usb. If not existant, the mountpoint is immediately created and the host directory is mounted into the LXC. Very nice!

Testcase 2) Mounting a host directory into running LXC using the webgui. Couldn't test that, because I don't know how. I can only add storage 'local-vm' and not a host directory to bind mount.

Wanted to also test unmounting but became aware that I don't know how to do that, either. Is there an option in pct to unmount a mountpoint from a comtainer?
 
Yes, creating bind and device mounts is a rather advanced feature and not exposed in the web UI. IIRC, it's also root-only for security reasons.

When you remove a mount point with pct set -delete mpX or Detach in the UI, the change is not applied while the container is running. If you need that feature, feel free to open a feature request on our bugtracker outlining your use case.
 
  • Like
Reactions: n0x0n
[...] the change is not applied while the container is running. If you need that feature, feel free to open a feature request on our bugtracker outlining your use case.
Than you, I will. It would be consistent with the new behaviour, as attaching now doesn't need a container restart.
Have a good week!
 

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!