Skip to content

Instantly share code, notes, and snippets.

@rngadam
Last active February 18, 2025 20:53
Show Gist options
  • Save rngadam/43a16c4d28ee783b6de6c8c4db449379 to your computer and use it in GitHub Desktop.
Save rngadam/43a16c4d28ee783b6de6c8c4db449379 to your computer and use it in GitHub Desktop.
Writable LVM volume hosted in Proxmox binded to a mount point within an LXC container

creating a shared media disk between LXC containers and VM for multimedia content

on the proxmox host

create the disk and mount it:

lvcreate -n media -V 100G pve/data
mkfs.ext4 /dev/pve/media 
mkdir -p /mnt/bindmounts/media
echo '/dev/pve/media /mnt/bindmounts/media/ ext4 defaults 0 2' >> /etc/fstab
systemctl daemon-reload

set permissions

chown 100000:110000 /mnt/bindmounts/media
chmod 770 /mnt/bindmounts/media

modify lxc container configuration /etc/pve/lxc/100.conf :

mp0:/mnt/bindmounts/media,mp=/media

the bind 100000 will map to 0 in the container (root) and group 110000 will map to a new group we'll create

in LXC

groupadd -g 10000 lxc_shares
usermod -aG lxc_shares $USER

Testing

in proxmox host:

root@pve:/home/rngadam# touch /mnt/bindmounts/media/HELLO_FROM_PVE 
root@pve:/home/rngadam# ls -al /mnt/bindmounts/media/HELLO_FROM_PVE 
-rw-r--r-- 1 root root 0 Feb 10 17:38 /mnt/bindmounts/media/HELLO_FROM_PVE

in lxc:

rngadam@backup:/media$ ls -al /media/HELLO_FROM_PVE
-rw-r--r-- 1 nobody nogroup 0 Feb 10 22:38 /media/HELLO_FROM_PVE
rngadam@backup:/media$ touch /media/HELLO_FROM_LXC
rngadam@backup:/media$ ls -al /media/HELLO_FROM_LXC
-rw-rw-r-- 1 rngadam rngadam 0 Feb 10 22:38 /media/HELLO_FROM_LXC

back in Proxmox:

root@pve:/home/rngadam# ls -al /mnt/bindmounts/media/HELLO_FROM_LXC
-rw-rw-r-- 1 101000 101000 0 Feb 10 17:38 /mnt/bindmounts/media/HELLO_FROM_LXC

references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment