Proxmox: sharing files to container with snapshots
I finally figured out how to mount a directory in a container without making Proxmox refuse to do snapshots. The trick is to use lxc.mount.entry instead of a bindmount. Thanks to this Reddit hint. In detail...
I have a USB disc mounted on the Proxmox host as /mnt/usb-media. I want to share it to a container running a media server. When you look online for how to do this you quickly find that bindmounts are the way to do this. Basically it says “take this directory in the host and make it available to the guest”. This is the config in /etc/pve/nodes/pve/lxc/110.conf I was using:
mp0: /mnt/usb-media,mp=/mnt/usb-media
This works fine but has the side effect of Proxmox refusing to take a container snapshot. There’s an error in the GUI console saying “The current guest configuration does not support taking new snapshots”. I don’t know quite why that’s a problem, maybe it is concerned it can’t snapshot the contents of the mounted files? I’d be fine skipping those!
Anyway, the solution is a different config line:
lxc.mount.entry: /mnt/usb-media mnt/usb-media none bind,create=dir 0 0
This makes the files available, just like the bindmount did, but Proxmox will still take snapshots. The snapshots still seem to work. I didn’t test what they did with files on the mounted directory. In this particular application I should probably mark the mount read only...
The format is documented in the LXC man page but all it says it’s like an fstab entry. Note it’s very important that the third word, the destination directory, has no leading slash. It’s a relative path, relative to /, mnt/usb-media in this case. If you make it an absolute path there will be no error message but nothing is visibly mounted.
Proxmox’ docs are really not very helpful here. I have no idea what all a bindmount might do or how it’s more than the plain LXC entry. Someone else suggested trying to add replicate=0 to the bindmount options to make snapshots work. That didn’t work for me.
Anyway, I can play my mp3s and still snapshot the container, so mission accomplished.