I'm following the procedure for mounting a host drive inside an lxc container as described here. In that article the author sets the raw.idmap like this:

lxc config set zesty raw.idmap 'both 1000 1000'

I want to customize the mapping for gid and uid as described in the lxd idmap documentation. Which shows a sample mapping as this:

both 1000 1000
uid 50-60 500-510
gid 10000-110000 10000-20000

I'm struggling with the syntax for actually setting this, as it doesn't seem as though the command in the first article works for multi-line configurations, and I've tried entering it all on a single line and by using JSON, but no luck, as the container gives configuration errors and won't start.

What is the correct way to configure this?


This question has been answered in the LXC user mailing list:

As idmap is a blob, if you want to assign multiple values, you have to send multilines. Example:

echo -en "both 1003 1003\nboth 1004 1004" | lxc config set mycontainer raw.idmap -

Another way in order to automate this could be as described here (https://ubuntu.com/blog/custom-user-mappings-in-lxd-containers):

printf "uid $(id -u) 1000\ngid $(id -g) 1000" | lxc config set your_container raw.idmap -
lxc restart your_container

So it will retrieve your current UID and GID and map them to the UID 1000 and GID 1000 inside the container. You can change this value if you are using another user. Also, you need to restart your container so the change will take effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.