Create a lxc accessible folder on the host

Xavier Bit

New Member
May 22, 2025
3
0
1
Hi!

I'm new to Proxmox, please be patient :)

I'm trying to set up a very small Proxmox server with only a local cluster where I'm running PiHole and Lyrion Music Server on it, both as lxc.

My goal is to get my music collection into the Proxmox server so I can use it for the Lyrion Music Server and for a management tool to complete collections with all the metadata missing.
As I see it I would have to create a folder on the host which would be accessible for the two lxcs which are running as unprivileged instances. I prefer lxc over a virtual machine as the overhead is much smaller and my hardware is already somewhat dated.
I have been searching for days now and I'm not able to follow the tutorials I found on Youtube, where some are really old and I'm not sure if they still work.

Could somebody point me to a beginner friendly tutorial which is easy to follow or help me here?
 
Hey Reinob,
Thanks for answering.

I'm still not clear how to create a local directory for my music files. If I create just a directory on the host, how would the unprivileged LXCs have access to it?

Would it be better to install Openmediavault instead and try to go from there?
 
Bash:
#!/bin/bash

# Stop execution, if we encounter any failure
set -e

read -p 'Which container do you want to modify: ' id
read -p 'Which directory should be shared with the container: ' dir

# Stop the container, if it's still running
pct stop "${id}" >&/dev/null || :

# Create the shared directory
mkdir -p "${dir}"
chown 100000:100000 "${dir}"

# Mount shared directory in container; avoid "mpX: entries, as they prevent snapshots.
# We create an entry of the form
#   lxc.mount.entry: /dir dir none rbind,optional,create=dir
# Things are slightly more complicated, as we have to edit the configuration file
# ourselves. ProxmoxVE doesn't have a ready-made command-line tool to do this. And
# while configuration files are generally really simple key-value files, we have to
# make sure that we only modify the current values and not any of the previous
# snaphots. A little bit of "sed" magic does the trick.
new="${dir} ${dir#/} none rbind,optional,create=dir"
sed -i '/^$/b1;$!b;p;s/.*//;:1;ilxc.mount.entry: '"${new}"'
:2;$b;N;b2'  "/etc/pve/lxc/${id}.conf"

# Now, start the container again
pct start "${id}"

This script creates a shared folder that is stored on the host and that is accessible from the container. You can also share it between multiple containers, if you need that.

Since you said you are using unprivileged containers, the user and group ids will be 100000 instead of root. If that is a problem for your intended use-case, you can create id mappings. That's a little more intricate and probably requires a reading the documentation or writing a short Python program. It would push the limits of a normal shell script. So, I didn't want to include that here to avoid confusion.

Try it on your own first, and if the documentation doesn't make sense, tell us where you got stuck.
 
  • Like
Reactions: reinob