Proxmox How-to: Configure LXC Mountpoints

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.

1: Open shell to the LXC

2a: If you have already created a user, get the user id using command

$ id
uid=1000(myuser) gid=1000(myuser) groups=1000(myuser)

2b: If you have not created a user, create one using command below then go back to step 2a

$ adduser <username>

3: 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

4. Add the mountpoint anywhere in the file

mp0: /path/to/directory/in/host,mp=/path/in/containerExample: 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.

5. 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

6. Save file

7. Open file /etc/subuid in editor

$ nano /etc/subuid

8. Add line (replace 1000 with uid) and save file

root:1000:1

9. Open file /etc/subgid in editor

$ nano /etc/subgid

10. Add line (replace 1000 with guid) and save file

root:1000:1

11. 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..

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store