The Problem
Proxmox offers a user-friendly interface for adding extra storage to containers. But if you need to use storage that already exists or share it across multiple containers, you’re out of luck. Bind mounting provides a simple solution to make a directory available in multiple locations. However, with Proxmox, bind mounting must be done in a specific order because of how it handles device nodes and pre-populates directories. This can be frustrating, but it’s not impossible to work around.
The solution
ZFS needs to come up first
If you are using ZFS for your storage (which you should), you need to ensure that all of ZFS’s mounts are fully online before proxmox does anything. You will need to add After=zfs.target to the [Unit] section of the Proxmox Systemd service files. The change needs to be applied to the following files:
/lib/systemd/system/pve-cluster.service
/lib/systemd/system/pve-ha-crm.service
/lib/systemd/system/pve-ha-lrm.service
/lib/systemd/system/pve-container@.service
/lib/systemd/system/pve-firewall.service
/lib/systemd/system/pvefw-logger.service
/lib/systemd/system/pve-daily-update.service
/lib/systemd/system/pve-guests.service
/lib/systemd/system/pvebanner.service
/lib/systemd/system/pvedaemon.service
/lib/systemd/system/pvenetcommit.service
/lib/systemd/system/pveproxy.service
/lib/systemd/system/pvesr.service
/lib/systemd/system/pvestatd.service
Create mount script
You will need to make a simple script that can be run by Systemd that can do a little cleanup and perform the mounts. An example should be attached to this gist a bit further down. Copy it to /opt/ and be sure to chmod it to be executable.
Create Systemd service file
The Systemd service file that you want is included below. Copy it to /etc/systemd/system/ and do the following commands:
systemctl daemon-reload
systemctl enable bindmounts
The next time you reboot your host[s], this should allow all containers with the shared bind mount to come up properly. You can also do systemctl start bindmounts if you would like to mount the paths for running containers.
Final notes
- While this approach is based on recommendations from Proxmox staff, it is not officially supported and carries a risk of data loss. Use it at your own discretion, with no expectation of warranty.
- I haven’t tested this in a formal “production” environment—I’m using it at home with some success, but that’s the extent of it.
- I intend to replace the current Bash script for managing bind mounts with a Python version. This will allow for more complex configurations, like multiple mounts per container or different mounts for each container. I’ll tackle this as time allows.