lxc / go-lxc

Go bindings for liblxc
https://linuxcontainers.org/lxc
Other
430 stars 76 forks source link

create example not working #160

Open DeathsGun opened 2 years ago

DeathsGun commented 2 years ago

I tried running the create/create example and got the following output:

lxc 20220324161237.959 ERROR    conf - conf.c:userns_exec_mapped_root:4499 - No uid mapping for container root
lxc 20220324161237.959 ERROR    lxccontainer - lxccontainer.c:do_storage_create:1292 - Error chowning "/home/lbue/.local/share/lxc/rubik/rootfs" to container root
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4820 - You must either run as root, or define uid mappings
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4821 - To pass uid mappings to lxc-create, you could create
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4822 - ~/.config/lxc/default.conf:
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4823 - lxc.include = /etc/lxc/default.conf
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4824 - lxc.idmap = u 0 100000 65536
lxc 20220324161237.959 ERROR    conf - conf.c:suggest_default_idmap:4825 - lxc.idmap = g 0 100000 65536
lxc 20220324161237.959 ERROR    lxccontainer - lxccontainer.c:do_lxcapi_create:1871 - Failed to create dir storage for rubik

Even tough i have set up the uid mapping in ~/.config/lxc/default.conf: cat ~/.config/lxc/default.conf

lxc.include = /etc/lxc/default.conf
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536

When using lxc-create -t download test then it will create the container like expected.

lxc-checkconfig Output

LXC version 4.0.6
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled

--- Control groups ---
Cgroups: enabled

Cgroup v1 mount points:
/sys/fs/cgroup/cpuset
/sys/fs/cgroup/cpu
/sys/fs/cgroup/cpuacct
/sys/fs/cgroup/blkio
/sys/fs/cgroup/memory
/sys/fs/cgroup/devices
/sys/fs/cgroup/freezer
/sys/fs/cgroup/net_cls
/sys/fs/cgroup/perf_event
/sys/fs/cgroup/net_prio
/sys/fs/cgroup/hugetlb
/sys/fs/cgroup/pids
/sys/fs/cgroup/rdma

Cgroup v2 mount points:
/sys/fs/cgroup/unified

Cgroup v1 systemd controller: missing
Cgroup v1 clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled, not loaded
Macvlan: enabled, not loaded
Vlan: enabled, not loaded
Bridges: enabled, not loaded
Advanced netfilter: enabled, not loaded
CONFIG_NF_NAT_IPV4: missing
CONFIG_NF_NAT_IPV6: missing
CONFIG_IP_NF_TARGET_MASQUERADE: enabled, not loaded
CONFIG_IP6_NF_TARGET_MASQUERADE: enabled, not loaded
CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled, not loaded
CONFIG_NETFILTER_XT_MATCH_COMMENT: enabled, not loaded
FUSE (for use with lxcfs): enabled, not loaded

--- Checkpoint/Restore ---
checkpoint restore: enabled
CONFIG_FHANDLE: enabled
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
CONFIG_UNIX_DIAG: enabled
CONFIG_INET_DIAG: enabled
CONFIG_PACKET_DIAG: enabled
CONFIG_NETLINK_DIAG: enabled
File capabilities:

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

go env output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/lbue/.cache/go-build"
GOENV="/home/lbue/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/lbue/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/lbue/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/lbue/go-lxc/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build707100842=/tmp/go-build -gno-record-gcc-switches"
tox2ik commented 2 years ago

likely this:

First of all, you need to make sure your user has a uid and gid map defined in /etc/subuid and /etc/subgid. On Ubuntu systems, a default allocation of 65536 uids and gids is given to every new user on the system, so you should already have one. If not, you'll have to use usermod to give yourself one.

e.g.

 usermod -v 1000000-1065535  jaro