How to Configure Mountpoints in Proxmox LXC

How to Configure Mountpoints in Proxmox LXC

we start with the assumption that you have a proxmox server set up, you have created an LXC and you have a directory you need to pass through from the host to the container. it may be easier to create privileged containers but it is ideal that unprivileged containers are given limited access to only what they require.

open shell to the LXC

if you have already created a user, get the user id using command

$ id

if you have not created a user, create one using command below then startover from the top

$ adduser <username>

open shell in the proxmox host and enter command below to get access to the conf file for the LXC and replace {vmid} with the id of the LXC.

$ nano /etc/pve/lxc/{vmid}.conf

add the mountpoint anywhere in the file

mp0: /path/to/directory/in/host,mp=/path/in/container

example: mp0: /mnt/pve/ssd/shared,mp=/shared

this basically says, take directory /mnt/pve/ssd/shared in the host and mount it as /shared in the LXC.

add lines below in the same .conf file

lxc.idmap: u 0 100000 1000
lxc.idmap: g 0 100000 1000
lxc.idmap: u 1000 1000 1
lxc.idmap: g 1000 1000 1
lxc.idmap: u 1001 101001 64535
lxc.idmap: g 1001 101001 64535

find detailed explanation here

save file

open file /etc/subuid in editor

$ nano /etc/subuid

add line (replace 1000 with uid) and save file

root:1000:1

open file /etc/subgid in editor

$ nano /etc/subgid

add line (replace 1000 with guid) and save file

root:1000:1

restart container and you should have the directory mp0 passed through. if you need more mountpoints, add it as mp1, mp2.. in the .conf file.

troubleshooting

default directory permissions depend on when the folder was created or who created it. check directory permissions using$ ls -lhn

if the directory does not have permissions set to 1000 1000 (your uid, guid), use command below to give the right permissions

chown -R 1000:1000 /mnt/pve/ssd/shared

next steps..

pass a directory to an LXC running docker, then pass that directory down into a docker container or create a SMB share using samba..